itty-time

Btw, we just dropped "itty-time" v1 on NPM as a direct rival to the popular "ms" library. At 386 bytes for the entire library, it handles ms/second conversions (great for TTLs like with KV), creates human-readable durations, and can do readable date math (great for expiration dates). https://www.npmjs.com/package/itty-time itty-time/ms: 183 bytes, 9.7m ops/sec ms: 938 bytes, 5.6m ops/sec
npm
itty-time
Ultra-small (~390 bytes) library for TTL date math and converting ms durations to and from strings.. Latest version: 1.0.3, last published: 11 hours ago. Start using itty-time in your project by running npm i itty-time. There are no other projects in the npm registry using itty-time.
No description
3 Replies
Kevin
Kevin•7mo ago
Absolutely not... but then I don't think other ones do either 🙂 We originally tried to do clever things like that with "months" for instance (by instantiating dates, then modifying attributes and doing the diff), but that's waaaaaaaaay slower/bigger than straight ms math. In the end, the more common use cases are the ones we have to target, which means dead simple segments like "1 month" and "3 days", etc. Thus our months (which the official ms library doesn't even support) are merely 30 days, which of course is an approximation. nah, that's showing the tree-shaked itty-time/ms :p
Kevin
Kevin•7mo ago
but I guess I did undersell by 3 bytes
No description
Kevin
Kevin•7mo ago
...the product of countless hours with a frustratingly bad ChatGPT as a code-golfing assistant, paired with a benchmarking suite to keep performance in balance.
Want results from more Discord servers?
Add your server