Permalink
Cannot retrieve contributors at this time
39 lines (37 sloc)
890 Bytes
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/lodash/clamp.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var baseClamp = require('./_baseClamp'), | |
toNumber = require('./toNumber'); | |
/** | |
* Clamps `number` within the inclusive `lower` and `upper` bounds. | |
* | |
* @static | |
* @memberOf _ | |
* @since 4.0.0 | |
* @category Number | |
* @param {number} number The number to clamp. | |
* @param {number} [lower] The lower bound. | |
* @param {number} upper The upper bound. | |
* @returns {number} Returns the clamped number. | |
* @example | |
* | |
* _.clamp(-10, -5, 5); | |
* // => -5 | |
* | |
* _.clamp(10, -5, 5); | |
* // => 5 | |
*/ | |
function clamp(number, lower, upper) { | |
if (upper === undefined) { | |
upper = lower; | |
lower = undefined; | |
} | |
if (upper !== undefined) { | |
upper = toNumber(upper); | |
upper = upper === upper ? upper : 0; | |
} | |
if (lower !== undefined) { | |
lower = toNumber(lower); | |
lower = lower === lower ? lower : 0; | |
} | |
return baseClamp(toNumber(number), lower, upper); | |
} | |
module.exports = clamp; |