0.2.9 • Published 9 years ago

clamp.js v0.2.9

Weekly downloads
12
License
MIT
Repository
github
Last release
9 years ago

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

0.2.9

9 years ago

0.2.8

9 years ago

0.2.7

9 years ago

0.2.5

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago