negateValue.js 1022 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "default", {
  6. enumerable: true,
  7. get: ()=>negateValue
  8. });
  9. function negateValue(value) {
  10. value = `${value}`;
  11. if (value === "0") {
  12. return "0";
  13. }
  14. // Flip sign of numbers
  15. if (/^[+-]?(\d+|\d*\.\d+)(e[+-]?\d+)?(%|\w+)?$/.test(value)) {
  16. return value.replace(/^[+-]?/, (sign)=>sign === "-" ? "" : "-");
  17. }
  18. // What functions we support negating numeric values for
  19. // var() isn't inherently a numeric function but we support it anyway
  20. // The trigonometric functions are omitted because you'll need to use calc(…) with them _anyway_
  21. // to produce generally useful results and that will be covered already
  22. let numericFunctions = [
  23. "var",
  24. "calc",
  25. "min",
  26. "max",
  27. "clamp"
  28. ];
  29. for (const fn of numericFunctions){
  30. if (value.includes(`${fn}(`)) {
  31. return `calc(${value} * -1)`;
  32. }
  33. }
  34. }