nameClass.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. function _export(target, all) {
  6. for(var name in all)Object.defineProperty(target, name, {
  7. enumerable: true,
  8. get: all[name]
  9. });
  10. }
  11. _export(exports, {
  12. asClass: function() {
  13. return asClass;
  14. },
  15. default: function() {
  16. return nameClass;
  17. },
  18. formatClass: function() {
  19. return formatClass;
  20. }
  21. });
  22. const _escapeClassName = /*#__PURE__*/ _interop_require_default(require("./escapeClassName"));
  23. const _escapeCommas = /*#__PURE__*/ _interop_require_default(require("./escapeCommas"));
  24. function _interop_require_default(obj) {
  25. return obj && obj.__esModule ? obj : {
  26. default: obj
  27. };
  28. }
  29. function asClass(name) {
  30. return (0, _escapeCommas.default)(`.${(0, _escapeClassName.default)(name)}`);
  31. }
  32. function nameClass(classPrefix, key) {
  33. return asClass(formatClass(classPrefix, key));
  34. }
  35. function formatClass(classPrefix, key) {
  36. if (key === "DEFAULT") {
  37. return classPrefix;
  38. }
  39. if (key === "-" || key === "-DEFAULT") {
  40. return `-${classPrefix}`;
  41. }
  42. if (key.startsWith("-")) {
  43. return `-${classPrefix}${key}`;
  44. }
  45. if (key.startsWith("/")) {
  46. return `${classPrefix}${key}`;
  47. }
  48. return `${classPrefix}-${key}`;
  49. }