@ztimson/utils 0.26.16 → 0.26.18
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 +12 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +12 -0
- 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,17 @@ ${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(ms) {
|
|
646
|
+
if (isNaN(ms) || ms < 0) return "Invalid input";
|
|
647
|
+
const seconds = ms / 1e3;
|
|
648
|
+
const minutes = seconds / 60;
|
|
649
|
+
const hours = minutes / 60;
|
|
650
|
+
const days = hours / 24;
|
|
651
|
+
if (days >= 1) return `${days.toFixed(1)} days`;
|
|
652
|
+
else if (hours >= 1) return `${hours.toFixed(1)} hours`;
|
|
653
|
+
else if (minutes >= 1) return `${minutes.toFixed(1)} minutes`;
|
|
654
|
+
else return `${seconds.toFixed(1)} seconds`;
|
|
655
|
+
}
|
|
645
656
|
function formatPhoneNumber(number) {
|
|
646
657
|
const parts = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(number);
|
|
647
658
|
if (!parts) throw new Error(`Number cannot be parsed: ${number}`);
|
|
@@ -2317,6 +2328,7 @@ ${opts.message || this.desc}`;
|
|
|
2317
2328
|
exports2.formData = formData;
|
|
2318
2329
|
exports2.formatBytes = formatBytes;
|
|
2319
2330
|
exports2.formatDate = formatDate;
|
|
2331
|
+
exports2.formatMs = formatMs;
|
|
2320
2332
|
exports2.formatPhoneNumber = formatPhoneNumber;
|
|
2321
2333
|
exports2.fracToDec = fracToDec;
|
|
2322
2334
|
exports2.fromCsv = fromCsv;
|