@neramjs/cron 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1 — 2026-12-06
4
+
5
+ - Add a `funding` link to GitHub Sponsors, shown on npm and by `npm fund`. No code changes.
6
+
3
7
  ## 0.3.0 — 2026-12-06
4
8
 
5
9
  - First release as its own package. cron and Cron moved here from `neramjs/recur`, with the same API and the same
@@ -1,2 +1,2 @@
1
- /*! @neramjs/cron v0.3.0 | MIT | github.com/varksh05/neramjs */
1
+ /*! @neramjs/cron v0.3.1 | MIT | github.com/varksh05/neramjs */
2
2
  (()=>{var X=Object.create;var v=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var K=(i,e,t)=>()=>{if(t)throw t[0];try{return i&&(e=i(i=0)),e}catch(n){throw t=[n],n}};var j=(i,e)=>()=>{try{return e||i((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},F=(i,e)=>{for(var t in e)v(i,t,{get:e[t],enumerable:!0})},A=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Z(e))!B.call(i,r)&&r!==t&&v(i,r,{get:()=>e[r],enumerable:!(n=G(e,r))||n.enumerable});return i};var y=(i,e,t)=>(t=i!=null?X(q(i)):{},A(e||!i||!i.__esModule?v(t,"default",{value:i,enumerable:!0}):t,i)),Q=i=>A(v({},"__esModule",{value:!0}),i);var E=j((re,T)=>{var S=globalThis.neram;if(typeof S!="function")throw new Error("@neramjs/cron: load neram.global.js before cron.global.js");T.exports={neram:S,Neram:S.Neram,Duration:S.Duration,duration:S.duration,isDuration:S.isDuration}});var U={};F(U,{Schedule:()=>z});function D(i,e){if(e!==void 0&&(!Number.isInteger(e)||e<0))throw new RangeError(`neram: ${i} must be a whole number of zero or more, got ${String(e)}`)}var W,O,ee,z,Y=K(()=>{"use strict";W=y(E(),1),O=y(E(),1),ee=400*366*864e5,z=class{originalOf(e){}durationOf(e){}coerce(e){let t=(0,O.neram)(e,{zone:this.tz}).valueOf();if(Number.isNaN(t))throw new RangeError(`neram: invalid date ${JSON.stringify(e)}`);return t}out(e,t){let n=(0,O.neram)(e,{zone:this.tz});if(typeof t=="function")return t(n);let r=()=>n.format(this.allDay?"YYYY-MM-DD":"YYYY-MM-DDTHH:mm:ss"),s;switch(t??"neram"){case"neram":s=n;break;case"date":s=n.toDate();break;case"epoch":s=e;break;case"unix":s=Math.floor(e/1e3);break;case"iso":s=n.toISOString();break;case"zoned":s=n.toZonedISOString();break;case"local":s=r();break;case"record":{let c={utc:n.toISOString(),local:r(),tz:n.timezone(),epoch:e,allDay:this.allDay},u=this.originalOf(e);u!==void 0&&(c.original=new Date(u).toISOString()),s=c;break}default:throw new RangeError(`neram: unknown output format "${String(t)}"`)}return s}all(e={}){if(D("limit",e.limit),e.limit===void 0&&this.isInfinite())throw new RangeError("neram: this schedule never ends; pass { limit } or use between()");let t=[];for(let n of this.iterate(this.startMs())){if(e.limit!==void 0&&t.length>=e.limit)break;t.push(this.out(n,e.as))}return t}between(e,t,n={}){D("limit",n.limit);let r=n.inclusive??!0,s=this.coerce(e),c=this.coerce(t),u=[];for(let o of this.iterate(s)){if(o>c||!r&&o===c)break;if(!(!r&&o===s)){if(n.limit!==void 0&&u.length>=n.limit)break;u.push(this.out(o,n.as))}}return u}after(e,t={}){let n=e===void 0?Date.now():this.coerce(e);for(let r of this.iterate(n))if(!(r===n&&!t.inclusive))return this.out(r,t.as);return null}before(e,t={}){let n=e===void 0?Date.now():this.coerce(e),r=Math.max(this.startMs(),n-ee),s=7*864e5;for(;;){let c=Math.max(r,n-s),u;for(let o of this.iterate(c)){if(o>n||o===n&&!t.inclusive)break;u=o}if(u!==void 0)return this.out(u,t.as);if(c<=r)return null;s*=8}}take(e,t={}){D("take(n)",e);let n=t.from===void 0?Date.now():this.coerce(t.from),r=[];if(e===0)return r;for(let s of this.iterate(n))if(s!==n&&(r.push(this.out(s,t.as)),r.length>=e))break;return r}includes(e){let t=this.coerce(e);for(let n of this.iterate(t))return n===t;return!1}instances(e,t,n){let r=(0,W.duration)(n.duration);if(!r.isValid()||r.valueOf()<0)throw new RangeError("neram: instances() needs a duration of zero or more");let s=this.coerce(e),c=this.coerce(t),u=Math.abs(r.asMilliseconds())+2*864e5,o=[];for(let a of this.iterate(s-u)){if(a>=c)break;let d=(0,O.neram)(a,{zone:this.tz}).add(this.durationOf(a)??r);d.valueOf()<=s&&a<s||o.push({start:this.out(a,n.as),end:this.out(d.valueOf(),n.as)})}return o}*[Symbol.iterator](){for(let e of this.iterate(this.startMs()))yield(0,O.neram)(e,{zone:this.tz})}}});var M=j((oe,J)=>{var L=globalThis.neram;if(typeof L!="function")throw new Error("@neramjs/cron: load neram.global.js before cron.global.js");J.exports={...L[Symbol.for("neramjs.internal")],Schedule:(Y(),Q(U)).Schedule}});var I={};F(I,{Cron:()=>k,Schedule:()=>V.Schedule,cron:()=>_});var $=y(M(),1);var R=y(E(),1),f=y(M(),1),te={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"},H=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"],P=["SUN","MON","TUE","WED","THU","FRI","SAT"];function N(i,e,t,n,r){let s=new Set,c=i.startsWith("*")||i==="?",u=o=>{let a=o.toUpperCase(),h=r?r.indexOf(a):-1,d=h>=0?h+(r===H?1:0):Number(o);if(!/^\d+$/.test(o)&&h<0)throw new RangeError(`neram: invalid cron ${e} "${o}"`);return d};for(let o of i.split(",")){if(!o)throw new RangeError(`neram: empty item in cron ${e}`);let[a,h]=o.split("/"),d=h===void 0?1:Number(h);if(!Number.isInteger(d)||d<1)throw new RangeError(`neram: invalid cron step "${o}"`);let m,g;if(a==="*"||a==="?")m=t,g=n;else if(a.includes("-")){let[l,w]=a.split("-");m=u(l),g=u(w)}else m=u(a),g=h===void 0?m:n;let b=l=>{if(l<t||l>n)throw new RangeError(`neram: cron ${e} value ${l} is out of range ${t}-${n}`)};if(b(m),b(g),m<=g)for(let l=m;l<=g;l+=d)s.add(l);else{let l=n-t+1,w=(g-m+l)%l;for(let p=0;p<=w;p+=d)s.add(t+(m-t+p)%l)}}return{values:s,any:c}}var k=class extends f.Schedule{tz;allDay=!1;expression;hasSeconds;#i;#a;#l;#n;#u;#t;#e={last:[],nearestWeekday:[],lastWeekday:!1};#r={nth:[],last:[]};#s;#o;constructor(e,t={}){super(),this.expression=e.trim(),this.tz=(0,f.normalizeZone)(t.tz??(0,R.neram)().timezone());let r=(te[this.expression.toLowerCase()]??this.expression).split(/\s+/);if(r.length!==5&&r.length!==6)throw new RangeError(`neram: cron needs 5 or 6 fields, got ${r.length} in "${e}"`);this.hasSeconds=r.length===6;let[s,c,u,o,a,h]=this.hasSeconds?r:["0",...r];this.#i=N(s,"second",0,59),this.#a=N(c,"minute",0,59),this.#l=N(u,"hour",0,23),this.#u=N(a,"month",1,12,H);let d=[];for(let g of o.split(",")){let b=g.toUpperCase(),l;if(b==="L")this.#e.last.push(0);else if(l=/^L-(\d+)$/.exec(b)){if(Number(l[1])>30)throw new RangeError(`neram: invalid cron day of month "${g}" (L-n needs n from 0 to 30)`);this.#e.last.push(Number(l[1]))}else if(b==="LW")this.#e.lastWeekday=!0;else if(l=/^(\d+)W$/.exec(b)){let w=Number(l[1]);if(w<1||w>31)throw new RangeError(`neram: invalid cron day of month "${g}" (nW needs n from 1 to 31)`);this.#e.nearestWeekday.push(w)}else d.push(g)}this.#n=d.length?N(d.join(","),"day of month",1,31):{values:new Set,any:!1},d.length!==o.split(",").length&&(this.#n.any=!1);let m=[];for(let g of h.split(",")){let b=g.toUpperCase(),l=p=>{let C=P.indexOf(p),x=C>=0?C:Number(p);if(!Number.isInteger(x)||x<0||x>7)throw new RangeError(`neram: invalid cron weekday "${p}"`);return x%7},w;(w=/^(\w+)#([1-5])$/.exec(b))?this.#r.nth.push([l(w[1]),Number(w[2])]):(w=/^(\w+)L$/.exec(b))?this.#r.last.push(l(w[1])):m.push(g)}this.#t=m.length?N(m.join(","),"day of week",0,7,P):{values:new Set,any:!1},m.length!==h.split(",").length&&(this.#t.any=!1),this.#t.values.delete(7)&&this.#t.values.add(0),this.#s=t.start===void 0?void 0:this.coerce(t.start),this.#o=t.end===void 0?void 0:this.coerce(t.end)}isInfinite(){return this.#o===void 0}startMs(){return this.#s??Date.now()}#c(e,t,n){let r=(Math.floor((0,f.utcFromParts)(e,t,n)/864e5)%7+11)%7,s=(0,f.daysInMonth)(e,t),c=()=>{if(this.#n.values.has(n)||this.#e.last.some(a=>n===s-a))return!0;let o=a=>{let h=Math.min(a,s),d=new Date((0,f.utcFromParts)(e,t,h)).getUTCDay();return d===6?h=h===1?3:h-1:d===0&&(h=h===s?h-2:h+1),h};if(this.#e.nearestWeekday.some(a=>n===o(a)))return!0;if(this.#e.lastWeekday){let a=s;for(;[0,6].includes(new Date((0,f.utcFromParts)(e,t,a)).getUTCDay());)a--;if(n===a)return!0}return!1},u=()=>this.#t.values.has(r)||this.#r.nth.some(([o,a])=>o===r&&Math.floor((n-1)/7)+1===a)||this.#r.last.some(o=>o===r&&n+7>s);return this.#n.any||this.#t.any?c()&&u():c()||u()}#h(e){let t=new Date(e).getUTCFullYear()+400;for(;;){let{y:n,M:r,D:s,h:c,m:u,s:o}=(0,f.wallOfMs)(e);if(n>t||n>9999)return null;if(!this.#u.values.has(r+1)){e=(0,f.utcFromParts)(n,r+1,1);continue}if(!this.#c(n,r,s)){e=(0,f.utcFromParts)(n,r,s+1);continue}if(!this.#l.values.has(c)){e=(0,f.utcFromParts)(n,r,s,c+1);continue}if(!this.#a.values.has(u)){e=(0,f.utcFromParts)(n,r,s,c,u+1);continue}if(!this.#i.values.has(o)){e=(0,f.utcFromParts)(n,r,s,c,u,o+1);continue}return e}}*iterate(e){let t=e;this.#s!==void 0&&(t=Math.max(t,this.#s)),Number.isFinite(t)||(t=Date.now());let n=this.hasSeconds?1e3:6e4,r=(0,R.neram)(t,{zone:this.tz}),[s,c,u,o,a,h,d]=r.toArray(),m=(0,f.utcFromParts)(s,c,u,o,a,this.hasSeconds?h:0);(d>0||!this.hasSeconds&&(h>0||d>0))&&(m+=n);let g=-1/0;for(;;){let b=this.#h(m);if(b===null)return;let l=(0,f.wallToEpoch)((0,f.wallOfMs)(b),this.tz);if(m=b+n,!(l<t||l<=g)){if(this.#o!==void 0&&l>this.#o)return;g=l,yield l}}}toString(){return this.expression}toJSON(){return{expression:this.expression,tz:this.tz}}};function _(i,e={}){return new k(i,e)}var V=y(M(),1);if($.INTERNAL_VERSION!==1)throw new Error(`@neramjs/cron needs a neramjs version with internals v1, but the installed neramjs has v${$.INTERNAL_VERSION}. Install matching versions of neramjs and @neramjs/cron.`);globalThis.neram.recur=Object.assign(globalThis.neram.recur||{},I);})();
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @neramjs/cron v0.3.0 | MIT | github.com/varksh05/neramjs */
1
+ /*! @neramjs/cron v0.3.1 | MIT | github.com/varksh05/neramjs */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neramjs/cron",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Cron schedules in any time zone, built on neramjs: the next runs, runs between two dates, and the right times across daylight saving.",
5
5
  "keywords": [
6
6
  "cron",
@@ -22,6 +22,10 @@
22
22
  "bugs": {
23
23
  "url": "https://github.com/varksh05/neramjs/issues"
24
24
  },
25
+ "funding": {
26
+ "type": "github",
27
+ "url": "https://github.com/sponsors/varksh05"
28
+ },
25
29
  "type": "module",
26
30
  "main": "./dist/index.cjs",
27
31
  "module": "./dist/index.js",