utilities.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.camelCase = void 0;
  4. var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9_-]+$/;
  5. var HYPHEN_REGEX = /-([a-z])/g;
  6. var NO_HYPHEN_REGEX = /^[^-]+$/;
  7. var VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
  8. var MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
  9. /**
  10. * Checks whether to skip camelCase.
  11. */
  12. var skipCamelCase = function (property) {
  13. return !property ||
  14. NO_HYPHEN_REGEX.test(property) ||
  15. CUSTOM_PROPERTY_REGEX.test(property);
  16. };
  17. /**
  18. * Replacer that capitalizes first character.
  19. */
  20. var capitalize = function (match, character) {
  21. return character.toUpperCase();
  22. };
  23. /**
  24. * Replacer that removes beginning hyphen of vendor prefix property.
  25. */
  26. var trimHyphen = function (match, prefix) { return "".concat(prefix, "-"); };
  27. /**
  28. * CamelCases a CSS property.
  29. */
  30. var camelCase = function (property, options) {
  31. if (options === void 0) { options = {}; }
  32. if (skipCamelCase(property)) {
  33. return property;
  34. }
  35. property = property.toLowerCase();
  36. if (options.reactCompat) {
  37. // `-ms` vendor prefix should not be capitalized
  38. property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
  39. }
  40. else {
  41. // for non-React, remove first hyphen so vendor prefix is not capitalized
  42. property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
  43. }
  44. return property.replace(HYPHEN_REGEX, capitalize);
  45. };
  46. exports.camelCase = camelCase;
  47. //# sourceMappingURL=utilities.js.map