@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
17 lines (16 loc) • 582 B
JavaScript
/*!
* All material copyright ESRI, All Rights Reserved, unless otherwise specified.
* See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
*/
export const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
export const decimalPlaces = (value) => {
const match = ("" + value).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
if (!match) {
return 0;
}
return Math.max(0,
// Number of digits right of decimal point.
(match[1] ? match[1].length : 0) -
// Adjust for scientific notation.
(match[2] ? +match[2] : 0));
};