@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.mjs CHANGED
@@ -657,8 +657,9 @@ const NUMBER_LIST = "0123456789";
657
657
  const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
658
658
  const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST;
659
659
  function camelCase(str) {
660
- const text = pascalCase(str);
661
- return !text ? "" : text[0].toLowerCase() + text.slice(1);
660
+ if (!str) return "";
661
+ const pascal = pascalCase(str);
662
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
662
663
  }
663
664
  function formatBytes(bytes, decimals = 2) {
664
665
  if (bytes === 0) return "0 Bytes";
@@ -677,16 +678,15 @@ function insertAt(target, str, index) {
677
678
  }
678
679
  function kebabCase(str) {
679
680
  if (!str) return "";
680
- 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();
681
+ return wordSegments(str).map((w) => w.toLowerCase()).join("-");
681
682
  }
682
683
  function pad(text, length, char = " ", start = true) {
683
684
  if (start) return text.toString().padStart(length, char);
684
685
  return text.toString().padEnd(length, char);
685
686
  }
686
687
  function pascalCase(str) {
687
- var _a;
688
688
  if (!str) return "";
689
- return ((_a = str.match(/[a-zA-Z0-9]+/g)) == null ? void 0 : _a.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("")) ?? "";
689
+ return wordSegments(str).map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join("");
690
690
  }
691
691
  function randomHex(length) {
692
692
  return Array(length).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
@@ -716,7 +716,7 @@ function randomStringBuilder(length, letters = false, numbers = false, symbols =
716
716
  }
717
717
  function snakeCase(str) {
718
718
  if (!str) return "";
719
- 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();
719
+ return wordSegments(str).map((w) => w.toLowerCase()).join("_");
720
720
  }
721
721
  function strSplice(str, start, deleteCount, insert = "") {
722
722
  const before = str.slice(0, start);
@@ -806,6 +806,10 @@ function safe_add(d, _) {
806
806
  function bit_rol(d, _) {
807
807
  return d << _ | d >>> 32 - _;
808
808
  }
809
+ function wordSegments(str) {
810
+ if (!str) return [];
811
+ 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);
812
+ }
809
813
  function validateEmail(email) {
810
814
  return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email);
811
815
  }
@@ -2117,6 +2121,7 @@ export {
2117
2121
  timestampFilename,
2118
2122
  toCsv,
2119
2123
  uploadWithProgress,
2120
- validateEmail
2124
+ validateEmail,
2125
+ wordSegments
2121
2126
  };
2122
2127
  //# sourceMappingURL=index.mjs.map