Mixin for checking if value is inside or outside of bounds
Mixin for checking if value is inside or outside of bounds You can use
Bounds for any objects for
which you can define compare function (dates, vectors etc.)
In addition to regular range checking
Bounds supports reversed ranges: if
min is bigger than max it considers values outside ot the max, min range as valid.
$ npm install bounds
Sets comparison function.
fn should take 2 arguments and behave like sort comparison function i.e.
return 0 if items are equal, -1 if the first is smaller than the second, 1 is the first is bigger
than the second.
Set lower bound (inclusive) to
Set upper bound (inclusive) to
v is in bounds i.e.
min <= v <= max
v is outside of bounds i.e.
v < min OR
max < v
v < min
v > max
For regular ranges it's the same as
in. For reversed ranges it considers as valid values that are
outside of the range (it's still inclusive so
max are still considered valid)
Returns the passed value for
valid values. For invalid values returns the closest boundary (
restrict only works for reverse ranges if
distance function is defined.
Optional distance function: it's only used when calculating proper restriction for reversed ranges.
If restricted value is closed to
min than to
max, then the
min is returned.