Comparing version 0.1.1 to 0.1.2
@@ -7,3 +7,2 @@ declare const getDuration: (duration: string) => { | ||
declare const getTTL: (duration: string) => number; | ||
declare const divideBy: (divisor: string) => (duration: string) => number; | ||
declare const divide: (duration: string) => { | ||
@@ -13,2 +12,2 @@ by: (divisor: string) => number; | ||
export { divide, divideBy, getDatePlus, getDuration, getTTL }; | ||
export { divide, getDatePlus, getDuration, getTTL }; |
@@ -1,1 +0,1 @@ | ||
var a=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var v=(n,t)=>{for(var e in t)a(n,e,{get:t[e],enumerable:!0})},m=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of w(t))!h.call(n,s)&&s!==e&&a(n,s,{get:()=>t[s],enumerable:!(o=D(t,s))||o.enumerable});return n};var y=n=>m(a({},"__esModule",{value:!0}),n);var k={};v(k,{divide:()=>$,divideBy:()=>M,getDatePlus:()=>c,getDuration:()=>d,getTTL:()=>u});module.exports=y(k);var d=n=>{let t=n.match(/^(?<strValue>[\d.]+)?\s?(?<unit>\w+?)s?$/),{strValue:e,unit:o}=t.groups;return{value:+(e===void 0?1:e),unit:o}},c=n=>{let t=n.split(/,?\s*and\s*|,\s*/),e=new Date;for(let o of t){let{value:s,unit:i}=d(o),l={Days:"Date",Weeks:"Date",Years:"Month",Months:"Month"},g={Weeks:7,Years:12},r=i.charAt(0).toUpperCase()+i.slice(1)+"s",p=g[r]||1;r=l[r]||r;let[x,f]=[`get${r}`,`set${r}`];e=new Date(e[f](e[x]()+s*p))}return e},u=n=>{let t=+new Date;return(+c(n)-t)/1e3|0},M=n=>{let t=u(n);return e=>{let o=+new Date/1e3|0;return((+c(e)/1e3|0)-o)/t}},$=n=>({by:t=>{let e=+new Date/1e3|0;return((+c(n)/1e3|0)-e)/u(t)}});0&&(module.exports={divide,divideBy,getDatePlus,getDuration,getTTL}); | ||
var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var n in t)c(e,n,{get:t[n],enumerable:!0})},m=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of w(t))!h.call(e,s)&&s!==n&&c(e,s,{get:()=>t[s],enumerable:!(o=f(t,s))||o.enumerable});return e};var M=e=>m(c({},"__esModule",{value:!0}),e);var k={};v(k,{divide:()=>$,getDatePlus:()=>a,getDuration:()=>u,getTTL:()=>l});module.exports=M(k);var u=e=>{let t=e.match(/^(?<strValue>[\d.]+)?\s?(?<unit>\w+?)s?$/),{strValue:n,unit:o}=t.groups;return{value:+(n===void 0?1:n),unit:o}},a=e=>{let t=e.split(/,?\s*and\s*|,\s*/),n=new Date;for(let o of t){let{value:s,unit:i}=u(o),g={Days:"Date",Weeks:"Date",Years:"Month",Months:"Month"},p={Weeks:7,Years:12},r=i.charAt(0).toUpperCase()+i.slice(1)+"s",d=p[r]||1;r=g[r]||r;let[x,D]=[`get${r}`,`set${r}`];n=new Date(n[D](n[x]()+s*d))}return n},l=e=>{let t=+new Date;return(+a(e)-t)/1e3|0},$=e=>({by:t=>{let n=+new Date/1e3|0;return((+a(e)/1e3|0)-n)/l(t)}});0&&(module.exports={divide,getDatePlus,getDuration,getTTL}); |
{ | ||
"name": "itty-time", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A tiny library to handle common time-related things for your API in a beautiful way.", | ||
@@ -5,0 +5,0 @@ "sourceType": "module", |
@@ -14,7 +14,7 @@ # ![itty-time](https://user-images.githubusercontent.com/865416/197366211-0b93287c-50fb-4f2e-b78e-ff1a8aa7d635.png) | ||
Tiny (~600 bytes) time math library for making your APIs beautiful. | ||
Tiny (~530 bytes) time math library for making date handling and TTLs within your APIs beautiful. | ||
## Features | ||
- Tiny. This IS an itty lib, after all! | ||
- Tiny @ ~530 bytes gzipped | ||
- Fully typed/TypeScript support | ||
@@ -29,3 +29,3 @@ - Use plain text strings to describe time, not seconds/milliseconds | ||
```js | ||
import { getTTL, divide, getDatePlus } = 'itty-time' // under 600 bytes | ||
import { getTTL, divide, getDatePlus } from 'itty-time' // under 600 bytes | ||
@@ -39,28 +39,24 @@ // Easily get TTL in seconds | ||
// Need an expiration date? | ||
getDatePlus('5 seconds') => 2022-10-22T23:10:11.824Z | ||
getDatePlus('1 minutes') => 2022-10-22T23:11:06.824Z | ||
getDatePlus('2 months') => 2022-12-23T00:11:58.534Z | ||
getDatePlus('4 years') => 2026-10-22T23:11:58.534Z | ||
getDatePlus('5 seconds') // 2022-10-22T23:10:11.824Z | ||
getDatePlus('1 minutes') // 2022-10-22T23:11:06.824Z | ||
getDatePlus('2 months') // 2022-12-23T00:11:58.534Z | ||
getDatePlus('4 years') // 2026-10-22T23:11:58.534Z | ||
// Want to find out how many X are in Y? | ||
divide('1 week').by('days') = 7 | ||
divide('2 minutes').by('seconds') = 120 | ||
divide('3 days').by('hours') = 72 | ||
divide('1 day').by('3 hours') = 8 | ||
divide('1 week').by('seconds') = 604800 | ||
divide('24 hours').by('minutes') = 1440 | ||
divide('3 days').by('hours') = 72 | ||
divide('1 day, 30 minutes').by('hours') = 24.5 | ||
divide('1 week').by('days') // 7 | ||
divide('2 minutes').by('seconds') // 120 | ||
divide('3 days').by('hours') // 72 | ||
divide('1 day').by('3 hours') // 8 | ||
divide('1 week').by('seconds') // 604800 | ||
divide('24 hours').by('minutes') // 1440 | ||
divide('3 days').by('hours') // 72 | ||
divide('1 day, 30 minutes').by('hours') // 24.5 | ||
``` | ||
/* | ||
## DISCLAIMER: This is a CONVENIENCE library for making short, readable code. | ||
DISCLAIMER: This is a CONVENIENCE library for making short, readable code. | ||
If you need absolute max performance for iterative work in a single thread, do the operations manually. That's always faster. | ||
Otherwise, you'll never feel the difference, but your code sure will! <3 | ||
Otherwise, you'll probably never feel the difference, but your code sure will! <3 | ||
*/ | ||
``` | ||
# API | ||
@@ -80,6 +76,6 @@ | ||
```ts | ||
getDatePlus('5 seconds') => 2022-10-22T23:10:11.824Z | ||
getDatePlus('1 minutes') => 2022-10-22T23:11:06.824Z | ||
getDatePlus('2 months') => 2022-12-23T00:11:58.534Z | ||
getDatePlus('4 years') => 2026-10-22T23:11:58.534Z | ||
getDatePlus('5 seconds') // 2022-10-22T23:10:11.824Z | ||
getDatePlus('1 minutes') // 2022-10-22T23:11:06.824Z | ||
getDatePlus('2 months') // 2022-12-23T00:11:58.534Z | ||
getDatePlus('4 years') // 2026-10-22T23:11:58.534Z | ||
``` | ||
@@ -91,10 +87,10 @@ | ||
```ts | ||
divide('1 week').by('days') = 7 | ||
divide('2 minutes').by('seconds') = 120 | ||
divide('3 days').by('hours') = 72 | ||
divide('1 day').by('3 hours') = 8 | ||
divide('1 week').by('seconds') = 604800 | ||
divide('24 hours').by('minutes') = 1440 | ||
divide('3 days').by('hours') = 72 | ||
divide('1 day, 30 minutes').by('hours') = 24.5 | ||
divide('1 week').by('days') // 7 | ||
divide('2 minutes').by('seconds') // 120 | ||
divide('3 days').by('hours') // 72 | ||
divide('1 day').by('3 hours') // 8 | ||
divide('1 week').by('seconds') // 604800 | ||
divide('24 hours').by('minutes') // 1440 | ||
divide('3 days').by('hours') // 72 | ||
divide('1 day, 30 minutes').by('hours') // 24.5 | ||
``` |
Sorry, the diff of this file is not supported yet
13571
56
92