@ztimson/utils 0.23.18 → 0.23.20

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
@@ -543,12 +543,8 @@ ${opts.message || this.desc}`;
543
543
  const NUMBER_LIST = "0123456789";
544
544
  const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
545
545
  const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST;
546
- function camelCase(text) {
547
- if (!text) return "";
548
- text = text.replaceAll(/^[0-9]+/g, "").replaceAll(/[^a-zA-Z0-9]+(\w?)/g, (...args) => {
549
- var _a;
550
- return ((_a = args[1]) == null ? void 0 : _a.toUpperCase()) || "";
551
- });
546
+ function camelCase(str) {
547
+ const text = pascalCase(str);
552
548
  return text[0].toLowerCase() + text.slice(1);
553
549
  }
554
550
  function formatBytes(bytes, decimals = 2) {
@@ -566,10 +562,22 @@ ${opts.message || this.desc}`;
566
562
  function insertAt(target, str, index) {
567
563
  return `${target.slice(0, index)}${str}${target.slice(index + 1)}`;
568
564
  }
565
+ function kebabCase(str) {
566
+ if (!str) return "";
567
+ 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();
568
+ }
569
569
  function pad(text, length, char = " ", start = true) {
570
570
  if (start) return text.toString().padStart(length, char);
571
571
  return text.toString().padEnd(length, char);
572
572
  }
573
+ function pascalCase(str) {
574
+ if (!str) return "";
575
+ const text = str.replaceAll(/(^[^a-zA-Z]+|[^a-zA-Z0-9-_])/g, "").replaceAll(/[^a-zA-Z0-9]+(\w?)/g, (...args) => {
576
+ var _a;
577
+ return ((_a = args[1]) == null ? void 0 : _a.toUpperCase()) || "";
578
+ });
579
+ return text[0].toUpperCase() + text.slice(1);
580
+ }
573
581
  function randomHex(length) {
574
582
  return Array(length).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
575
583
  }
@@ -596,6 +604,10 @@ ${opts.message || this.desc}`;
596
604
  return c;
597
605
  }).join("");
598
606
  }
607
+ function snakeCase(str) {
608
+ if (!str) return "";
609
+ 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();
610
+ }
599
611
  function strSplice(str, start, deleteCount, insert = "") {
600
612
  const before = str.slice(0, start);
601
613
  const after = str.slice(start + deleteCount);
@@ -744,7 +756,7 @@ ${opts.message || this.desc}`;
744
756
  const value2 = dotNotation(row, h);
745
757
  if (value2 == null) return "";
746
758
  if (typeof value2 == "object") return `"${JSONSanitize(value2).replaceAll('"', '""')}"`;
747
- if (typeof value2 == "string" && /[\n"]/g.test(value2)) return `"${value2.replaceAll('"', '""')}"`;
759
+ if (typeof value2 == "string" && /[\n",]/g.test(value2)) return `"${value2.replaceAll('"', '""')}"`;
748
760
  return value2;
749
761
  }).join(","))
750
762
  ].join("\n");
@@ -1757,6 +1769,7 @@ ${opts.message || this.desc}`;
1757
1769
  exports.instantInterval = instantInterval;
1758
1770
  exports.isEqual = isEqual;
1759
1771
  exports.jwtDecode = jwtDecode;
1772
+ exports.kebabCase = kebabCase;
1760
1773
  exports.makeArray = makeArray;
1761
1774
  exports.makeUnique = makeUnique;
1762
1775
  exports.matchAll = matchAll;
@@ -1764,12 +1777,14 @@ ${opts.message || this.desc}`;
1764
1777
  exports.mixin = mixin;
1765
1778
  exports.pad = pad;
1766
1779
  exports.parseUrl = parseUrl;
1780
+ exports.pascalCase = pascalCase;
1767
1781
  exports.randomHex = randomHex;
1768
1782
  exports.randomString = randomString;
1769
1783
  exports.randomStringBuilder = randomStringBuilder;
1770
1784
  exports.search = search;
1771
1785
  exports.sleep = sleep;
1772
1786
  exports.sleepWhile = sleepWhile;
1787
+ exports.snakeCase = snakeCase;
1773
1788
  exports.sortByProp = sortByProp;
1774
1789
  exports.strSplice = strSplice;
1775
1790
  exports.timeUntil = timeUntil;