vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
23 lines (22 loc) • 541 B
JavaScript
export { humanizeTime };
function humanizeTime(milliseconds) {
const seconds = milliseconds / 1000;
if (seconds < 120) {
const n = round(seconds);
return `${n} second${plural(n)}`;
}
{
const minutes = seconds / 60;
const n = round(minutes);
return `${n} minute${plural(n)}`;
}
}
function round(n) {
let rounded = n.toFixed(1);
if (rounded.endsWith('.0'))
rounded = rounded.slice(0, -2);
return rounded;
}
function plural(n) {
return n === '1' ? '' : 's';
}