@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.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);
|
|
@@ -1233,8 +1245,9 @@ const _Http = class _Http {
|
|
|
1233
1245
|
request(opts = {}) {
|
|
1234
1246
|
var _a;
|
|
1235
1247
|
if (!this.url && !opts.url) throw new Error("URL needs to be set");
|
|
1236
|
-
let url = ((
|
|
1237
|
-
|
|
1248
|
+
let url = ((_a = opts.url) == null ? void 0 : _a.startsWith("http")) ? opts.url : (this.url || "") + (opts.url || "");
|
|
1249
|
+
url = url.replaceAll(/([^:]\/)\/+/g, "$1");
|
|
1250
|
+
if (opts.fragment) url.includes("#") ? url.replace(/#.*(\?|\n)/g, (match, arg1) => `#${opts.fragment}${arg1}`) : `${url}#${opts.fragment}`;
|
|
1238
1251
|
if (opts.query) {
|
|
1239
1252
|
const q = Array.isArray(opts.query) ? opts.query : Object.keys(opts.query).map((k) => ({ key: k, value: opts.query[k] }));
|
|
1240
1253
|
url += (url.includes("?") ? "&" : "?") + q.map((q2) => `${q2.key}=${q2.value}`).join("&");
|
|
@@ -1754,6 +1767,7 @@ export {
|
|
|
1754
1767
|
instantInterval,
|
|
1755
1768
|
isEqual,
|
|
1756
1769
|
jwtDecode,
|
|
1770
|
+
kebabCase,
|
|
1757
1771
|
makeArray,
|
|
1758
1772
|
makeUnique,
|
|
1759
1773
|
matchAll,
|
|
@@ -1761,12 +1775,14 @@ export {
|
|
|
1761
1775
|
mixin,
|
|
1762
1776
|
pad,
|
|
1763
1777
|
parseUrl,
|
|
1778
|
+
pascalCase,
|
|
1764
1779
|
randomHex,
|
|
1765
1780
|
randomString,
|
|
1766
1781
|
randomStringBuilder,
|
|
1767
1782
|
search,
|
|
1768
1783
|
sleep,
|
|
1769
1784
|
sleepWhile,
|
|
1785
|
+
snakeCase,
|
|
1770
1786
|
sortByProp,
|
|
1771
1787
|
strSplice,
|
|
1772
1788
|
timeUntil,
|