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

lodash-constrain

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash-constrain

Extend Lodash to take a numeric value, check that it's within a range and, if not, return the minimum or maximum allowed value instead.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Lodash constrain

Build Status Known Vulnerabilities NPM version

Extend Lodash to take a numeric value, check that it's within a range and, if not, return the minimum or maximum allowed value instead. That is, if value is lower than the minimum allowed then minimum is returned. If it is greater than the maximum allowed then maximum is returned, otherwise value is returned unchanged.

_.constrain(value, [min=0], [max=Number.MAX_VALUE])

Arguments
value (number): The number value to be checked. Required.
[min] (number): The minimum allowed value. Optional. When none is supplied, zero is used.
[max] (number): The maximum allowed value. Optional. When none is supplied the maximum allowed for the environment (Number.MAX_VALUE) is used.

Returns
(Number): A number.

Examples

var _ = require('lodash')
require('lodash-constrain')

_.constrain(10,12) // 12 
_.constrain(10,10) // 10 
_.constrain(10,0,10) // 10 
_.constrain(15,10) // 15
_.constrain(-1) // 0
_.constrain(15,20.5) // 20.5
_.constrain(120,20,100) // 100

Version History

VersionRelease DateDetails
1.0.025th February, 2018Initial release.

FAQs

Package last updated on 25 Feb 2018

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