Comparing version 1.1.5 to 1.1.6
@@ -233,8 +233,8 @@ /* ------------------------------------------------------------------------------------ | ||
// Parse parts into arrays, validates as we go | ||
this.partToArray("seconds", this.seconds, parts[0], 0); | ||
this.partToArray("minutes", this.minutes, parts[1], 0); | ||
this.partToArray("hours", this.hours, parts[2], 0); | ||
this.partToArray("days", this.days, parts[3], -1); | ||
this.partToArray("months", this.months, parts[4], -1); | ||
this.partToArray("daysOfWeek", this.daysOfWeek, parts[5], 0); | ||
this.partToArray("seconds", parts[0], 0); | ||
this.partToArray("minutes", parts[1], 0); | ||
this.partToArray("hours", parts[2], 0); | ||
this.partToArray("days", parts[3], -1); | ||
this.partToArray("months", parts[4], -1); | ||
this.partToArray("daysOfWeek", parts[5], 0); | ||
@@ -252,11 +252,10 @@ // 0 = Sunday, 7 = Sunday | ||
CronPattern.prototype.partToArray = function (type, arr, conf, valueIndexOffset) { | ||
CronPattern.prototype.partToArray = function (type, conf, valueIndexOffset) { | ||
var i,x, | ||
confParts, | ||
var i, | ||
split, | ||
index, | ||
lower, | ||
upper, | ||
steps; | ||
steps, | ||
arr = this[type]; | ||
@@ -273,8 +272,8 @@ // First off, handle wildcard | ||
// Check if we need to split | ||
confParts = conf.split(","); | ||
split = conf.split(","); | ||
// Recurse into comma separated entries | ||
if (confParts.length > 1) { | ||
for (i = 0; i < confParts.length; i++) { | ||
this.partToArray(type, arr, confParts[i], valueIndexOffset); | ||
if (split.length > 1) { | ||
for (i = 0; i < split.length; i++) { | ||
this.partToArray(type, split[i], valueIndexOffset); | ||
} | ||
@@ -285,6 +284,6 @@ | ||
// Didn"t need to recurse, determine if this is a range, steps or a number | ||
// Didn't need to recurse, determine if this is a range, steps or a number | ||
// - Got a range | ||
if (conf.indexOf("-") !== -1) { | ||
// Got a range | ||
split = conf.split("-"); | ||
@@ -315,9 +314,9 @@ | ||
for (x = lower; x <= upper; x++) { | ||
arr[(x + valueIndexOffset)] = 1; | ||
for (i = lower; i <= upper; i++) { | ||
arr[(i + valueIndexOffset)] = 1; | ||
} | ||
// - Got stepping | ||
} else if (conf.indexOf("/") !== -1) { | ||
// Got a step | ||
split = conf.split("/"); | ||
@@ -347,17 +346,18 @@ | ||
for (x = 0; x < arr.length; x+= steps) { | ||
arr[(x + valueIndexOffset)] = 1; | ||
for (i = 0; i < arr.length; i+= steps) { | ||
arr[(i + valueIndexOffset)] = 1; | ||
} | ||
// - Got a number | ||
} else { | ||
// Got a number | ||
index = (parseInt(conf, 10) + valueIndexOffset); | ||
i = (parseInt(conf, 10) + valueIndexOffset); | ||
if (index < 0 || index >= arr.length) { | ||
if (i < 0 || i >= arr.length) { | ||
raise(type + " value out of range: '" + conf + "'"); | ||
} | ||
arr[index] = 1; | ||
arr[i] = 1; | ||
} | ||
}; | ||
@@ -364,0 +364,0 @@ |
// Licenced under MIT - croner - ©2016 Hexagon <github.com/hexagon> | ||
(function(){"use strict";function c(a){throw new TypeError("Cron parser: "+a)}function d(){return new Date((new Date).setMilliseconds(0))}function e(a,b){for(var c=0;c<a.length;c++)a[c]=b;return a}function f(a){this.seconds=a.getSeconds()+1,this.minutes=a.getMinutes(),this.hours=a.getHours(),this.days=a.getDate(),this.months=a.getMonth(),this.years=a.getFullYear()}function g(a){this.pattern=a,this.seconds=e(Array(60),0),this.minutes=e(Array(60),0),this.hours=e(Array(24),0),this.days=e(Array(31),0),this.months=e(Array(12),0),this.daysOfWeek=e(Array(8),0),this.parse()}function h(a,b,c){var d=this;return this instanceof h?(d.pattern=new g(a),d.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof b&&(c=b,b={}),"undefined"==typeof c?d:this.schedule(b,c)):new h(a,b,c)}var a=this,b=Math.pow(2,31)-1;f.prototype.findNext=function(a,b,c,d){for(var e=void 0===d?this[a]+c:0+c,f=!1,g=e;g<b[a].length;g++)if(b[a][g]){this[a]=g-c,f=!0;break}return f},f.prototype.increment=function(a){for(var b=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],c=0;c<5;){if(!this.findNext(b[c][0],a,b[c][2]))for(this[b[c][1]]++;c>=0;)this.findNext(b[c][0],a,b[c][2],0),c--;c++}for(;!a.daysOfWeek[this.getDate().getDay()];)this.days+=1},f.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,0)},g.prototype.parse=function(){"string"!=typeof this.pattern&&c("invalid configuration string ('"+this.pattern+"').");var b,d,f,g,h,a=this.pattern.trim().replace(/\s+/g," ").split(" "),e=/[^\/\*0-9,-]+/;for(6!==a.length&&c("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),d=0;d<a.length;d++)b=a[d].trim(),e.test(b)&&c("configuration entry "+(d+1)+" ("+b+") contains illegal characters.");f="*"!==a[4],g="*"!==a[5],h="*"!==a[3],g&&(f||h)&&c("configuration invalid, you can not combine month/date with day of week."),this.partToArray("seconds",this.seconds,a[0],0),this.partToArray("minutes",this.minutes,a[1],0),this.partToArray("hours",this.hours,a[2],0),this.partToArray("days",this.days,a[3],-1),this.partToArray("months",this.months,a[4],-1),this.partToArray("daysOfWeek",this.daysOfWeek,a[5],0),this.daysOfWeek[0]&&(this.daysOfWeek[7]=1),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},g.prototype.partToArray=function(a,b,d,e){var f,g,h,i,j,k,l,m;if("*"!==d)if(h=d.split(","),h.length>1)for(f=0;f<h.length;f++)this.partToArray(a,b,h[f],e);else if(d.indexOf("-")!==-1)for(i=d.split("-"),2!==i.length&&c("Syntax error, illegal range: '"+d+"'"),k=parseInt(i[0],10)+e,l=parseInt(i[1],10)+e,isNaN(k)?c("Syntax error, illegal lower range (NaN)"):isNaN(l)&&c("Syntax error, illegal upper range (NaN)"),(k<0||l>=b.length)&&c("Value out of range: '"+d+"'"),k>l&&c("From value is larger than to value: '"+d+"'"),g=k;g<=l;g++)b[g+e]=1;else if(d.indexOf("/")!==-1)for(i=d.split("/"),2!==i.length&&c("Syntax error, illegal stepping: '"+d+"'"),"*"!==i[0]&&c("Syntax error, left part of / needs to be * : '"+d+"'"),m=parseInt(i[1],10),isNaN(m)&&c("Syntax error, illegal stepping: (NaN)"),0===m&&c("Syntax error, illegal stepping: 0"),m>b.length&&c("Syntax error, steps cannot be greater than maximum value of part ("+b.length+")"),g=0;g<b.length;g+=m)b[g+e]=1;else j=parseInt(d,10)+e,(j<0||j>=b.length)&&c(a+" value out of range: '"+d+"'"),b[j]=1;else for(f=0;f<b.length;f++)b[f]=1},h.prototype.next=function(a){var b=new f(a||d());return b.increment(this.pattern),b.getDate()},h.prototype.msToNext=function(a){return a=a||d(),this.next(a)-a.getTime()},h.prototype.schedule=function(a,c,e){var g,f=this,h=f.maxDelay||b;if(c||(c=a,a={}),a.paused="undefined"!=typeof a.paused&&a.paused,a.previous=e===!1?d():a.startAt||a.previous,a.stopAt=a.stopAt||this.schedulerDefaults.stopAt,a.kill=a.kill||this.schedulerDefaults.kill,a.rest=a.rest||0,a.maxRuns||0===a.maxRuns||(a.maxRuns=this.schedulerDefaults.maxRuns),a.startAt=void 0,g=this.msToNext(a.previous),!(a.maxRuns<=0||a.stopAt!==1/0&&a.previous.getTime()+g/1e3>a.stopAt.getTime()||a.kill))return g>h&&(g=h),a.currentTimeout=setTimeout(function(){g===h||a.paused||(a.maxRuns--,a.previous=d(),c()),a.paused&&(a.previous=d()),f.schedule(a,c,!0)},g),{stop:function(){a.kill=!0,a.currentTimeout&&clearTimeout(a.currentTimeout)},pause:function(){return(a.paused=!0)&&!a.kill},resume:function(){return!(a.paused=!1)&&!a.kill}}},"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=h:"function"==typeof define&&define.amd?define([],function(){return h}):a.Cron=h}).call(this); | ||
(function(){"use strict";function c(a){throw new TypeError("Cron parser: "+a)}function d(){return new Date((new Date).setMilliseconds(0))}function e(a,b){for(var c=0;c<a.length;c++)a[c]=b;return a}function f(a){this.seconds=a.getSeconds()+1,this.minutes=a.getMinutes(),this.hours=a.getHours(),this.days=a.getDate(),this.months=a.getMonth(),this.years=a.getFullYear()}function g(a){this.pattern=a,this.seconds=e(Array(60),0),this.minutes=e(Array(60),0),this.hours=e(Array(24),0),this.days=e(Array(31),0),this.months=e(Array(12),0),this.daysOfWeek=e(Array(8),0),this.parse()}function h(a,b,c){var d=this;return this instanceof h?(d.pattern=new g(a),d.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof b&&(c=b,b={}),"undefined"==typeof c?d:this.schedule(b,c)):new h(a,b,c)}var a=this,b=Math.pow(2,31)-1;f.prototype.findNext=function(a,b,c,d){for(var e=void 0===d?this[a]+c:0+c,f=!1,g=e;g<b[a].length;g++)if(b[a][g]){this[a]=g-c,f=!0;break}return f},f.prototype.increment=function(a){for(var b=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],c=0;c<5;){if(!this.findNext(b[c][0],a,b[c][2]))for(this[b[c][1]]++;c>=0;)this.findNext(b[c][0],a,b[c][2],0),c--;c++}for(;!a.daysOfWeek[this.getDate().getDay()];)this.days+=1},f.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,0)},g.prototype.parse=function(){"string"!=typeof this.pattern&&c("invalid configuration string ('"+this.pattern+"').");var b,d,f,g,h,a=this.pattern.trim().replace(/\s+/g," ").split(" "),e=/[^\/\*0-9,-]+/;for(6!==a.length&&c("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),d=0;d<a.length;d++)b=a[d].trim(),e.test(b)&&c("configuration entry "+(d+1)+" ("+b+") contains illegal characters.");f="*"!==a[4],g="*"!==a[5],h="*"!==a[3],g&&(f||h)&&c("configuration invalid, you can not combine month/date with day of week."),this.partToArray("seconds",a[0],0),this.partToArray("minutes",a[1],0),this.partToArray("hours",a[2],0),this.partToArray("days",a[3],-1),this.partToArray("months",a[4],-1),this.partToArray("daysOfWeek",a[5],0),this.daysOfWeek[0]&&(this.daysOfWeek[7]=1),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},g.prototype.partToArray=function(a,b,d){var e,f,g,h,i,j=this[a];if("*"!==b)if(f=b.split(","),f.length>1)for(e=0;e<f.length;e++)this.partToArray(a,f[e],d);else if(b.indexOf("-")!==-1)for(f=b.split("-"),2!==f.length&&c("Syntax error, illegal range: '"+b+"'"),g=parseInt(f[0],10)+d,h=parseInt(f[1],10)+d,isNaN(g)?c("Syntax error, illegal lower range (NaN)"):isNaN(h)&&c("Syntax error, illegal upper range (NaN)"),(g<0||h>=j.length)&&c("Value out of range: '"+b+"'"),g>h&&c("From value is larger than to value: '"+b+"'"),e=g;e<=h;e++)j[e+d]=1;else if(b.indexOf("/")!==-1)for(f=b.split("/"),2!==f.length&&c("Syntax error, illegal stepping: '"+b+"'"),"*"!==f[0]&&c("Syntax error, left part of / needs to be * : '"+b+"'"),i=parseInt(f[1],10),isNaN(i)&&c("Syntax error, illegal stepping: (NaN)"),0===i&&c("Syntax error, illegal stepping: 0"),i>j.length&&c("Syntax error, steps cannot be greater than maximum value of part ("+j.length+")"),e=0;e<j.length;e+=i)j[e+d]=1;else e=parseInt(b,10)+d,(e<0||e>=j.length)&&c(a+" value out of range: '"+b+"'"),j[e]=1;else for(e=0;e<j.length;e++)j[e]=1},h.prototype.next=function(a){var b=new f(a||d());return b.increment(this.pattern),b.getDate()},h.prototype.msToNext=function(a){return a=a||d(),this.next(a)-a.getTime()},h.prototype.schedule=function(a,c,e){var g,f=this,h=f.maxDelay||b;if(c||(c=a,a={}),a.paused="undefined"!=typeof a.paused&&a.paused,a.previous=e===!1?d():a.startAt||a.previous,a.stopAt=a.stopAt||this.schedulerDefaults.stopAt,a.kill=a.kill||this.schedulerDefaults.kill,a.rest=a.rest||0,a.maxRuns||0===a.maxRuns||(a.maxRuns=this.schedulerDefaults.maxRuns),a.startAt=void 0,g=this.msToNext(a.previous),!(a.maxRuns<=0||a.stopAt!==1/0&&a.previous.getTime()+g/1e3>a.stopAt.getTime()||a.kill))return g>h&&(g=h),a.currentTimeout=setTimeout(function(){g===h||a.paused||(a.maxRuns--,a.previous=d(),c()),a.paused&&(a.previous=d()),f.schedule(a,c,!0)},g),{stop:function(){a.kill=!0,a.currentTimeout&&clearTimeout(a.currentTimeout)},pause:function(){return(a.paused=!0)&&!a.kill},resume:function(){return!(a.paused=!1)&&!a.kill}}},"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=h:"function"==typeof define&&define.amd?define([],function(){return h}):a.Cron=h}).call(this); |
{ | ||
"name": "croner", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "Isomorphic JavaScript cron parser and scheduler.", | ||
@@ -5,0 +5,0 @@ "author": "Hexagon <github.com/hexagon>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43846
972