source: trip-planner-front/node_modules/lodash/clamp.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 890 bytes
Line 
1var baseClamp = require('./_baseClamp'),
2 toNumber = require('./toNumber');
3
4/**
5 * Clamps `number` within the inclusive `lower` and `upper` bounds.
6 *
7 * @static
8 * @memberOf _
9 * @since 4.0.0
10 * @category Number
11 * @param {number} number The number to clamp.
12 * @param {number} [lower] The lower bound.
13 * @param {number} upper The upper bound.
14 * @returns {number} Returns the clamped number.
15 * @example
16 *
17 * _.clamp(-10, -5, 5);
18 * // => -5
19 *
20 * _.clamp(10, -5, 5);
21 * // => 5
22 */
23function clamp(number, lower, upper) {
24 if (upper === undefined) {
25 upper = lower;
26 lower = undefined;
27 }
28 if (upper !== undefined) {
29 upper = toNumber(upper);
30 upper = upper === upper ? upper : 0;
31 }
32 if (lower !== undefined) {
33 lower = toNumber(lower);
34 lower = lower === lower ? lower : 0;
35 }
36 return baseClamp(toNumber(number), lower, upper);
37}
38
39module.exports = clamp;
Note: See TracBrowser for help on using the repository browser.