@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 +22 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +22 -7
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +16 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -539,12 +539,8 @@ const LETTER_LIST = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
539
539
|
const NUMBER_LIST = "0123456789";
|
|
540
540
|
const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
|
|
541
541
|
const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST;
|
|
542
|
-
function camelCase(
|
|
543
|
-
|
|
544
|
-
text = text.replaceAll(/^[0-9]+/g, "").replaceAll(/[^a-zA-Z0-9]+(\w?)/g, (...args) => {
|
|
545
|
-
var _a;
|
|
546
|
-
return ((_a = args[1]) == null ? void 0 : _a.toUpperCase()) || "";
|
|
547
|
-
});
|
|
542
|
+
function camelCase(str) {
|
|
543
|
+
const text = pascalCase(str);
|
|
548
544
|
return text[0].toLowerCase() + text.slice(1);
|
|
549
545
|
}
|
|
550
546
|
function formatBytes(bytes, decimals = 2) {
|
|
@@ -562,10 +558,22 @@ function formatPhoneNumber(number) {
|
|
|
562
558
|
function insertAt(target, str, index) {
|
|
563
559
|
return `${target.slice(0, index)}${str}${target.slice(index + 1)}`;
|
|
564
560
|
}
|
|
561
|
+
function kebabCase(str) {
|
|
562
|
+
if (!str) return "";
|
|
563
|
+
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();
|
|
564
|
+
}
|
|
565
565
|
function pad(text, length, char = " ", start = true) {
|
|
566
566
|
if (start) return text.toString().padStart(length, char);
|
|
567
567
|
return text.toString().padEnd(length, char);
|
|
568
568
|
}
|
|
569
|
+
function pascalCase(str) {
|
|
570
|
+
if (!str) return "";
|
|
571
|
+
const text = str.replaceAll(/(^[^a-zA-Z]+|[^a-zA-Z0-9-_])/g, "").replaceAll(/[^a-zA-Z0-9]+(\w?)/g, (...args) => {
|
|
572
|
+
var _a;
|
|
573
|
+
return ((_a = args[1]) == null ? void 0 : _a.toUpperCase()) || "";
|
|
574
|
+
});
|
|
575
|
+
return text[0].toUpperCase() + text.slice(1);
|
|
576
|
+
}
|
|
569
577
|
function randomHex(length) {
|
|
570
578
|
return Array(length).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
|
|
571
579
|
}
|
|
@@ -592,6 +600,10 @@ function randomStringBuilder(length, letters = false, numbers = false, symbols =
|
|
|
592
600
|
return c;
|
|
593
601
|
}).join("");
|
|
594
602
|
}
|
|
603
|
+
function snakeCase(str) {
|
|
604
|
+
if (!str) return "";
|
|
605
|
+
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();
|
|
606
|
+
}
|
|
595
607
|
function strSplice(str, start, deleteCount, insert = "") {
|
|
596
608
|
const before = str.slice(0, start);
|
|
597
609
|
const after = str.slice(start + deleteCount);
|
|
@@ -740,7 +752,7 @@ function toCsv(target, flatten = true) {
|
|
|
740
752
|
const value2 = dotNotation(row, h);
|
|
741
753
|
if (value2 == null) return "";
|
|
742
754
|
if (typeof value2 == "object") return `"${JSONSanitize(value2).replaceAll('"', '""')}"`;
|
|
743
|
-
if (typeof value2 == "string" && /[\n"]/g.test(value2)) return `"${value2.replaceAll('"', '""')}"`;
|
|
755
|
+
if (typeof value2 == "string" && /[\n",]/g.test(value2)) return `"${value2.replaceAll('"', '""')}"`;
|
|
744
756
|
return value2;
|
|
745
757
|
}).join(","))
|
|
746
758
|
].join("\n");
|
|
@@ -1754,6 +1766,7 @@ export {
|
|
|
1754
1766
|
instantInterval,
|
|
1755
1767
|
isEqual,
|
|
1756
1768
|
jwtDecode,
|
|
1769
|
+
kebabCase,
|
|
1757
1770
|
makeArray,
|
|
1758
1771
|
makeUnique,
|
|
1759
1772
|
matchAll,
|
|
@@ -1761,12 +1774,14 @@ export {
|
|
|
1761
1774
|
mixin,
|
|
1762
1775
|
pad,
|
|
1763
1776
|
parseUrl,
|
|
1777
|
+
pascalCase,
|
|
1764
1778
|
randomHex,
|
|
1765
1779
|
randomString,
|
|
1766
1780
|
randomStringBuilder,
|
|
1767
1781
|
search,
|
|
1768
1782
|
sleep,
|
|
1769
1783
|
sleepWhile,
|
|
1784
|
+
snakeCase,
|
|
1770
1785
|
sortByProp,
|
|
1771
1786
|
strSplice,
|
|
1772
1787
|
timeUntil,
|