ms

Tiny utility for converting time durations between human-readable strings and milliseconds. Converts '2 days', '1h', '10m', '30s', '100ms' to millisecond values and vice versa. Zero dependencies, tiny (< 1KB). Used everywhere JWT expiration ('7d' → 604800000), cache TTL configuration, setTimeout/setInterval helpers, and any code that needs human-readable time duration strings. Maintained by Vercel.

Evaluated Mar 06, 2026 (0d ago) v2.x
Homepage ↗ Repo ↗ Developer Tools time milliseconds duration parsing formatting node browser tiny
&#9881; Agent Friendliness
71
/ 100
Can an agent use this?
&#128274; Security
99
/ 100
Is it safe for agents?
&#9889; Reliability
96
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
95
Error Messages
85
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
95
Secret Handling
100

Tiny utility library — no network surface. ReDoS vulnerability fixed in 2.1.3 — use updated version.

⚡ Reliability

Uptime/SLA
98
Version Stability
95
Breaking Changes
95
Error Recovery
95
AF Security Reliability

Best When

You need to convert between human-readable duration strings ('2h', '30m') and milliseconds anywhere in your Node.js or browser code.

Avoid When

You need ISO 8601 duration parsing, full date arithmetic, or calendar-aware time calculations — use date-fns or Temporal.

Use Cases

  • Convert JWT expiration strings to milliseconds: ms('7d') for token expiry configuration
  • Format cache TTL configurations: ms('1h') → 3600000 for Redis/cache expiry settings
  • Convert setTimeout/setInterval durations: setTimeout(fn, ms('30s')) for readable timeout code
  • Format milliseconds to human-readable: ms(1500, { long: true }) → '1 second and 500 milliseconds'
  • Parse user-facing duration inputs in configuration files, APIs, or CLI tools

Not For

  • Full date/time manipulation — use date-fns or Luxon for date arithmetic
  • Timezone-aware duration calculations — ms handles pure duration, not calendar-aware time
  • ISO 8601 duration strings (PT1H30M) — ms uses informal shorthand, not ISO standard

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No authentication — utility library.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

Fully free, MIT licensed.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • Returns undefined for invalid input — always check: const delay = ms('2 houurs'); if (!delay) throw new Error('Invalid duration'); don't use undefined values as timeouts
  • Supported units: ms supports 'ms', 's', 'm', 'h', 'd', 'w', 'y' — no months support (months are ambiguous in milliseconds); use days for month-range durations
  • Reverse conversion precision: ms(1500) returns '2s' (rounded); ms(1500, { long: true }) returns '1 second' — different precision modes
  • ReDoS: older versions had a ReDoS vulnerability — use ms >= 2.1.3 for security-fixed version; keep dependency up to date
  • Floating point: ms('1.5h') returns 5400000 (1.5 * 3600 * 1000) — fractional units are supported
  • Case sensitivity: 'H', 'Hours', 'HOURS' are all accepted — case insensitive parsing is forgiving

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for ms.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered