The ms npm package converts human-readable time strings to milliseconds and back, with TypeScript types and strict parsing helpers.
Overview
ms accepts strings with numeric values and units such as minutes or hours and returns equivalent millisecond counts. Passing a number returns a readable string with a unit instead.
Version 3 adds TypeScript definitions using template literal types to reject invalid strings at compile time. Optional parseStrict enforces unit casing and spacing rules.
Helper exports parse and format can be imported separately for tree-shaken usage. The package is compatible with Vercel Edge Runtime environments.
Installers include npm, yarn, pnpm, deno, and bun.
Key features
- String to millisecond conversion
- Number to labeled string output
- TypeScript template literal types
- parseStrict validation mode
- Separate parse and format exports
- Fractional duration support
- Edge runtime compatibility
Use cases
- Config timeout parsing
- Human-readable delay labels
- Type-safe duration constants
- Edge function timing helpers