UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

28 lines (24 loc) 673 B
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; // clamp utility, replacing lodash.clamp // If it's lower than the lower bound, we pick the lower bound. // If it's higher than the upper bound, we pick the upper bound. // Otherwise, we pick the number passed in. const clamp = (value, min, max) => { if (isNaN(value) || isNaN(min) || isNaN(max)) { return; } if (max !== undefined) { value = value <= max ? value : max; } { value = value >= min ? value : min; } return value; }; exports.clamp = clamp;