math-f71ad83a.js 664 B

12345678910111213141516171819202122
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. 'use strict';
  7. const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
  8. const decimalPlaces = (value) => {
  9. const match = ("" + value).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  10. if (!match) {
  11. return 0;
  12. }
  13. return Math.max(0,
  14. // Number of digits right of decimal point.
  15. (match[1] ? match[1].length : 0) -
  16. // Adjust for scientific notation.
  17. (match[2] ? +match[2] : 0));
  18. };
  19. exports.clamp = clamp;
  20. exports.decimalPlaces = decimalPlaces;