ftr

fit-to-range

Fit a number to a given range

Showing:

Popularity

Downloads/wk

1

GitHub Stars

1

Maintenance

Last Commit

3yrs ago

Contributors

0

Package

Dependencies

2

Size (min+gzip)

0.3KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

fit-to-range

Fit a number to a given range

NPM Version NPM Downloads Build Status

Fits a number to a given range. The (simple) algorithm is:

  1. If number is equal or lower than lower bound - return lower bound.
  2. If number is equal or higher than upper bound - return upper bound.
  3. Return number.

A valid number is any regular integer/float, +-Infinity. NaN is invalid.

Installation

npm install --save fit-to-range

Usage

fitToRange(num, lowerBound, upperBound)

var fitToRange = require('fit-to-range');

var fitted;
fitted = fitToRange(5, 10, 20);
// => 10

fitted = fitToRange(25, 10, 20);
// => 20

fitted = fitToRange(0, -1, 1);
// => 0

fitted = fitToRange(1, -Infinity, 0);
// => 0

fitted = fitToRange(10.1, 0, Infinity);
// => 10.1

License

MIT © Gilad Peleg

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100