{"name":"itty-time","version":"2.0.2","description":"Smaller and faster than ms.","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","exports":{".":{"import":"./index.mjs","types":"./index.d.ts","require":"./index.cjs"},"./datePlus":{"import":"./datePlus.mjs","types":"./datePlus.d.ts","require":"./datePlus.cjs"},"./duration":{"import":"./duration.mjs","types":"./duration.d.ts","require":"./duration.cjs"},"./ms":{"import":"./ms.mjs","types":"./ms.d.ts","require":"./ms.cjs"},"./seconds":{"import":"./seconds.mjs","types":"./seconds.d.ts","require":"./seconds.cjs"}},"scripts":{"dev":"bun test --watch --coverage","test":"bun test --coverage","lint":"itty lint","build":"itty lint && itty build --hybrid","release":"itty release --prepare --tag --push","release:next":"itty release --prepare --tag --push --type=next"},"keywords":["humanize","duration","ttl","ms","months","time","dates","string","readable"],"repository":{"type":"git","url":"git+https://github.com/kwhitley/itty-time.git"},"author":{"name":"Kevin R. Whitley","email":"krwhitley@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/kwhitley/itty-time/issues"},"devDependencies":{"@types/bun":"^1.2.17","itty-packager":"^1.6.7"},"_id":"itty-time@2.0.2","gitHead":"ef8520d4115a8cb381c6f32bb07769703dc0ba34","homepage":"https://github.com/kwhitley/itty-time#readme","_nodeVersion":"22.9.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-95U9Xo3Qggz/e82ewZQJw8x76HgiMvbrijzoPy6nCTae4FZEwbcVJgrB57Kvddf8Q5pQdgJKTX6euFJpDr6Low==","shasum":"3cae94f1625898084e88e0f1548de3ad4de630f6","tarball":"http://registry-npm.ywwl.com/itty-time/download/itty-time-2.0.2.tgz","fileCount":19,"unpackedSize":11347,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICEH0G/UW0Zp2GQj8RlxIMUzh4/UPki+UUh2Ff3y0fJEAiACz1IJASSGDxRHfvoEckXbUPXbzs67uxzZ+epMZ3RE4g=="}],"size":4506,"noattachment":false,"key":"/itty-time/-/itty-time-2.0.2.tgz"},"_npmUser":{"name":"krwhitley","email":"krwhitley@gmail.com"},"directories":{},"maintainers":[{"name":"krwhitley","email":"krwhitley@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/itty-time_2.0.2_1753561987227_0.15463956837517734"},"_hasShrinkwrap":false,"readme":"<br />\n\n<p>\n<a href=\"https://itty.dev/itty-time\" target=\"_blank\">\n  <img src=\"https://github.com/kwhitley/itty-time/assets/865416/e45b9e04-a442-43b1-9961-59d62c62e88a\" alt=\"itty-time\" height=\"120\" />\n</a>\n</p>\n\n[![GitHub](https://img.shields.io/badge/GitHub-%23555.svg?style=flat-square&logo=github&logoColor=#fff)](https://github.com/kwhitley/itty-time)\n[![Version](https://img.shields.io/npm/v/itty-time.svg?style=flat-square)](https://npmjs.com/package/itty-time)\n[![Bundle Size](https://deno.bundlejs.com/?q=itty-time&badge&badge-style=flat-square)](https://deno.bundlejs.com/?q=itty-time)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/kwhitley/itty-time/verify.yml?branch=v2.x&style=flat-square)](https://github.com/kwhitley/itty-time/actions/workflows/verify.yml)\n[![Coverage Status](https://img.shields.io/coveralls/github/kwhitley/itty-time/v2.x?style=flat-square)](https://coveralls.io/github/kwhitley/itty-time?branch=v2.x)\n[![Issues](https://img.shields.io/github/issues/kwhitley/itty-time?style=flat-square)](https://github.com/kwhitley/itty-time/issues)\n[![Discord](https://img.shields.io/discord/832353585802903572?label=Discord&logo=Discord&style=flat-square&logoColor=fff)](https://discord.gg/WQnqAsjhd6)\n\n###  [v1 Documentation](https://itty.dev/itty-time) &nbsp;| &nbsp; [Discord](https://discord.gg/53vyrZAu9u)\n\n---\n\n# Smaller and faster than ms.\nWhat more do you need to know?\n\n## Features\n\n- Tiny. The entire library is ~390 bytes, and fully tree-shakeable.\n- Convert string durations to ms/seconds.\n- Convert ms to human-readable string durations.\n- Add durations to dates.\n\n## Comparison to other top-rated libraries\n| library | string to ms | ms to string | date math | size<sup>1</sup>\n| --- | :-: | :-: | :-: | :-: |\n| [itty-time](https://www.npmjs.com/package/itty-time) | ✅ | ✅ | ✅ | 391b |\n| [@lukeed/ms](https://www.npmjs.com/package/@lukeed/ms) | ✅ | ✅ | ❌ | 435b |\n| [ms](https://www.npmjs.com/package/ms) | ✅ | ❌ | ❌ | 938b |\n| [pretty-ms](https://www.npmjs.com/package/pretty-ms) | ❌ | ✅ | ❌ | 1.04kB |\n| [humanize-duration](https://www.npmjs.com/package/humanize-duration) | ❌ | ✅ | ❌ | 6.74kB |\n\n<sup>1: minified and gzipped</sup> &nbsp;\n\n## Performance\n\nThe only function most folks care about in terms of raw performance is string to ms conversion.  In this, itty stacks up pretty well, being significantly faster than [ms](https://www.npmjs.com/package/ms), but falling to the insanely-optimized [@lukeed/ms](https://www.npmjs.com/package/@lukeed/ms).\n\n![image](https://github.com/kwhitley/itty-time/assets/865416/71170005-7962-4bc8-9a66-f4ad5713e545)\n\nMoral of the story, probably don't use [ms](https://www.npmjs.com/package/ms).\n\nUse Luke's if you want the absolute fastest parsing, or itty if you want some of the other functions as well.  If you're byte-counting, itty wins again, but if you're byte-counting that hard, you're probably better off with raw ms math if you can stomach it.\n\n\n---\n\n## seconds/ms\n<h4>\n  <code>seconds(duration: string) => number</code><br />\n  <code>ms(duration: string) => number</code><br />\n</h4>\n\nTTL math is a maintenance nightmare. It's a pain to write, a pain to read, and when you update the math later, you'll probably forget to update the comment, causing all sorts of mayhem.\n\n```ts\nconst TTL = 2 * 7 * 24 * 60 * 60 * 1000 // 2 weeks, right?\n```\n\nHere's a better way.\n\n```ts\nimport { ms, seconds } from 'itty-time'\n\n// to seconds\nseconds('2 weeks') // 1209600\n\n// to milliseconds\nms('2 weeks') // 1209600000\n```\n\n## duration\n<h4>\n  <code>duration(ms: number) => string</code>\n</h4>\n\nOf course, we sometimes need to go the other direction.  Want to tell a user how long ago something happened?  How much time they have left?\n\nYou could build it yourself, or import the fantastic [humanize-duration](https://www.npmjs.com/package/humanize-duration) library that inspired this, but at 6.3kB<sup>1</sup>, it's over 20x the size of this 280 byte function.\n\n<sup>1: of course [humanize-duration](https://www.npmjs.com/package/humanize-duration) can also do much, much more.</sup>\n\n```ts\nimport { duration } from 'itty-time'\n\nduration(3750000)\n// \"1 hour, 2 minutes, 30 seconds\"\n\n// limit number of segments returned\nduration(3750000, { parts: 2 })\n// \"1 hour, 2.5 minutes\"\n\n// change the delimiter\nduration(3750000, { join: ' --> ' })\n// \"1 hour --> 2 minutes --> 30 seconds\"\n\n// or get the raw components\nduration(3750000, { join: false })\n/*\n  [\n    ['hour', 1],\n    ['minutes', 2],\n    ['seconds', 30]\n  ]\n/*\n```\n\n## datePlus\n<h4>\n  <code>datePlus(duration: string, from = new Date) => Date</code>\n</h4>\n\nSometimes you need a TTL for some point in the future, but sometimes you need the actual date.  You could convert it all yourself... or use this.\n\n```js\nimport { datePlus } from 'itty-time'\n\n// from right now\ndatePlus('2 months')\n\n// or from a different date\ndatePlus('2 months', datePlus('1 week'))\n```\n","publish_time":1753561987426,"_cnpm_publish_time":1753561987426,"dist-tags":{"latest":"2.0.2","next":"1.0.6-next.0"}}