@ztimson/utils 0.25.7 → 0.25.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -661,8 +661,9 @@ ${opts.message || this.desc}`;
661
661
  const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
662
662
  const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST;
663
663
  function camelCase(str) {
664
- const text = pascalCase(str);
665
- return !text ? "" : text[0].toLowerCase() + text.slice(1);
664
+ if (!str) return "";
665
+ const pascal = pascalCase(str);
666
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
666
667
  }
667
668
  function formatBytes(bytes, decimals = 2) {
668
669
  if (bytes === 0) return "0 Bytes";
@@ -681,16 +682,15 @@ ${opts.message || this.desc}`;
681
682
  }
682
683
  function kebabCase(str) {
683
684
  if (!str) return "";
684
- return str.replaceAll(/(^[^a-zA-Z]+|[^a-zA-Z0-9-_])/g, "").replaceAll(/([A-Z]|[0-9]+)/g, (...args) => `-${args[0].toLowerCase()}`).replaceAll(/([0-9])([a-z])/g, (...args) => `${args[1]}-${args[2]}`).replaceAll(/[^a-z0-9]+(\w?)/g, (...args) => `-${args[1] ?? ""}`).toLowerCase();
685
+ return wordSegments(str).map((w) => w.toLowerCase()).join("-");
685
686
  }
686
687
  function pad(text, length, char = " ", start = true) {
687
688
  if (start) return text.toString().padStart(length, char);
688
689
  return text.toString().padEnd(length, char);
689
690
  }
690
691
  function pascalCase(str) {
691
- var _a;
692
692
  if (!str) return "";
693
- return ((_a = str.match(/[a-zA-Z0-9]+/g)) == null ? void 0 : _a.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("")) ?? "";
693
+ return wordSegments(str).map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join("");
694
694
  }
695
695
  function randomHex(length) {
696
696
  return Array(length).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
@@ -720,7 +720,7 @@ ${opts.message || this.desc}`;
720
720
  }
721
721
  function snakeCase(str) {
722
722
  if (!str) return "";
723
- return str.replaceAll(/(^[^a-zA-Z]+|[^a-zA-Z0-9-_])/g, "").replaceAll(/([A-Z]|[0-9]+)/g, (...args) => `_${args[0].toLowerCase()}`).replaceAll(/([0-9])([a-z])/g, (...args) => `${args[1]}_${args[2]}`).replaceAll(/[^a-z0-9]+(\w?)/g, (...args) => `_${args[1] ?? ""}`).toLowerCase();
723
+ return wordSegments(str).map((w) => w.toLowerCase()).join("_");
724
724
  }
725
725
  function strSplice(str, start, deleteCount, insert = "") {
726
726
  const before = str.slice(0, start);
@@ -810,6 +810,10 @@ ${opts.message || this.desc}`;
810
810
  function bit_rol(d, _) {
811
811
  return d << _ | d >>> 32 - _;
812
812
  }
813
+ function wordSegments(str) {
814
+ if (!str) return [];
815
+ return str.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/([0-9]+)([a-zA-Z])/g, "$1 $2").replace(/([a-zA-Z])([0-9]+)/g, "$1 $2").replace(/[_\-\s]+/g, " ").trim().split(/\s+/).filter(Boolean);
816
+ }
813
817
  function validateEmail(email) {
814
818
  return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email);
815
819
  }
@@ -2121,6 +2125,7 @@ ${opts.message || this.desc}`;
2121
2125
  exports2.toCsv = toCsv;
2122
2126
  exports2.uploadWithProgress = uploadWithProgress;
2123
2127
  exports2.validateEmail = validateEmail;
2128
+ exports2.wordSegments = wordSegments;
2124
2129
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
2125
2130
  });
2126
2131
  //# sourceMappingURL=index.cjs.map