@philiprehberger/pretty-ms
v0.1.2
Published
Convert milliseconds to human-readable strings and back
Readme
@philiprehberger/pretty-ms
Convert milliseconds to human-readable strings and back.
Installation
npm install @philiprehberger/pretty-msUsage
import { prettyMs, parseMs } from '@philiprehberger/pretty-ms';
prettyMs(9015000);
// => "2h 30m 15s"
prettyMs(9015000, { compact: true });
// => "2h"
prettyMs(9015000, { verbose: true });
// => "2 hours 30 minutes 15 seconds"
prettyMs(9015000, { colonNotation: true });
// => "2:30:15"
prettyMs(9015000, { unitCount: 2 });
// => "2h 30m"
parseMs('2h 30m 15s');
// => 9015000
parseMs('2:30:15');
// => 9015000API
prettyMs(ms: number, options?: PrettyMsOptions): string
Convert milliseconds to a human-readable string.
Options:
| Option | Type | Default | Description |
|---|---|---|---|
| compact | boolean | false | Show only the most significant unit |
| verbose | boolean | false | Use full unit names |
| colonNotation | boolean | false | Use colon notation (H:MM:SS) |
| unitCount | number | undefined | Limit to N most significant units |
parseMs(str: string): number
Parse a human-readable duration string back to milliseconds. Supports unit notation (2h 30m 15s) and colon notation (2:30:15).
Development
npm install
npm run build
npm testSupport
If you find this project useful:
