math.js 630 B

12345678910111213141516171819
  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. const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
  7. const decimalPlaces = (value) => {
  8. const match = ("" + value).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  9. if (!match) {
  10. return 0;
  11. }
  12. return Math.max(0,
  13. // Number of digits right of decimal point.
  14. (match[1] ? match[1].length : 0) -
  15. // Adjust for scientific notation.
  16. (match[2] ? +match[2] : 0));
  17. };
  18. export { clamp as c, decimalPlaces as d };