parse-duration-ms: a JavaScript library that converts human-readable duration strings into milliseconds.
Key features:
- Parses combined units like "1h 30m" and "2 days 5 hours"
- Supports decimal values, shortened forms, and case-insensitive input
- Handles negative durations
- Zero dependencies
- Works in Node.js and browsers
Perfect for parsing timeout values, cache TTLs, rate limits, and configuration strings.
The library returns undefined for invalid input instead of throwing errors, which makes fallback handling cleaner.
π Blog Post
π GitHub Repo
π Live Demo
Top comments (0)