Skip to main content
variable formatDuration
import { formatDuration } from "https://deno.land/x/30_seconds_of_typescript@v1.0.1/util.ts";

Returns the human readable format of the given number of milliseconds.

Divide ms with the appropriate values to obtain the appropriate values for day, hour, minute, second and millisecond. Use Object.entries() with Array.prototype.filter() to keep only non-zero values. Use Array.prototype.map() to create the string for each value, pluralizing appropriately. Use String.prototype.join(', ') to combine the values into a string.

type

(ms: number) => unknown