@ztimson/utils 0.26.15 → 0.26.17
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 +14 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +14 -1
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +6 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -642,6 +642,18 @@ ${opts.message || this.desc}`;
|
|
|
642
642
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
643
643
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + " " + sizes[i];
|
|
644
644
|
}
|
|
645
|
+
function formatMs(number) {
|
|
646
|
+
const ms = parseInt(number, 10);
|
|
647
|
+
if (isNaN(ms) || ms < 0) return "Invalid input";
|
|
648
|
+
const seconds = ms / 1e3;
|
|
649
|
+
const minutes = seconds / 60;
|
|
650
|
+
const hours = minutes / 60;
|
|
651
|
+
const days = hours / 24;
|
|
652
|
+
if (days >= 1) return `${days.toFixed(1)} days`;
|
|
653
|
+
else if (hours >= 1) return `${hours.toFixed(1)} hours`;
|
|
654
|
+
else if (minutes >= 1) return `${minutes.toFixed(1)} minutes`;
|
|
655
|
+
else return `${seconds.toFixed(1)} seconds`;
|
|
656
|
+
}
|
|
645
657
|
function formatPhoneNumber(number) {
|
|
646
658
|
const parts = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(number);
|
|
647
659
|
if (!parts) throw new Error(`Number cannot be parsed: ${number}`);
|
|
@@ -1529,7 +1541,7 @@ ${opts.message || this.desc}`;
|
|
|
1529
1541
|
if (!this.url && !opts.url) throw new Error("URL needs to be set");
|
|
1530
1542
|
let url = ((_a = opts.url) == null ? void 0 : _a.startsWith("http")) ? opts.url : (this.url || "") + (opts.url || "");
|
|
1531
1543
|
url = url.replaceAll(/([^:]\/)\/+/g, "$1");
|
|
1532
|
-
if (opts.fragment) url.includes("#") ? url.replace(/#.*(
|
|
1544
|
+
if (opts.fragment) url.includes("#") ? url.replace(/#.*([?\n])/g, (match, arg1) => `#${opts.fragment}${arg1}`) : `${url}#${opts.fragment}`;
|
|
1533
1545
|
if (opts.query) {
|
|
1534
1546
|
const q = Array.isArray(opts.query) ? opts.query : Object.keys(opts.query).map((k) => ({ key: k, value: opts.query[k] }));
|
|
1535
1547
|
url += (url.includes("?") ? "&" : "?") + q.map((q2) => `${q2.key}=${q2.value}`).join("&");
|
|
@@ -2317,6 +2329,7 @@ ${opts.message || this.desc}`;
|
|
|
2317
2329
|
exports2.formData = formData;
|
|
2318
2330
|
exports2.formatBytes = formatBytes;
|
|
2319
2331
|
exports2.formatDate = formatDate;
|
|
2332
|
+
exports2.formatMs = formatMs;
|
|
2320
2333
|
exports2.formatPhoneNumber = formatPhoneNumber;
|
|
2321
2334
|
exports2.fracToDec = fracToDec;
|
|
2322
2335
|
exports2.fromCsv = fromCsv;
|