1.0.0 • Published 6 years ago

lodash-constrain v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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: The minimum allowed value. Optional. When none is supplied, zero is used.
max: 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.