@ztimson/utils 0.26.17 → 0.26.19
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 +5 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +5 -6
- package/dist/index.mjs.map +1 -1
- package/dist/string.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -638,17 +638,16 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
638
638
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
639
639
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + " " + sizes[i];
|
|
640
640
|
}
|
|
641
|
-
function formatMs(
|
|
642
|
-
const ms = parseInt(number, 10);
|
|
641
|
+
function formatMs(ms, short = false) {
|
|
643
642
|
if (isNaN(ms) || ms < 0) return "Invalid input";
|
|
644
643
|
const seconds = ms / 1e3;
|
|
645
644
|
const minutes = seconds / 60;
|
|
646
645
|
const hours = minutes / 60;
|
|
647
646
|
const days = hours / 24;
|
|
648
|
-
if (days >= 1) return `${days.toFixed(1)} days`;
|
|
649
|
-
else if (hours >= 1) return `${hours.toFixed(1)} hours`;
|
|
650
|
-
else if (minutes >= 1) return `${minutes.toFixed(1)} minutes`;
|
|
651
|
-
else return `${seconds.toFixed(1)} seconds`;
|
|
647
|
+
if (days >= 1) return `${days.toFixed(1)} ${short ? "d" : "days"}`;
|
|
648
|
+
else if (hours >= 1) return `${hours.toFixed(1)} ${short ? "h" : "hours"}`;
|
|
649
|
+
else if (minutes >= 1) return `${minutes.toFixed(1)} ${short ? "m" : "minutes"}`;
|
|
650
|
+
else return `${seconds.toFixed(1)} ${short ? "s" : "seconds"}`;
|
|
652
651
|
}
|
|
653
652
|
function formatPhoneNumber(number) {
|
|
654
653
|
const parts = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(number);
|