croner 9.0.0-dev.6 → 9.0.0-dev.8

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.
@@ -0,0 +1 @@
1
+ var D=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var U=(n,t)=>{for(var e in t)D(n,e,{get:t[e],enumerable:!0})},k=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!M.call(n,s)&&s!==e&&D(n,s,{get:()=>t[s],enumerable:!(r=E(t,s))||r.enumerable});return n};var A=n=>k(D({},"__esModule",{value:!0}),n);var I={};U(I,{Cron:()=>N,CronDate:()=>l,CronPattern:()=>p,scheduledJobs:()=>C});module.exports=A(I);function f(n,t,e,r,s,i,a,u){return f.fromTZ(f.tp(n,t,e,r,s,i,a),u)}f.fromTZISO=(n,t,e)=>f.fromTZ(z(n,t),e);f.fromTZ=function(n,t){let e=new Date(Date.UTC(n.y,n.m-1,n.d,n.h,n.i,n.s)),r=v(n.tz,e),s=new Date(e.getTime()-r),i=v(n.tz,s);if(i-r===0)return s;{let a=new Date(e.getTime()-i),u=v(n.tz,a);if(u-i===0)return a;if(!t&&u-i>0)return a;if(t)throw new Error("Invalid date passed to fromTZ()");return s}};f.toTZ=function(n,t){let e=n.toLocaleString("en-US",{timeZone:t}).replace(/[\u202f]/," "),r=new Date(e);return{y:r.getFullYear(),m:r.getMonth()+1,d:r.getDate(),h:r.getHours(),i:r.getMinutes(),s:r.getSeconds(),tz:t}};f.tp=(n,t,e,r,s,i,a)=>({y:n,m:t,d:e,h:r,i:s,s:i,tz:a});function v(n,t=new Date){let e=t.toLocaleString("en-US",{timeZone:n,timeZoneName:"shortOffset"}).split(" ").slice(-1)[0],r=t.toLocaleString("en-US").replace(/[\u202f]/," ");return Date.parse(`${r} GMT`)-Date.parse(`${r} ${e}`)}function z(n,t){let e=new Date(Date.parse(n));if(isNaN(e))throw new Error("minitz: Invalid ISO8601 passed to parser.");let r=n.substring(9);return n.includes("Z")||r.includes("-")||r.includes("+")?f.tp(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),"Etc/UTC"):f.tp(e.getFullYear(),e.getMonth()+1,e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),t)}f.minitz=f;var b=32,g=31|b,O=[1,2,4,8,16],p=class{constructor(t,e){this.pattern=t,this.timezone=e,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.lastDayOfMonth=!1,this.starDOM=!1,this.starDOW=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let t=this.pattern.replace(/\s+/g," ").split(" ");if(t.length<5||t.length>6)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five or six space separated parts are required.");if(t.length===5&&t.unshift("0"),t[3].indexOf("L")>=0&&(t[3]=t[3].replace("L",""),this.lastDayOfMonth=!0),t[3]=="*"&&(this.starDOM=!0),t[4].length>=3&&(t[4]=this.replaceAlphaMonths(t[4])),t[5].length>=3&&(t[5]=this.replaceAlphaDays(t[5])),t[5]=="*"&&(this.starDOW=!0),this.pattern.indexOf("?")>=0){let e=new l(new Date,this.timezone).getDate(!0);t[0]=t[0].replace("?",e.getSeconds().toString()),t[1]=t[1].replace("?",e.getMinutes().toString()),t[2]=t[2].replace("?",e.getHours().toString()),this.starDOM||(t[3]=t[3].replace("?",e.getDate().toString())),t[4]=t[4].replace("?",(e.getMonth()+1).toString()),this.starDOW||(t[5]=t[5].replace("?",e.getDay().toString()))}this.throwAtIllegalCharacters(t),this.partToArray("second",t[0],0,1),this.partToArray("minute",t[1],0,1),this.partToArray("hour",t[2],0,1),this.partToArray("day",t[3],-1,1),this.partToArray("month",t[4],-1,1),this.partToArray("dayOfWeek",t[5],0,g),this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(t,e,r,s){let i=this[t],a=t==="day"&&this.lastDayOfMonth;if(e===""&&!a)throw new TypeError("CronPattern: configuration entry "+t+" ("+e+") is empty, check for trailing spaces.");if(e==="*")return i.fill(s);let u=e.split(",");if(u.length>1)for(let o=0;o<u.length;o++)this.partToArray(t,u[o],r,s);else e.indexOf("-")!==-1&&e.indexOf("/")!==-1?this.handleRangeWithStepping(e,t,r,s):e.indexOf("-")!==-1?this.handleRange(e,t,r,s):e.indexOf("/")!==-1?this.handleStepping(e,t,r,s):e!==""&&this.handleNumber(e,t,r,s)}throwAtIllegalCharacters(t){for(let e=0;e<t.length;e++)if((e===5?/[^/*0-9,\-#L]+/:/[^/*0-9,-]+/).test(t[e]))throw new TypeError("CronPattern: configuration entry "+e+" ("+t[e]+") contains illegal characters.")}handleNumber(t,e,r,s){let i=this.extractNth(t,e),a=parseInt(i[0],10)+r;if(isNaN(a))throw new TypeError("CronPattern: "+e+" is not a number: '"+t+"'");this.setPart(e,a,i[1]||s)}setPart(t,e,r){if(!Object.prototype.hasOwnProperty.call(this,t))throw new TypeError("CronPattern: Invalid part specified: "+t);if(t==="dayOfWeek"){if(e===7&&(e=0),e<0||e>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+e);this.setNthWeekdayOfMonth(e,r);return}if(t==="second"||t==="minute"){if(e<0||e>=60)throw new RangeError("CronPattern: Invalid value for "+t+": "+e)}else if(t==="hour"){if(e<0||e>=24)throw new RangeError("CronPattern: Invalid value for "+t+": "+e)}else if(t==="day"){if(e<0||e>=31)throw new RangeError("CronPattern: Invalid value for "+t+": "+e)}else if(t==="month"&&(e<0||e>=12))throw new RangeError("CronPattern: Invalid value for "+t+": "+e);this[t][e]=r}handleRangeWithStepping(t,e,r,s){let i=this.extractNth(t,e),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+t+"'");let[,u,o,h]=a,c=parseInt(u,10)+r,w=parseInt(o,10)+r,y=parseInt(h,10);if(isNaN(c))throw new TypeError("CronPattern: Syntax error, illegal lower range (NaN)");if(isNaN(w))throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");if(isNaN(y))throw new TypeError("CronPattern: Syntax error, illegal stepping: (NaN)");if(y===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(y>this[e].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[e].length+")");if(c>w)throw new TypeError("CronPattern: From value is larger than to value: '"+t+"'");for(let T=c;T<=w;T+=y)this.setPart(e,T,i[1]||s)}extractNth(t,e){let r=t,s;if(r.includes("#")){if(e!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");s=r.split("#")[1],r=r.split("#")[0]}return[r,s]}handleRange(t,e,r,s){let i=this.extractNth(t,e),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+t+"'");let u=parseInt(a[0],10)+r,o=parseInt(a[1],10)+r;if(isNaN(u))throw new TypeError("CronPattern: Syntax error, illegal lower range (NaN)");if(isNaN(o))throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");if(u>o)throw new TypeError("CronPattern: From value is larger than to value: '"+t+"'");for(let h=u;h<=o;h++)this.setPart(e,h,i[1]||s)}handleStepping(t,e,r,s){let i=this.extractNth(t,e),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+t+"'");a[0]===""&&(a[0]="*");let u=0;a[0]!=="*"&&(u=parseInt(a[0],10)+r);let o=parseInt(a[1],10);if(isNaN(o))throw new TypeError("CronPattern: Syntax error, illegal stepping: (NaN)");if(o===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(o>this[e].length)throw new TypeError("CronPattern: Syntax error, max steps for part is ("+this[e].length+")");for(let h=u;h<this[e].length;h+=o)this.setPart(e,h,i[1]||s)}replaceAlphaDays(t){return t.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaMonths(t){return t.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(t){let e=t.trim().toLowerCase();return e==="@yearly"||e==="@annually"?"0 0 1 1 *":e==="@monthly"?"0 0 1 * *":e==="@weekly"?"0 0 * * 0":e==="@daily"?"0 0 * * *":e==="@hourly"?"0 * * * *":t}setNthWeekdayOfMonth(t,e){if(typeof e!="number"&&e==="L")this.dayOfWeek[t]=this.dayOfWeek[t]|b;else if(e===g)this.dayOfWeek[t]=g;else if(e<6&&e>0)this.dayOfWeek[t]=this.dayOfWeek[t]|O[e-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${e}, Type: ${typeof e}`)}};var S=[31,28,31,30,31,30,31,31,30,31,30,31],m=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],l=class n{constructor(t,e){if(this.tz=e,t&&t instanceof Date)if(!isNaN(t))this.fromDate(t);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(t===void 0)this.fromDate(new Date);else if(t&&typeof t=="string")this.fromString(t);else if(t instanceof n)this.fromCronDate(t);else throw new TypeError("CronDate: Invalid type ("+typeof t+") passed to CronDate constructor")}isNthWeekdayOfMonth(t,e,r,s){let a=new Date(Date.UTC(t,e,r)).getUTCDay(),u=0;for(let o=1;o<=r;o++)new Date(Date.UTC(t,e,o)).getUTCDay()===a&&u++;if(s&g&&O[u-1]&s)return!0;if(s&b){let o=new Date(Date.UTC(t,e+1,0)).getUTCDate();for(let h=r+1;h<=o;h++)if(new Date(Date.UTC(t,e,h)).getUTCDay()===a)return!1;return!0}return!1}fromDate(t){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes()+this.tz,this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply();else{let e=f.toTZ(t,this.tz);this.ms=t.getMilliseconds(),this.second=e.s,this.minute=e.i,this.hour=e.h,this.day=e.d,this.month=e.m-1,this.year=e.y}else this.ms=t.getMilliseconds(),this.second=t.getSeconds(),this.minute=t.getMinutes(),this.hour=t.getHours(),this.day=t.getDate(),this.month=t.getMonth(),this.year=t.getFullYear()}fromCronDate(t){this.tz=t.tz,this.year=t.year,this.month=t.month,this.day=t.day,this.hour=t.hour,this.minute=t.minute,this.second=t.second,this.ms=t.ms}apply(){if(this.month>11||this.day>S[this.month]||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let t=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),!0}else return!1}fromString(t){if(typeof this.tz=="number"){let e=f.fromTZISO(t);this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply()}else return this.fromDate(f.fromTZISO(t,this.tz))}findNext(t,e,r,s){let i=this[e],a;r.lastDayOfMonth&&(this.month!==1?a=S[this.month]:a=new Date(Date.UTC(this.year,this.month+1,0,0,0,0,0)).getUTCDate());let u=!r.starDOW&&e=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0;for(let o=this[e]+s;o<r[e].length;o++){let h=r[e][o];if(e==="day"&&r.lastDayOfMonth&&o-s==a&&(h=1),e==="day"&&!r.starDOW){let c=r.dayOfWeek[(u+(o-s-1))%7];if(c&&c&g)c=this.isNthWeekdayOfMonth(this.year,this.month,o-s,c)?1:0;else if(c)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);t.legacyMode&&!r.starDOM?h=h||c:h=h&&c}if(h)return this[e]=o-s,i!==this[e]?2:1}return 3}recurse(t,e,r){let s=this.findNext(e,m[r][0],t,m[r][2]);if(s>1){let i=r+1;for(;i<m.length;)this[m[i][0]]=-m[i][2],i++;if(s===3)return this[m[r][1]]++,this[m[r][0]]=-m[r][2],this.apply(),this.recurse(t,e,0);if(this.apply())return this.recurse(t,e,r-1)}return r+=1,r>=m.length?this:this.year>=3e3?null:this.recurse(t,e,r)}increment(t,e,r){return this.second+=e.interval!==void 0&&e.interval>1&&r?e.interval:1,this.ms=0,this.apply(),this.recurse(t,e,0)}getDate(t){return t||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):f.fromTZ(f.tp(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}};function _(n){if(n===void 0&&(n={}),delete n.name,n.legacyMode=n.legacyMode===void 0?!0:n.legacyMode,n.paused=n.paused===void 0?!1:n.paused,n.maxRuns=n.maxRuns===void 0?1/0:n.maxRuns,n.catch=n.catch===void 0?!1:n.catch,n.interval=n.interval===void 0?0:parseInt(n.interval.toString(),10),n.utcOffset=n.utcOffset===void 0?void 0:parseInt(n.utcOffset.toString(),10),n.unref=n.unref===void 0?!1:n.unref,n.startAt&&(n.startAt=new l(n.startAt,n.timezone)),n.stopAt&&(n.stopAt=new l(n.stopAt,n.timezone)),n.interval!==null){if(isNaN(n.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(n.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(n.utcOffset!==void 0){if(isNaN(n.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(n.utcOffset<-870||n.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(n.utcOffset!==void 0&&n.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(n.unref!==!0&&n.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");return n}function d(n){return Object.prototype.toString.call(n)==="[object Function]"||typeof n=="function"||n instanceof Function}function P(n){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(n):n&&typeof n.unref<"u"&&n.unref()}var R=30*1e3,C=[],N=class{constructor(t,e,r){let s,i;if(d(e))i=e;else if(typeof e=="object")s=e;else if(e!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(d(r))i=r;else if(typeof r=="object")s=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=s?s.name:void 0,this.options=_(s),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:s?s.maxRuns:void 0,paused:s?s.paused:!1,pattern:new p("* * * * *")},t&&(t instanceof Date||typeof t=="string"&&t.indexOf(":")>0)?this._states.once=new l(t,this.options.timezone||this.options.utcOffset):this._states.pattern=new p(t,this.options.timezone),this.name){if(C.find(u=>u.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");C.push(this)}return i!==void 0&&d(i)&&(this.fn=i,this.schedule()),this}nextRun(t){let e=this._next(t);return e?e.getDate(!1):null}nextRuns(t,e){this._states.maxRuns!==void 0&&t>this._states.maxRuns&&(t=this._states.maxRuns);let r=[],s=e||this._states.currentRun||void 0;for(;t--&&(s=this.nextRun(s));)r.push(s);return r}getPattern(){return this._states.pattern?this._states.pattern.pattern:void 0}isRunning(){let t=this.nextRun(this._states.currentRun),e=!this._states.paused,r=this.fn!==void 0,s=!this._states.kill;return e&&r&&s&&t!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(t){t=t||new Date;let e=this._next(t);return e?t instanceof l||t instanceof Date?e.getTime()-t.getTime():e.getTime()-new l(t).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let t=C.indexOf(this);t>=0&&C.splice(t,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(t){if(t&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");t&&(this.fn=t);let e=this.msToNext(),r=this.nextRun(this._states.currentRun);return e==null||isNaN(e)||r===null?this:(e>R&&(e=R),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),e),this._states.currentTimeout&&this.options.unref&&P(this._states.currentTimeout),this)}async _trigger(t){if(this._states.blocking=!0,this._states.currentRun=new l(void 0,this.options.timezone||this.options.utcOffset),this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(e){d(this.options.catch)&&this.options.catch(e,this)}else this.fn!==void 0&&await this.fn(this,this.options.context);this._states.previousRun=new l(t,this.options.timezone||this.options.utcOffset),this._states.blocking=!1}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(t){let e=new Date,r=!this._states.paused&&e.getTime()>=t.getTime(),s=this._states.blocking&&this.options.protect;r&&!s?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&s&&d(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(t){let e=!!(t||this._states.currentRun),r=!1;!t&&this.options.startAt&&this.options.interval&&([t,e]=this._calculatePreviousRun(t,e),r=!t),t=new l(t,this.options.timezone||this.options.utcOffset),this.options.startAt&&t&&t.getTime()<this.options.startAt.getTime()&&(t=this.options.startAt);let s=this._states.once||new l(t,this.options.timezone||this.options.utcOffset);return!r&&s!==this._states.once&&(s=s.increment(this._states.pattern,this.options,e)),this._states.once&&this._states.once.getTime()<=t.getTime()||s===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&s.getTime()>=this.options.stopAt.getTime()?null:s}_calculatePreviousRun(t,e){let r=new l(void 0,this.options.timezone||this.options.utcOffset),s=t;if(this.options.startAt.getTime()<=r.getTime()){s=this.options.startAt;let i=s.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)s=new l(s,this.options.timezone||this.options.utcOffset).increment(this._states.pattern,this.options,!0),i=s.getTime()+this.options.interval*1e3;e=!0}return s===null&&(s=void 0),[s,e]}};0&&(module.exports={Cron,CronDate,CronPattern,scheduledJobs});
@@ -0,0 +1,365 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export type CatchCallbackFn = (e: unknown, job: Cron) => void;
4
+ export type ProtectCallbackFn = (job: Cron) => void;
5
+ export interface CronOptions {
6
+ name?: string;
7
+ paused?: boolean;
8
+ kill?: boolean;
9
+ catch?: boolean | CatchCallbackFn;
10
+ unref?: boolean;
11
+ maxRuns?: number;
12
+ interval?: number;
13
+ protect?: boolean | ProtectCallbackFn;
14
+ startAt?: string | Date | CronDate;
15
+ stopAt?: string | Date | CronDate;
16
+ timezone?: string;
17
+ utcOffset?: number;
18
+ legacyMode?: boolean;
19
+ context?: unknown;
20
+ }
21
+ /**
22
+ * Create a CronPattern instance from pattern string ('* * * * * *')
23
+ * @constructor
24
+ * @param {string} pattern - Input pattern
25
+ * @param {string} timezone - Input timezone, used for '?'-substitution
26
+ */
27
+ export declare class CronPattern {
28
+ pattern: string;
29
+ timezone?: string;
30
+ second: number[];
31
+ minute: number[];
32
+ hour: number[];
33
+ day: number[];
34
+ month: number[];
35
+ dayOfWeek: number[];
36
+ lastDayOfMonth: boolean;
37
+ starDOM: boolean;
38
+ starDOW: boolean;
39
+ constructor(pattern: string, timezone?: string);
40
+ /**
41
+ * Parse current pattern, will throw on any type of failure
42
+ * @private
43
+ */
44
+ private parse;
45
+ /**
46
+ * Convert current part (seconds/minutes etc) to an array of 1 or 0 depending on if the part is about to trigger a run or not.
47
+ */
48
+ private partToArray;
49
+ /**
50
+ * After converting JAN-DEC, SUN-SAT only 0-9 * , / - are allowed, throw if anything else pops up
51
+ * @throws On error
52
+ */
53
+ private throwAtIllegalCharacters;
54
+ /**
55
+ * Nothing but a number left, handle that
56
+ *
57
+ * @param conf Current part, expected to be a number, as a string
58
+ * @param type One of "seconds", "minutes" etc
59
+ * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
60
+ */
61
+ private handleNumber;
62
+ /**
63
+ * Set a specific value for a specific part of the CronPattern.
64
+ *
65
+ * @param part The specific part of the CronPattern, e.g., "second", "minute", etc.
66
+ * @param index The index to modify.
67
+ * @param value The value to set, typically 0 or 1, in case of "nth weekday" it will be the weekday number used for further processing
68
+ */
69
+ private setPart;
70
+ /**
71
+ * Take care of ranges with stepping (e.g. 3-23/5)
72
+ *
73
+ * @param conf Current part, expected to be a string like 3-23/5
74
+ * @param type One of "seconds", "minutes" etc
75
+ * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
76
+ */
77
+ private handleRangeWithStepping;
78
+ private extractNth;
79
+ /**
80
+ * Take care of ranges (e.g. 1-20)
81
+ *
82
+ * @param conf - Current part, expected to be a string like 1-20, can contain L for last
83
+ * @param type - One of "seconds", "minutes" etc
84
+ * @param valueIndexOffset - -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
85
+ */
86
+ private handleRange;
87
+ /**
88
+ * Handle stepping (e.g. * / 14)
89
+ *
90
+ * @param conf Current part, expected to be a string like * /20 (without the space)
91
+ * @param type One of "seconds", "minutes" etc
92
+ */
93
+ private handleStepping;
94
+ /**
95
+ * Replace day name with day numbers
96
+ *
97
+ * @param conf Current part, expected to be a string that might contain sun,mon etc.
98
+ *
99
+ * @returns Conf with 0 instead of sun etc.
100
+ */
101
+ private replaceAlphaDays;
102
+ /**
103
+ * Replace month name with month numbers
104
+ *
105
+ * @param conf Current part, expected to be a string that might contain jan,feb etc.
106
+ *
107
+ * @returns conf with 0 instead of sun etc.
108
+ */
109
+ private replaceAlphaMonths;
110
+ /**
111
+ * Replace nicknames with actual cron patterns
112
+ *
113
+ * @param pattern Pattern, may contain nicknames, or not
114
+ *
115
+ * @returns Pattern, with cron expression insted of nicknames
116
+ */
117
+ private handleNicknames;
118
+ /**
119
+ * Handle the nth weekday of the month logic using hash sign (e.g. FRI#2 for the second Friday of the month)
120
+ *
121
+ * @param index Weekday, example: 5 for friday
122
+ * @param nthWeekday bitmask, 2 (0x00010) for 2nd friday, 31 (ANY_OCCURRENCE, 0b100000) for any day
123
+ */
124
+ private setNthWeekdayOfMonth;
125
+ }
126
+ /**
127
+ * Converts date to CronDate
128
+ *
129
+ * @param d Input date, if using string representation ISO 8001 (2015-11-24T19:40:00) local timezone is expected
130
+ * @param tz String representation of target timezone in Europe/Stockholm format, or a number representing offset in minutes.
131
+ */
132
+ export declare class CronDate {
133
+ tz: string | number | undefined;
134
+ /**
135
+ * Current milliseconds
136
+ * @type {number}
137
+ */
138
+ ms: number;
139
+ /**
140
+ * Current second (0-59), in local time or target timezone specified by `this.tz`
141
+ * @type {number}
142
+ */
143
+ second: number;
144
+ /**
145
+ * Current minute (0-59), in local time or target timezone specified by `this.tz`
146
+ * @type {number}
147
+ */
148
+ minute: number;
149
+ /**
150
+ * Current hour (0-23), in local time or target timezone specified by `this.tz`
151
+ * @type {number}
152
+ */
153
+ hour: number;
154
+ /**
155
+ * Current day (1-31), in local time or target timezone specified by `this.tz`
156
+ * @type {number}
157
+ */
158
+ day: number;
159
+ /**
160
+ * Current month (1-12), in local time or target timezone specified by `this.tz`
161
+ * @type {number}
162
+ */
163
+ month: number;
164
+ /**
165
+ * Current full year, in local time or target timezone specified by `this.tz`
166
+ */
167
+ year: number;
168
+ constructor(d?: CronDate | Date | string | null, tz?: string | number);
169
+ /**
170
+ * Check if the given date is the nth occurrence of a weekday in its month.
171
+ *
172
+ * @param year The year.
173
+ * @param month The month (0 for January, 11 for December).
174
+ * @param day The day of the month.
175
+ * @param nth The nth occurrence (bitmask).
176
+ *
177
+ * @return True if the date is the nth occurrence of its weekday, false otherwise.
178
+ */
179
+ private isNthWeekdayOfMonth;
180
+ /**
181
+ * Sets internals using a Date
182
+ */
183
+ private fromDate;
184
+ /**
185
+ * Sets internals by deep copying another CronDate
186
+ *
187
+ * @param {CronDate} d - Input date
188
+ */
189
+ private fromCronDate;
190
+ /**
191
+ * Reset internal parameters (seconds, minutes, hours) if any of them have exceeded (or could have exceeded) their normal ranges
192
+ *
193
+ * Will alway return true on february 29th, as that is a date that _could_ be out of bounds
194
+ */
195
+ private apply;
196
+ /**
197
+ * Sets internals by parsing a string
198
+ */
199
+ private fromString;
200
+ /**
201
+ * Find next match of current part
202
+ */
203
+ private findNext;
204
+ /**
205
+ * Increment to next run time recursively
206
+ *
207
+ * This function is currently capped at year 3000. Do you have a reason to go further? Open an issue on GitHub!
208
+ *
209
+ * @param pattern The pattern used to increment current state
210
+ * @param options Cron options used for incrementing
211
+ * @param doing Which part to increment, 0 represent first item of RecursionSteps-array etc.
212
+ * @return Returns itthis for chaining, or null if increment wasnt possible
213
+ */
214
+ private recurse;
215
+ /**
216
+ * Increment to next run time
217
+ *
218
+ * @param pattern The pattern used to increment current state
219
+ * @param options Cron options used for incrementing
220
+ * @param hasPreviousRun If this run should adhere to minimum interval
221
+ * @return Returns itthis for chaining, or null if increment wasnt possible
222
+ */
223
+ increment(pattern: CronPattern, options: CronOptions, hasPreviousRun: boolean): CronDate | null;
224
+ /**
225
+ * Convert current state back to a javascript Date()
226
+ *
227
+ * @param internal If this is an internal call
228
+ */
229
+ getDate(internal?: boolean): Date;
230
+ /**
231
+ * Convert current state back to a javascript Date() and return UTC milliseconds
232
+ */
233
+ getTime(): number;
234
+ }
235
+ /**
236
+ * An array containing all named cron jobs.
237
+ */
238
+ export declare const scheduledJobs: Cron[];
239
+ /**
240
+ * Cron entrypoint
241
+ *
242
+ * @constructor
243
+ * @param pattern - Input pattern, input date, or input ISO 8601 time string
244
+ * @param [fnOrOptions1] - Options or function to be run each iteration of pattern
245
+ * @param [fnOrOptions2] - Options or function to be run each iteration of pattern
246
+ */
247
+ export declare class Cron {
248
+ name: string | undefined;
249
+ options: CronOptions;
250
+ private _states;
251
+ private fn?;
252
+ constructor(pattern: string | Date, fnOrOptions1?: CronOptions | Function, fnOrOptions2?: CronOptions | Function);
253
+ /**
254
+ * Find next runtime, based on supplied date. Strips milliseconds.
255
+ *
256
+ * @param prev - Date to start from
257
+ * @returns Next run time
258
+ */
259
+ nextRun(prev?: CronDate | Date | string | null): Date | null;
260
+ /**
261
+ * Find next n runs, based on supplied date. Strips milliseconds.
262
+ *
263
+ * @param n - Number of runs to enumerate
264
+ * @param previous - Date to start from
265
+ * @returns - Next n run times
266
+ */
267
+ nextRuns(n: number, previous?: Date | string): Date[];
268
+ /**
269
+ * Return the original pattern, if there was one
270
+ *
271
+ * @returns Original pattern
272
+ */
273
+ getPattern(): string | undefined;
274
+ /**
275
+ * Indicates whether or not the cron job is scheduled and running, e.g. awaiting next trigger
276
+ *
277
+ * @returns Running or not
278
+ */
279
+ isRunning(): boolean;
280
+ /**
281
+ * Indicates whether or not the cron job is permanently stopped
282
+ *
283
+ * @returns Running or not
284
+ */
285
+ isStopped(): boolean;
286
+ /**
287
+ * Indicates whether or not the cron job is currently working
288
+ *
289
+ * @returns Running or not
290
+ */
291
+ isBusy(): boolean;
292
+ /**
293
+ * Return current/previous run start time
294
+ *
295
+ * @returns Current (if running) or previous run time
296
+ */
297
+ currentRun(): Date | null;
298
+ /**
299
+ * Return previous run start time
300
+ *
301
+ * @returns Previous run time
302
+ */
303
+ previousRun(): Date | null;
304
+ /**
305
+ * Returns number of milliseconds to next run
306
+ *
307
+ * @param prev Starting date, defaults to now - minimum interval
308
+ */
309
+ msToNext(prev?: CronDate | Date | string): number | null;
310
+ /**
311
+ * Stop execution
312
+ *
313
+ * Running this will forcefully stop the job, and prevent furter exection. `.resume()` will not work after stopping.
314
+ * It will also be removed from the scheduledJobs array if it were named.
315
+ */
316
+ stop(): void;
317
+ /**
318
+ * Pause execution
319
+ *
320
+ * @returns Wether pause was successful
321
+ */
322
+ pause(): boolean;
323
+ /**
324
+ * Resume execution
325
+ *
326
+ * @returns Wether resume was successful
327
+ */
328
+ resume(): boolean;
329
+ /**
330
+ * Schedule a new job
331
+ *
332
+ * @param func - Function to be run each iteration of pattern
333
+ */
334
+ schedule(func?: Function): Cron;
335
+ /**
336
+ * Internal function to trigger a run, used by both scheduled and manual trigger
337
+ */
338
+ private _trigger;
339
+ /**
340
+ * Trigger a run manually
341
+ */
342
+ trigger(): Promise<void>;
343
+ /**
344
+ * Returns number of runs left, undefined = unlimited
345
+ */
346
+ runsLeft(): number | undefined;
347
+ /**
348
+ * Called when it's time to trigger.
349
+ * Checks if all conditions are currently met,
350
+ * then instantly triggers the scheduled function.
351
+ */
352
+ private _checkTrigger;
353
+ /**
354
+ * Internal version of next. Cron needs millseconds internally, hence _next.
355
+ */
356
+ private _next;
357
+ /**
358
+ * Calculate the previous run if no previous run is supplied, but startAt and interval are set.
359
+ * This calculation is only necessary if the startAt time is before the current time.
360
+ * Should only be called from the _next function.
361
+ */
362
+ private _calculatePreviousRun;
363
+ }
364
+
365
+ export {};