@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 +11 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +12 -7
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +5 -1
- package/package.json +1 -1
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
|
-
|
|
661
|
-
|
|
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
|
|
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 (
|
|
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
|
|
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
|