Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

croner

Package Overview
Dependencies
Maintainers
1
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

croner - npm Package Compare versions

Comparing version 1.1.7 to 1.1.8

29

lib/croner.js

@@ -388,3 +388,3 @@ /* ------------------------------------------------------------------------------------

// Store options
self.opts = options || {};
self.opts = self.validateOpts(options || {});

@@ -428,5 +428,25 @@ // Determine what to return, default is self

Cron.prototype.validateOpts = function (opts) {
if( opts.startAt !== undefined ) {
if( opts.startAt.constructor !== Date ) {
opts.startAt = new Date(Date.parse(opts.startAt)-1);
} else {
opts.startAt = new Date(opts.startAt.getTime()-1);
}
}
if( opts.stopAt !== undefined ) {
if( opts.stopAt.constructor !== Date ) {
opts.stopAt = new Date(Date.parse(opts.stopAt));
}
}
return opts;
};
Cron.prototype.msToNext = function (prev) {
prev = prev || safeDate();
return (this.next(prev) - prev.getTime());
var next = this.next(prev);
if (next)
return (this.next(prev) - prev.getTime());
else
return next;
};

@@ -458,7 +478,4 @@

// Store options
self.opts = opts;
self.opts = self.validateOpts(opts || {});
// One-timer
opts.startAt = void 0;
// Get ms to next run

@@ -465,0 +482,0 @@ waitMs = this.msToNext(opts.previous);

// 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={}),d.opts=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){this.opts.startAt&&a<this.opts.startAt&&(a=this.opts.startAt);var e,a=a||this.opts.startAt||d(),b=this.opts.stopAt||this.schedulerDefaults.stopAt,c=new f(a);if(c.increment(this.pattern),e=c.getDate(),!(b&&e>=b))return e},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.kill=a.kill||this.schedulerDefaults.kill,a.rest=a.rest||0,a.maxRuns||0===a.maxRuns||(a.maxRuns=this.schedulerDefaults.maxRuns),f.opts=a,a.startAt=void 0,g=this.msToNext(a.previous),!(a.maxRuns<=0||void 0===g||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={}),d.opts=d.validateOpts(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){this.opts.startAt&&a<this.opts.startAt&&(a=this.opts.startAt);var e,a=a||this.opts.startAt||d(),b=this.opts.stopAt||this.schedulerDefaults.stopAt,c=new f(a);if(c.increment(this.pattern),e=c.getDate(),!(b&&e>=b))return e},h.prototype.validateOpts=function(a){return void 0!==a.startAt&&(a.startAt.constructor!==Date?a.startAt=new Date(Date.parse(a.startAt)-1):a.startAt=new Date(a.startAt.getTime()-1)),void 0!==a.stopAt&&a.stopAt.constructor!==Date&&(a.stopAt=new Date(Date.parse(a.stopAt))),a},h.prototype.msToNext=function(a){a=a||d();var b=this.next(a);return b?this.next(a)-a.getTime():b},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.kill=a.kill||this.schedulerDefaults.kill,a.rest=a.rest||0,a.maxRuns||0===a.maxRuns||(a.maxRuns=this.schedulerDefaults.maxRuns),f.opts=f.validateOpts(a||{}),g=this.msToNext(a.previous),!(a.maxRuns<=0||void 0===g||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.7",
"version": "1.1.8",
"description": "Isomorphic JavaScript cron parser and scheduler.",

@@ -5,0 +5,0 @@ "author": "Hexagon <github.com/hexagon>",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc