{"_id":"parse-duration-ms","name":"parse-duration-ms","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"parse-duration-ms","version":"0.1.0","description":"Parse duration strings to milliseconds","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parse-duration-ms.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && node --test"},"keywords":["parse","duration","time","milliseconds","ms","convert","parser","human","readable","string","text","hours","minutes","seconds","days"],"devDependencies":{"xo":"^1.2.2"},"gitHead":"170bc16cc1d504e160a4379c9c99d8cdd3b337d8","types":"./index.d.ts","_id":"parse-duration-ms@0.1.0","bugs":{"url":"https://github.com/sindresorhus/parse-duration-ms/issues"},"homepage":"https://github.com/sindresorhus/parse-duration-ms#readme","_nodeVersion":"20.19.5","_npmVersion":"11.6.1","dist":{"integrity":"sha512-6yvHGGtBLcxF7pXLOxDOSCD8hnAycp1uiS+4vJ2x5O01wxC0mbEg5Zyc1Ru/+Sj5He/D+IwvQTFQ1SuJ/yAL0g==","shasum":"e9638ce54cf081ed9d30108f4f47ebd38dcaad76","tarball":"https://registry.npmjs.org/parse-duration-ms/-/parse-duration-ms-0.1.0.tgz","fileCount":5,"unpackedSize":7594,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFk3EI54vlQDhBey2cM+pxTYZ6xi/xBKmInRW3Lt2OduAiEAsMK+6ZqBsdG3UEho0nmeWRc4DjNuWAMmtSKG65q/8Ic="}]},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parse-duration-ms_0.1.0_1762056549114_0.413013041668836"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-02T04:09:09.113Z","0.1.0":"2025-11-02T04:09:09.294Z","modified":"2025-11-02T04:09:09.622Z"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"description":"Parse duration strings to milliseconds","homepage":"https://github.com/sindresorhus/parse-duration-ms#readme","keywords":["parse","duration","time","milliseconds","ms","convert","parser","human","readable","string","text","hours","minutes","seconds","days"],"repository":{"type":"git","url":"git+https://github.com/sindresorhus/parse-duration-ms.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"bugs":{"url":"https://github.com/sindresorhus/parse-duration-ms/issues"},"license":"MIT","readme":"# parse-duration-ms\n\n> Parse duration strings to milliseconds\n\nUseful for parsing timeout values, cache TTLs, rate limits, and other duration-based configuration in a human-friendly format.\n\nSee [`pretty-ms`](https://github.com/sindresorhus/pretty-ms) for the inverse.\n\n## Install\n\n```sh\nnpm install parse-duration-ms\n```\n\n## Usage\n\n```js\nimport parseDuration from 'parse-duration-ms';\n\nparseDuration('1h');\n//=> 3600000\n\nparseDuration('90m');\n//=> 5400000\n\nparseDuration('2 days 5 hours 30 minutes');\n//=> 192600000\n\nparseDuration('1hr 30min');\n//=> 5400000\n\nparseDuration('500ms');\n//=> 500\n\nparseDuration('1.5 hours');\n//=> 5400000\n\nparseDuration('1h41m');\n//=> 6060000\n\nparseDuration('invalid');\n//=> undefined\n```\n\n## API\n\n### parseDuration(input)\n\nParses a duration string to milliseconds.\n\nReturns `undefined` if the input is invalid.\n\nThrows a `TypeError` if the input is not a string.\n\n#### input\n\nType: `string`\n\nThe duration string to parse.\n\n**Features:**\n\n- Multiple units: `'1h 30m'`, `'2d 5h 30m'`, `'1 hour 30 minutes'`\n- Shortened forms: `'1hr 30min'`, `'90mins'`, `'2w 3d'`\n- Decimal values: `'1.5h'`, `'0.5m'`, `'1.5 hours'`\n- With or without spaces: `'1h30m'`, `'1h 30m'`, `'1hour'`, `'1 hour'`\n- Case insensitive: `'1H'`, `'30M'`, `'1 HOUR'`\n- Negative values: `'-1h'`, `'-30m'`\n\n**Supported units:**\n\n| Unit | Short | Shorter | Long (singular) | Long (plural) |\n|------|-------|---------|-----------------|---------------|\n| Nanoseconds | `ns` | `nsec`, `nsecs` | `nanosecond` | `nanoseconds` |\n| Milliseconds | `ms` | `msec`, `msecs` | `millisecond` | `milliseconds` |\n| Seconds | `s` | `sec`, `secs` | `second` | `seconds` |\n| Minutes | `m` | `min`, `mins` | `minute` | `minutes` |\n| Hours | `h` | `hr`, `hrs` | `hour` | `hours` |\n| Days | `d` | - | `day` | `days` |\n| Weeks | `w` | - | `week` | `weeks` |\n\n## FAQ\n\n### Why no months/years?\n\nMonths and years aren't fixed durations. They vary (28-31 days for months, 365-366 for years). Any approximation would be silently wrong in many cases. Be explicit instead: use `'30d'` for ~1 month or `'365d'` for ~1 year.\n\n### What's the difference from `ms`?\n\nThis package parses combined units like `'1h 30m'` and `'2 days 5 hours'`. The [`ms`](https://github.com/vercel/ms) package does bidirectional conversion but doesn't support combined units.\n\n### Localization support?\n\nNo. This keeps the package simple and small.\n\n### Dates, timestamps, or time zones?\n\nNo. This only parses relative durations (lengths of time), not absolute times.\n\n## Related\n\n- [pretty-ms](https://github.com/sindresorhus/pretty-ms) - Convert milliseconds to a human readable string\n- [to-milliseconds](https://github.com/sindresorhus/to-milliseconds) - Convert an object of time properties to milliseconds\n- [parse-ms](https://github.com/sindresorhus/parse-ms) - Parse milliseconds into an object\n","readmeFilename":"readme.md","_rev":"1-84afd9fce0870e437706e0a98ccfda5b"}