A tiny utility to convert human-readable time strings to milliseconds and vice versa.
ms is a lightweight JavaScript utility library that converts human-readable time strings (like '2 days' or '10 hours') into milliseconds and formats milliseconds back into readable time strings. It solves the problem of manual time unit calculations in code by providing a simple, consistent API for time parsing and formatting.
JavaScript and TypeScript developers working with time durations in applications, especially those needing to parse user input, format timers, or handle time intervals in a readable way.
Developers choose ms for its tiny size, zero dependencies, robust TypeScript support, and cross-runtime compatibility, making it the go-to solution for reliable time conversions without the overhead of larger date libraries.
Tiny millisecond conversion utility
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Parses a wide range of time strings with multiple unit abbreviations and spacings, converting them directly to milliseconds for easy calculations, as shown in the examples for '2.5 hrs' or '1y'.
With zero dependencies and a minimal footprint, ms is ideal for projects where bundle size is a concern, such as Edge Runtime functions or serverless environments.
Includes template literal types for compile-time validation of time strings, reducing runtime errors, and offers parseStrict for enhanced type safety in TypeScript projects.
Works seamlessly across browsers, Node.js, Deno, Bun, and Edge Runtime, ensuring consistent behavior in diverse JavaScript environments without extra configuration.
Uses fixed millisecond values for months (2629800000 ms) and years (31557600000 ms), which are averages and may not match real calendar durations, limiting precision for accurate time calculations.
Limited to duration parsing and formatting; cannot handle dates, time zones, or daylight saving adjustments, requiring additional libraries for such tasks in comprehensive applications.
Strict type checking with parseStrict can be cumbersome for dynamic strings, often necessitating type assertions that bypass safety, as noted in the README's cautionary examples.