@ztimson/utils 0.23.19 → 0.23.21
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 +24 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +24 -8
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +16 -2
- package/package.json +1 -1
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(
|
|
547
|
-
|
|
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);
|
|
@@ -1237,8 +1249,9 @@ ${opts.message || this.desc}`;
|
|
|
1237
1249
|
request(opts = {}) {
|
|
1238
1250
|
var _a;
|
|
1239
1251
|
if (!this.url && !opts.url) throw new Error("URL needs to be set");
|
|
1240
|
-
let url = ((
|
|
1241
|
-
|
|
1252
|
+
let url = ((_a = opts.url) == null ? void 0 : _a.startsWith("http")) ? opts.url : (this.url || "") + (opts.url || "");
|
|
1253
|
+
url = url.replaceAll(/([^:]\/)\/+/g, "$1");
|
|
1254
|
+
if (opts.fragment) url.includes("#") ? url.replace(/#.*(\?|\n)/g, (match, arg1) => `#${opts.fragment}${arg1}`) : `${url}#${opts.fragment}`;
|
|
1242
1255
|
if (opts.query) {
|
|
1243
1256
|
const q = Array.isArray(opts.query) ? opts.query : Object.keys(opts.query).map((k) => ({ key: k, value: opts.query[k] }));
|
|
1244
1257
|
url += (url.includes("?") ? "&" : "?") + q.map((q2) => `${q2.key}=${q2.value}`).join("&");
|
|
@@ -1757,6 +1770,7 @@ ${opts.message || this.desc}`;
|
|
|
1757
1770
|
exports.instantInterval = instantInterval;
|
|
1758
1771
|
exports.isEqual = isEqual;
|
|
1759
1772
|
exports.jwtDecode = jwtDecode;
|
|
1773
|
+
exports.kebabCase = kebabCase;
|
|
1760
1774
|
exports.makeArray = makeArray;
|
|
1761
1775
|
exports.makeUnique = makeUnique;
|
|
1762
1776
|
exports.matchAll = matchAll;
|
|
@@ -1764,12 +1778,14 @@ ${opts.message || this.desc}`;
|
|
|
1764
1778
|
exports.mixin = mixin;
|
|
1765
1779
|
exports.pad = pad;
|
|
1766
1780
|
exports.parseUrl = parseUrl;
|
|
1781
|
+
exports.pascalCase = pascalCase;
|
|
1767
1782
|
exports.randomHex = randomHex;
|
|
1768
1783
|
exports.randomString = randomString;
|
|
1769
1784
|
exports.randomStringBuilder = randomStringBuilder;
|
|
1770
1785
|
exports.search = search;
|
|
1771
1786
|
exports.sleep = sleep;
|
|
1772
1787
|
exports.sleepWhile = sleepWhile;
|
|
1788
|
+
exports.snakeCase = snakeCase;
|
|
1773
1789
|
exports.sortByProp = sortByProp;
|
|
1774
1790
|
exports.strSplice = strSplice;
|
|
1775
1791
|
exports.timeUntil = timeUntil;
|