@hanamura/circulate

Circulate a number into given range.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@hanamura/circulate
010.1.17 years ago8 years agoMinified + gzip package size for @hanamura/circulate in KB

Readme

circulate Build Status
Circulate a number into given range.

Installation

npm install @hanamura/circulate --save

Usage

circulate(number, start, end)

Returns normalized number between start (inclusive) and end (exclusive).

Example

Keeping angles between 0 and 360 degrees (or -180 and 180 degrees):
var circulate = require('@hanamura/circulate');

circulate(0, 0, 360);
// -> 0

circulate(180, 0, 360);
// -> 180

circulate(360, 0, 360);
// -> 0

circulate(450, 0, 360);
// -> 90

circulate(-90, 0, 360);
// -> 270

circulate(-3690, 0, 360);
// -> 270

circulate(450, -180, 180);
// -> 90

circulate(-270, -180, 180);
// -> 90

License

MIT