@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.mjs CHANGED
@@ -638,6 +638,17 @@ 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(ms) {
642
+ if (isNaN(ms) || ms < 0) return "Invalid input";
643
+ const seconds = ms / 1e3;
644
+ const minutes = seconds / 60;
645
+ const hours = minutes / 60;
646
+ const days = hours / 24;
647
+ if (days >= 1) return `${days.toFixed(1)} days`;
648
+ else if (hours >= 1) return `${hours.toFixed(1)} hours`;
649
+ else if (minutes >= 1) return `${minutes.toFixed(1)} minutes`;
650
+ else return `${seconds.toFixed(1)} seconds`;
651
+ }
641
652
  function formatPhoneNumber(number) {
642
653
  const parts = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(number);
643
654
  if (!parts) throw new Error(`Number cannot be parsed: ${number}`);
@@ -2314,6 +2325,7 @@ export {
2314
2325
  formData,
2315
2326
  formatBytes,
2316
2327
  formatDate,
2328
+ formatMs,
2317
2329
  formatPhoneNumber,
2318
2330
  fracToDec,
2319
2331
  fromCsv,