clamp.js (written in ES6)
Install:
npm install clamp.js
Run tests
npm test
Returns a function that clamps input values to range [min <= x <= max]. Useful for data structures like arrays. Swapping min and max is allowed and will be corrected.
with simple arrays:
import clamp from 'clamp.js';
[1,2,3,4,5].map(clamp(0, 3));
Can be used with frp libraries (e.g. Bacon.js, RxJS, Kefir.js). Examples are written with Bacon.js
in frp:
import clamp from 'clamp.js';
import Bacon from 'baconjs';
let stream = Bacon.sequentially(1000, [1, 2, 3, 4, 5])
.map(clamp(0, 3));
stream.log();
Further reading on functional reactive programming:
Copyright
Copyright © 2015 Maximilian Heinz, contributors. Released under the MIT License