@coverbase/time
Advanced tools
+197
-1
@@ -1,1 +0,197 @@ | ||
| var O=(w)=>{const F=w instanceof Date?w:new Date(w),$=new Intl.RelativeTimeFormat("en"),q={years:31536000,months:2592000,weeks:604800,days:86400,hours:3600,minutes:60,seconds:1},z=(F.getTime()-Date.now())/1000;for(let A in q)if(q[A]<Math.abs(z)){const B=z/q[A];return $.format(Math.round(B),A)}},_=(w,F)=>{const $=new Date(w),q=$.getDate(),z=new Date($.getTime());z.setMonth($.getMonth()+F+1,0);const A=z.getDate();if(q>=A)return z;else $.setFullYear(z.getFullYear(),z.getMonth(),q);return $},P=(w,F)=>{const $=new Date(w);return $.setDate($.getDate()+F),$},R=(w,F)=>{return T(w,F*3600000)},Q=(w,F)=>{return T(w,F*60000)},f=(w,F)=>{return T(w,F*1000)},T=(w,F)=>{return new Date(w.getTime()+F)},W=(w)=>{const F=new Date(w);return F.setDate(1),F.setHours(0,0,0,0),F},E=(w)=>{const F=new Date(w);return F.setHours(0,0,0,0),F},I=(w)=>{const F=new Date(w);return F.setMinutes(0,0,0),F},k=(w)=>{const F=new Date(w);return F.setSeconds(0,0),F},y=(w)=>{const F=new Date(w);return F.setMilliseconds(0),F};var H=[{name:"minute",min:0,max:59},{name:"hour",min:0,max:23},{name:"day",min:1,max:31},{name:"month",min:0,max:11},{name:"weekday",min:0,max:6}];var G=(w)=>{if(typeof w==="string"){const F=w.trim();if(/^\d+$/.test(F)){const $=Number(F);if(!isNaN($)&&isFinite($))return $}}else if(typeof w==="number"){if(!isNaN(w)&&isFinite(w)&&w===Math.floor(w))return w}return},U=(w,F)=>{const $=new Array;for(let q=w;q<=F;q++)$.push(q);return $},S=(w)=>{return w.reduce((F,$)=>F.concat($),[])};var p=(w,F)=>{const $=F.split(" ");if($.length===5){const[q,z,A,B,J]=$.map((K,L)=>C(K,H[L]));let j=Q(new Date(w),1);j.setSeconds(0),j.setMilliseconds(0);let N=24,X=!1,Y=!1,Z=!1;while(--N){while(B.indexOf(j.getMonth())===-1)j=W(_(j,1));const K=j.getMonth();while(A.indexOf(j.getDate())===-1||J.indexOf(j.getDay())===-1)if(j=E(P(j,1)),K!==j.getMonth()){X=!0;break}if(!X){const L=j.getDate();while(z.indexOf(j.getHours())===-1)if(j=I(R(j,1)),L!==j.getDate()){Y=!0;break}if(!Y){const b=j.getHours();while(q.indexOf(j.getMinutes())===-1)if(j=k(Q(j,1)),b!==j.getHours()){Z=!0;break}if(!Z)break}}}return j.setSeconds(0),j.setMilliseconds(0),j}},C=(w,F)=>{const $=w.split(",").map((q)=>{const z=q.split("/");if(z.length>2)throw new Error(`Invalid value "${w}"`);let A;const B=z[0],J=z[1];if(B==="*")A=U(F.min,F.max);else A=D(B);const j=V(J);return c(A,j)});return[...new Set(S($))].sort((q,z)=>q-z)},D=(w)=>{const F=w.split("-");if(F.length===1){const $=G(F[0]);if($===void 0)throw new Error("Invalid value");return[$]}else if(F.length===2){const $=G(F[0]),q=G(F[1]);if($===void 0||q===void 0)throw new Error("Invalid value");if(q<$)throw new Error(`Max range is less than min range in "${w}"`);return U($,q)}else throw new Error(`Invalid value "${w}"`)},V=(w)=>{if(w){const F=G(w);if(F===void 0)throw new Error(`Invalid interval step value "${w}"`);return F}return 0},c=(w,F)=>{if(F){const $=w[0];w=w.filter((q)=>q%F===$%F||q===$)}return w};export{H as units,V as toStep,D as toRange,C as toPart,G as toNumber,c as toInterval,O as timeSince,y as startOfSecond,W as startOfMonth,k as startOfMinute,I as startOfHour,E as startOfDay,U as range,p as nextSchedule,S as flatten,f as addSeconds,_ as addMonths,Q as addMinutes,T as addMilliseconds,R as addHours,P as addDays}; | ||
| var f = (j) => { | ||
| const q = j instanceof Date ? j : new Date(j), | ||
| w = new Intl.RelativeTimeFormat("en"), | ||
| A = { | ||
| years: 31536000, | ||
| months: 2592000, | ||
| weeks: 604800, | ||
| days: 86400, | ||
| hours: 3600, | ||
| minutes: 60, | ||
| seconds: 1, | ||
| }, | ||
| B = (q.getTime() - Date.now()) / 1000; | ||
| for (let F in A) | ||
| if (A[F] < Math.abs(B)) { | ||
| const G = B / A[F]; | ||
| return w.format(Math.round(G), F); | ||
| } | ||
| }, | ||
| _ = (j, q) => { | ||
| const w = new Date(j), | ||
| A = w.getDate(), | ||
| B = new Date(w.getTime()); | ||
| B.setMonth(w.getMonth() + q + 1, 0); | ||
| const F = B.getDate(); | ||
| if (A >= F) return B; | ||
| else w.setFullYear(B.getFullYear(), B.getMonth(), A); | ||
| return w; | ||
| }, | ||
| $ = (j, q) => { | ||
| const w = new Date(j); | ||
| return w.setDate(w.getDate() + q), w; | ||
| }, | ||
| R = (j, q) => { | ||
| return T(j, q * 3600000); | ||
| }, | ||
| Q = (j, q) => { | ||
| return T(j, q * 60000); | ||
| }, | ||
| O = (j, q) => { | ||
| return T(j, q * 1000); | ||
| }, | ||
| T = (j, q) => { | ||
| return new Date(j.getTime() + q); | ||
| }, | ||
| W = (j) => { | ||
| const q = new Date(j); | ||
| return q.setDate(1), q.setHours(0, 0, 0, 0), q; | ||
| }, | ||
| E = (j) => { | ||
| const q = new Date(j); | ||
| return q.setHours(0, 0, 0, 0), q; | ||
| }, | ||
| I = (j) => { | ||
| const q = new Date(j); | ||
| return q.setMinutes(0, 0, 0), q; | ||
| }, | ||
| S = (j) => { | ||
| const q = new Date(j); | ||
| return q.setSeconds(0, 0), q; | ||
| }, | ||
| y = (j) => { | ||
| const q = new Date(j); | ||
| return q.setMilliseconds(0), q; | ||
| }; | ||
| var H = [ | ||
| { name: "minute", min: 0, max: 59 }, | ||
| { name: "hour", min: 0, max: 23 }, | ||
| { name: "day", min: 1, max: 31 }, | ||
| { name: "month", min: 0, max: 11 }, | ||
| { name: "weekday", min: 0, max: 6 }, | ||
| ]; | ||
| var J = (j) => { | ||
| if (typeof j === "string") { | ||
| const q = j.trim(); | ||
| if (/^\d+$/.test(q)) { | ||
| const w = Number(q); | ||
| if (!isNaN(w) && isFinite(w)) return w; | ||
| } | ||
| } else if (typeof j === "number") { | ||
| if (!isNaN(j) && isFinite(j) && j === Math.floor(j)) return j; | ||
| } | ||
| return; | ||
| }, | ||
| U = (j, q) => { | ||
| const w = new Array(); | ||
| for (let A = j; A <= q; A++) w.push(A); | ||
| return w; | ||
| }, | ||
| N = (j) => { | ||
| return j.reduce((q, w) => q.concat(w), []); | ||
| }; | ||
| var v = (j, q) => { | ||
| const w = q.split(" "); | ||
| if (w.length === 5) { | ||
| const [A, B, F, G, K] = w.map((L, P) => C(L, H[P])); | ||
| let z = Q(new Date(j), 1); | ||
| z.setSeconds(0), z.setMilliseconds(0); | ||
| let k = 24, | ||
| X = !1, | ||
| Y = !1, | ||
| Z = !1; | ||
| while (--k) { | ||
| while (G.indexOf(z.getMonth()) === -1) z = W(_(z, 1)); | ||
| const L = z.getMonth(); | ||
| while (F.indexOf(z.getDate()) === -1 || K.indexOf(z.getDay()) === -1) | ||
| if (((z = E($(z, 1))), L !== z.getMonth())) { | ||
| X = !0; | ||
| break; | ||
| } | ||
| if (!X) { | ||
| const P = z.getDate(); | ||
| while (B.indexOf(z.getHours()) === -1) | ||
| if (((z = I(R(z, 1))), P !== z.getDate())) { | ||
| Y = !0; | ||
| break; | ||
| } | ||
| if (!Y) { | ||
| const b = z.getHours(); | ||
| while (A.indexOf(z.getMinutes()) === -1) | ||
| if (((z = S(Q(z, 1))), b !== z.getHours())) { | ||
| Z = !0; | ||
| break; | ||
| } | ||
| if (!Z) break; | ||
| } | ||
| } | ||
| } | ||
| return z.setSeconds(0), z.setMilliseconds(0), z; | ||
| } | ||
| }, | ||
| C = (j, q) => { | ||
| const w = j.split(",").map((A) => { | ||
| const B = A.split("/"); | ||
| if (B.length > 2) throw new Error(`Invalid value "${j}"`); | ||
| let F; | ||
| const G = B[0], | ||
| K = B[1]; | ||
| if (G === "*") F = U(q.min, q.max); | ||
| else F = D(G); | ||
| const z = V(K); | ||
| return c(F, z); | ||
| }); | ||
| return [...new Set(N(w))].sort((A, B) => A - B); | ||
| }, | ||
| D = (j) => { | ||
| const q = j.split("-"); | ||
| if (q.length === 1) { | ||
| const w = J(q[0]); | ||
| if (w === void 0) throw new Error("Invalid value"); | ||
| return [w]; | ||
| } else if (q.length === 2) { | ||
| const w = J(q[0]), | ||
| A = J(q[1]); | ||
| if (w === void 0 || A === void 0) throw new Error("Invalid value"); | ||
| if (A < w) throw new Error(`Max range is less than min range in "${j}"`); | ||
| return U(w, A); | ||
| } else throw new Error(`Invalid value "${j}"`); | ||
| }, | ||
| V = (j) => { | ||
| if (j) { | ||
| const q = J(j); | ||
| if (q === void 0) throw new Error(`Invalid interval step value "${j}"`); | ||
| return q; | ||
| } | ||
| return 0; | ||
| }, | ||
| c = (j, q) => { | ||
| if (q) { | ||
| const w = j[0]; | ||
| j = j.filter((A) => A % q === w % q || A === w); | ||
| } | ||
| return j; | ||
| }; | ||
| export { | ||
| H as units, | ||
| V as toStep, | ||
| D as toRange, | ||
| C as toPart, | ||
| J as toNumber, | ||
| c as toInterval, | ||
| f as timeSince, | ||
| y as startOfSecond, | ||
| W as startOfMonth, | ||
| S as startOfMinute, | ||
| I as startOfHour, | ||
| E as startOfDay, | ||
| U as range, | ||
| v as nextSchedule, | ||
| N as flatten, | ||
| O as addSeconds, | ||
| _ as addMonths, | ||
| Q as addMinutes, | ||
| T as addMilliseconds, | ||
| R as addHours, | ||
| $ as addDays, | ||
| }; |
+22
-22
| { | ||
| "name": "@coverbase/time", | ||
| "version": "0.0.1", | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js" | ||
| } | ||
| }, | ||
| "module": "./dist/index.ts", | ||
| "types": "./dist/index.d.ts", | ||
| "files": ["dist"], | ||
| "scripts": { | ||
| "build": "bun build ./src/index.ts --outdir ./dist --minify && tsc --emitDeclarationOnly" | ||
| }, | ||
| "devDependencies": { | ||
| "@biomejs/biome": "^1.5.3", | ||
| "@types/bun": "^1.0.4" | ||
| }, | ||
| "peerDependencies": { | ||
| "typescript": "^5.0.0" | ||
| } | ||
| "name": "@coverbase/time", | ||
| "version": "0.0.2", | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js" | ||
| } | ||
| }, | ||
| "module": "./dist/index.ts", | ||
| "types": "./dist/index.d.ts", | ||
| "files": ["dist"], | ||
| "scripts": { | ||
| "build": "bun build ./src/index.ts --outdir ./dist --minify && tsc --emitDeclarationOnly" | ||
| }, | ||
| "devDependencies": { | ||
| "@biomejs/biome": "^1.5.3", | ||
| "@types/bun": "^1.0.4" | ||
| }, | ||
| "peerDependencies": { | ||
| "typescript": "^5.0.0" | ||
| } | ||
| } |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
8047
50.36%228
418.18%3
-25%