Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

itty-time

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

itty-time - npm Package Compare versions

Comparing version 1.0.0-next.3 to 1.0.0-next.4

2

datePlus.js

@@ -1,2 +0,2 @@

"use strict";const e=36e5,t=24*e,n={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3,m:1};exports.datePlus=(e,t=new Date)=>new Date(t.getTime()+(e=>{if(+e)return+e;const[,t,r]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*n[r]})(e));
"use strict";const e=36e5,t=24*e,n={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3};exports.datePlus=(e,t=new Date)=>new Date(t.getTime()+(e=>{if(+e)return+e;const[,t,r]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*(n[r]||1)})(e));
//# sourceMappingURL=datePlus.js.map

@@ -1,2 +0,2 @@

"use strict";const e=36e5,o=24*e,t={year:315576e5,month:30*o,week:7*o,day:o,hour:e,minute:6e4,second:1e3,m:1};exports.duration=(e,{parts:o,join:s=", "}={},n=[])=>{for(const[o,s]of Object.entries(t))if(e>=s){const t=Math.floor(e/s);e%=s,n.push([o+(t>1||"m"==o?"s":""),t])}return s?n.slice(0,o).map((([e,o])=>o+" "+e)).join(s):n.slice(0,o)};
"use strict";const e=36e5,s=24*e,t={year:315576e5,month:30*s,week:7*s,day:s,hour:e,minute:6e4,second:1e3};exports.duration=(e,{parts:s,join:o=", "}={},n=[])=>{for(const[s,o]of Object.entries(t)){let t=e/o|0;t&&(e-=t*o,"second"==s&&(t+=e/1e3),n.push([t>1?s+"s":s,t]))}return o?n.slice(0,s).map((([e,s])=>s+" "+e)).join(o):n.slice(0,s)};
//# sourceMappingURL=duration.js.map

@@ -1,2 +0,2 @@

"use strict";const e=36e5,t=24*e,s={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3,m:1},o=e=>{if(+e)return+e;const[,t,o]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*s[o]};exports.datePlus=(e,t=new Date)=>new Date(t.getTime()+o(e)),exports.duration=(e,{parts:t,join:o=", "}={},r=[])=>{for(const[t,o]of Object.entries(s))if(e>=o){const s=Math.floor(e/o);e%=o,r.push([t+(s>1||"m"==t?"s":""),s])}return o?r.slice(0,t).map((([e,t])=>t+" "+e)).join(o):r.slice(0,t)},exports.ms=o,exports.seconds=e=>o(e)/1e3;
"use strict";const e=36e5,t=24*e,s={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3},n=e=>{if(+e)return+e;const[,t,n]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*(s[n]||1)};exports.datePlus=(e,t=new Date)=>new Date(t.getTime()+n(e)),exports.duration=(e,{parts:t,join:n=", "}={},o=[])=>{for(const[t,n]of Object.entries(s)){let s=e/n|0;s&&(e-=s*n,"second"==t&&(s+=e/1e3),o.push([s>1?t+"s":t,s]))}return n?o.slice(0,t).map((([e,t])=>t+" "+e)).join(n):o.slice(0,t)},exports.ms=n,exports.seconds=e=>n(e)/1e3;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

"use strict";const e=36e5,t=24*e,r={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3,m:1};exports.ms=e=>{if(+e)return+e;const[,t,s]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*r[s]};
"use strict";const e=36e5,t=24*e,r={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3};exports.ms=e=>{if(+e)return+e;const[,t,s]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*(r[s]||1)};
//# sourceMappingURL=ms.js.map
{
"name": "itty-time",
"version": "1.0.0-next.3",
"description": "Ultra-small (~420 bytes) library for date math and converting durations to and from strings.",
"version": "1.0.0-next.4",
"description": "Ultra-small (~400 bytes) library for TTL date math and converting ms durations to and from strings.",
"main": "./index.js",

@@ -6,0 +6,0 @@ "module": "./index.mjs",

@@ -47,11 +47,10 @@ <br />

Ultra-small (~420 bytes) library for date math and converting durations to and from strings.
Ultra-small (~400 bytes) library for TTL date math and converting ms durations to and from strings.
## Features
- Tiny. The entire library is ~420 bytes, or take only what you need.
- Use text strings (including multi-part) to describe durations.
- Tiny. The entire library is ~400 bytes, or take only what you need.
- Convert string durations to ms/seconds.
- Convert ms to human-readable string durations.
- Add durations to dates.
- Get human-readable durations from ms duration.
- Works everywhere.

@@ -61,10 +60,11 @@ ## Comparison to other top-rated libraries

| --- | :-: | :-: | :-: | :-: | :-: |
| [itty-time](https://www.npmjs.com/package/itty-time) | ✅ | ✅ | ✅ | 400b | **1x** |
| [@lukeed/ms](https://www.npmjs.com/package/@lukeed/ms) | ✅ | ✅ | ❌ | 435b | 1.01x |
| [ms](https://www.npmjs.com/package/ms) | ✅ | ❌ | ❌ | 938b | 2.04x |
| [pretty-ms](https://www.npmjs.com/package/pretty-ms) | ❌ | ✅ | ❌ | 1.04kB | 2.31x |
| [humanize-duration](https://www.npmjs.com/package/humanize-duration) | ❌ | ✅ | ❌ | 6.74kB | 15x |
| [itty-time](https://www.npmjs.com/package/itty-time)<sup>3</sup> | ✅ | ✅ | ✅ | 395b | **1x** |
| [@lukeed/ms](https://www.npmjs.com/package/@lukeed/ms) | ✅ | ✅ | ❌ | 435b | 1.1x |
| [ms](https://www.npmjs.com/package/ms) | ✅ | ❌ | ❌ | 938b | 2.4x |
| [pretty-ms](https://www.npmjs.com/package/pretty-ms) | ❌ | ✅ | ❌ | 1.04kB | 2.7x |
| [humanize-duration](https://www.npmjs.com/package/humanize-duration) | ❌ | ✅ | ❌ | 6.74kB | 17.5x |
<sup>1: minified and gzipped</sup> &nbsp;
<sup>2: smaller is better</sup> &nbsp;
<sup>3: we're including the entire library</sup> &nbsp;

@@ -95,5 +95,2 @@ ---

ms('2 weeks') // 1209600000
// handles multi-part inputs :)
ms('3 days, 2.5 hours, and 1 minute') // 268260000
```

@@ -108,3 +105,3 @@

You 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 20x the size of this function (300 bytes).
You 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.

@@ -149,3 +146,3 @@ <sup>1: of course [humanize-duration](https://www.npmjs.com/package/humanize-duration) can also do much, much more.</sup>

// from right now
datePlus('2 months, 1 week')
datePlus('2 months')

@@ -152,0 +149,0 @@ // or from a different date

@@ -1,2 +0,2 @@

"use strict";const e=36e5,t=24*e,s={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3,m:1};exports.seconds=e=>(e=>{if(+e)return+e;const[,t,n]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*s[n]})(e)/1e3;
"use strict";const e=36e5,t=24*e,s={year:315576e5,month:30*t,week:7*t,day:t,hour:e,minute:6e4,second:1e3};exports.seconds=e=>(e=>{if(+e)return+e;const[,t,n]=e.match(/^([^ ]+) *(\w\w*?)s?$/)||[];return+t*(s[n]||1)})(e)/1e3;
//# sourceMappingURL=seconds.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc