Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clamp.js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clamp.js

Returns a function that clamps input values to range [min <= x <= max].

  • 0.2.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

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 © 2015 Maximilian Heinz, contributors. Released under the MIT License

Keywords

FAQs

Package last updated on 06 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc