clamp.js

0.2.9 • Public • Published

clamp.js (written in ES6)

license npm build Coverage Status code climate devDependencies

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)); // [1,2,3,3,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));
 
    // every 1000ms stream emits a value which is mapped on clamp()
    stream.log();
 
    // result -> sequence of values over time: 1,2,3,3,3

Further reading on functional reactive programming:

Copyright

Copyright © 2015 Maximilian Heinz, contributors. Released under the MIT License

Package Sidebar

Install

npm i clamp.js

Weekly Downloads

30

Version

0.2.9

License

MIT

Last publish

Collaborators

  • meandmax