num-beauty
Version:
An ultra lightweight module for formatting numbers into human-friendly strings
1 lines • 400 B
JavaScript
export function formatDuration(o,r={}){if(o<1e3)return`${o}ms`;const t=Math.floor(o/1e3%60),$=Math.floor(o/6e4%60),s=Math.floor(o/36e5%24),e=Math.floor(o/864e5),h=[],n="long"===r.format;return e>0&&h.push(n?`${e} day${e>1?"s":""}`:`${e}d`),s>0&&h.push(n?`${s} hour${s>1?"s":""}`:`${s}h`),$>0&&h.push(n?`${$} minute${$>1?"s":""}`:`${$}m`),t>0&&h.push(n?`${t} second${t>1?"s":""}`:`${t}s`),h.join(" ")}