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.29 to 1.1.30

2

dist/croner.min.js

@@ -1,1 +0,1 @@

!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var r in s)("object"==typeof exports?exports:t)[r]=s[r]}}(this,(function(){return t={10:(t,e,s)=>{var r=s(407);t.exports=r,t.exports.Cron=r},407:t=>{const e=Math.pow(2,31)-1;function s(t){throw new TypeError("Cron parser: "+t)}function r(t,e){for(let s=0;s<t.length;s++)t[s]=e;return t}function n(t){this.milliseconds=t.getMilliseconds(),this.seconds=t.getSeconds()+1,this.minutes=t.getMinutes(),this.hours=t.getHours(),this.days=t.getDate(),this.months=t.getMonth(),this.years=t.getFullYear()}function o(t){this.pattern=t,this.seconds=r(Array(60),0),this.minutes=r(Array(60),0),this.hours=r(Array(24),0),this.days=r(Array(31),0),this.months=r(Array(12),0),this.daysOfWeek=r(Array(8),0),this.parse()}function a(t,e,s){let r=this;return this instanceof a?(r.pattern=new o(t),r.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof e&&(s=e,e={}),r.opts=r.validateOpts(e||{}),void 0===s?r:this.schedule(e,s)):new a(t,e,s)}n.prototype.increment=function(t){let e=this,s=function(t,s,r,n){for(let o=void 0===n?e[t]+r:0+r;o<s[t].length;o++)if(s[t][o])return e[t]=o-r,!0;return!1},r=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],n=0;for(;n<5;){if(!s(r[n][0],t,r[n][2]))for(this[r[n][1]]++;n>=0;)s(r[n][0],t,r[n][2],0),n--;n++}for(;!t.daysOfWeek[this.getDate().getDay()];)this.days+=1},n.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,0)},o.prototype.parse=function(){"string"!=typeof this.pattern&&this.pattern.constructor!==String&&s("Pattern has to be of type string.");let t,e,r,n,o,a=this.pattern.trim().replace(/\s+/g," ").split(" "),i=/[^/*0-9,-]+/;for(6!==a.length&&s("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),e=0;e<a.length;e++)t=a[e].trim(),i.test(t)&&s("configuration entry "+(e+1)+" ("+t+") contains illegal characters.");r="*"!==a[4],n="*"!==a[5],o="*"!==a[3],n&&(r||o)&&s("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[7]&&(this.daysOfWeek[0]=1)},o.prototype.partToArray=function(t,e,r){let n,o,a,i,u,p=this[t];if("*"!==e)if(o=e.split(","),o.length>1)for(n=0;n<o.length;n++)this.partToArray(t,o[n],r);else if(-1!==e.indexOf("-"))for(o=e.split("-"),2!==o.length&&s("Syntax error, illegal range: '"+e+"'"),a=parseInt(o[0],10)+r,i=parseInt(o[1],10)+r,isNaN(a)?s("Syntax error, illegal lower range (NaN)"):isNaN(i)&&s("Syntax error, illegal upper range (NaN)"),(a<0||i>=p.length)&&s("Value out of range: '"+e+"'"),a>i&&s("From value is larger than to value: '"+e+"'"),n=a;n<=i;n++)p[n+r]=1;else if(-1!==e.indexOf("/"))for(o=e.split("/"),2!==o.length&&s("Syntax error, illegal stepping: '"+e+"'"),"*"!==o[0]&&s("Syntax error, left part of / needs to be * : '"+e+"'"),u=parseInt(o[1],10),isNaN(u)&&s("Syntax error, illegal stepping: (NaN)"),0===u&&s("Syntax error, illegal stepping: 0"),u>p.length&&s("Syntax error, steps cannot be greater than maximum value of part ("+p.length+")"),n=0;n<p.length;n+=u)p[n+r]=1;else n=parseInt(e,10)+r,(n<0||n>=p.length)&&s(t+" value out of range: '"+e+"'"),p[n]=1;else for(n=0;n<p.length;n++)p[n]=1},a.prototype.next=function(t){let e=this._next(t);return e&&e.setMilliseconds(0),e},a.prototype._next=function(t){if(t=t||new Date,this.opts.startAt&&t<this.opts.startAt&&(t=this.opts.startAt),this.opts.maxRuns<=0||this.opts.kill)return;let e,s=this.opts.stopAt||this.schedulerDefaults.stopAt,r=new n(t);return r.increment(this.pattern),e=r.getDate(),s&&e>=s?void 0:e},a.prototype.validateOpts=function(t){return t.startAt&&(t.startAt.constructor!==Date?t.startAt=new Date(Date.parse(t.startAt)-1):t.startAt=new Date(t.startAt.getTime()-1),isNaN(t.startAt)&&s("Provided value for startAt could not be parsed as date.")),t.stopAt&&(t.stopAt.constructor!==Date&&(t.stopAt=new Date(Date.parse(t.stopAt))),isNaN(t.stopAt)&&s("Provided value for stopAt could not be parsed as date.")),t},a.prototype.msToNext=function(t){t=t||new Date;let e=this._next(t);return e?this._next(t)-t.getTime():e},a.prototype.schedule=function(t,s){let r,n=this,o=n.maxDelay||e;if(s||(s=t,t={}),t.paused=void 0!==t.paused&&t.paused,t.kill=t.kill||this.schedulerDefaults.kill,t.rest=t.rest||0,t.maxRuns||0===t.maxRuns||(t.maxRuns=this.schedulerDefaults.maxRuns),n.opts=n.validateOpts(t||{}),r=this.msToNext(t.previous),void 0!==r)return r>o&&(r=o),t.currentTimeout=setTimeout((function(){r!==o&&(t.previous=n._next(t.previous),t.paused||(t.maxRuns--,s())),n.schedule(t,s)}),r),{stop:function(){t.kill=!0,t.currentTimeout&&clearTimeout(t.currentTimeout)},pause:function(){return(t.paused=!0)&&!t.kill},resume:function(){return!(t.paused=!1)&&!t.kill}}},t.exports=a}},e={},function s(r){var n=e[r];if(void 0!==n)return n.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,s),o.exports}(10);var t,e}));
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var r in s)("object"==typeof exports?exports:t)[r]=s[r]}}(this,(function(){return t={10:(t,e,s)=>{var r=s(407);t.exports=r,t.exports.Cron=r},407:t=>{const e=Math.pow(2,31)-1;function s(t){throw new TypeError("Cron parser: "+t)}function r(t,e){for(let s=0;s<t.length;s++)t[s]=e;return t}function n(t){this.milliseconds=t.getMilliseconds(),this.seconds=t.getSeconds(),this.minutes=t.getMinutes(),this.hours=t.getHours(),this.days=t.getDate(),this.months=t.getMonth(),this.years=t.getFullYear()}function o(t){this.pattern=t,this.seconds=r(Array(60),0),this.minutes=r(Array(60),0),this.hours=r(Array(24),0),this.days=r(Array(31),0),this.months=r(Array(12),0),this.daysOfWeek=r(Array(8),0),this.parse()}function i(t,e,s){let r=this;return this instanceof i?(r.pattern=new o(t),r.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof e&&(s=e,e={}),r.opts=r.validateOpts(e||{}),void 0===s?r:this.schedule(e,s)):new i(t,e,s)}n.prototype.increment=function(t){this.seconds+=1,this.milliseconds=0;let e=this,s=function(t,s,r,n){for(let o=void 0===n?e[t]+r:0+r;o<s[t].length;o++)if(s[t][o])return e[t]=o-r,!0;return!1},r=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],n=0;for(;n<5;){if(!s(r[n][0],t,r[n][2]))for(this[r[n][1]]++;n>=0;)s(r[n][0],t,r[n][2],0),n--;n++}for(;!t.daysOfWeek[this.getDate().getDay()];)this.days+=1},n.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,this.milliseconds)},o.prototype.parse=function(){"string"!=typeof this.pattern&&this.pattern.constructor!==String&&s("Pattern has to be of type string.");let t,e,r,n,o,i=this.pattern.trim().replace(/\s+/g," ").split(" "),a=/[^/*0-9,-]+/;for(6!==i.length&&s("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),e=0;e<i.length;e++)t=i[e].trim(),a.test(t)&&s("configuration entry "+(e+1)+" ("+t+") contains illegal characters.");r="*"!==i[4],n="*"!==i[5],o="*"!==i[3],n&&(r||o)&&s("configuration invalid, you can not combine month/date with day of week."),this.partToArray("seconds",i[0],0),this.partToArray("minutes",i[1],0),this.partToArray("hours",i[2],0),this.partToArray("days",i[3],-1),this.partToArray("months",i[4],-1),this.partToArray("daysOfWeek",i[5],0),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},o.prototype.partToArray=function(t,e,r){let n,o,i,a,p,u=this[t];if("*"!==e)if(o=e.split(","),o.length>1)for(n=0;n<o.length;n++)this.partToArray(t,o[n],r);else if(-1!==e.indexOf("-"))for(o=e.split("-"),2!==o.length&&s("Syntax error, illegal range: '"+e+"'"),i=parseInt(o[0],10)+r,a=parseInt(o[1],10)+r,isNaN(i)?s("Syntax error, illegal lower range (NaN)"):isNaN(a)&&s("Syntax error, illegal upper range (NaN)"),(i<0||a>=u.length)&&s("Value out of range: '"+e+"'"),i>a&&s("From value is larger than to value: '"+e+"'"),n=i;n<=a;n++)u[n+r]=1;else if(-1!==e.indexOf("/"))for(o=e.split("/"),2!==o.length&&s("Syntax error, illegal stepping: '"+e+"'"),"*"!==o[0]&&s("Syntax error, left part of / needs to be * : '"+e+"'"),p=parseInt(o[1],10),isNaN(p)&&s("Syntax error, illegal stepping: (NaN)"),0===p&&s("Syntax error, illegal stepping: 0"),p>u.length&&s("Syntax error, steps cannot be greater than maximum value of part ("+u.length+")"),n=0;n<u.length;n+=p)u[n+r]=1;else n=parseInt(e,10)+r,(n<0||n>=u.length)&&s(t+" value out of range: '"+e+"'"),u[n]=1;else for(n=0;n<u.length;n++)u[n]=1},i.prototype.next=function(t){let e=this._next(t);return e&&e.setMilliseconds(0),e},i.prototype.previous=function(){return this.opts.previous},i.prototype._next=function(t){if(t=t||new Date,this.opts.startAt&&t<this.opts.startAt&&(t=this.opts.startAt),this.opts.maxRuns<=0||this.opts.kill)return;let e,s=this.opts.stopAt||this.schedulerDefaults.stopAt,r=new n(t);return r.increment(this.pattern),e=r.getDate(),s&&e>=s?void 0:e},i.prototype.validateOpts=function(t){return t.startAt&&(t.startAt.constructor!==Date?t.startAt=new Date(Date.parse(t.startAt)-1):t.startAt=new Date(t.startAt.getTime()-1),isNaN(t.startAt)&&s("Provided value for startAt could not be parsed as date.")),t.stopAt&&(t.stopAt.constructor!==Date&&(t.stopAt=new Date(Date.parse(t.stopAt))),isNaN(t.stopAt)&&s("Provided value for stopAt could not be parsed as date.")),t},i.prototype.msToNext=function(t){t=t||new Date;let e=this._next(t);return e?this._next(t)-t.getTime():e},i.prototype.schedule=function(t,s){let r,n=this,o=n.maxDelay||e;if(s||(s=t,t={}),t.paused=void 0!==t.paused&&t.paused,t.kill=t.kill||this.schedulerDefaults.kill,t.rest=t.rest||0,t.maxRuns||0===t.maxRuns||(t.maxRuns=this.schedulerDefaults.maxRuns),n.opts=n.validateOpts(t||{}),r=this.msToNext(t.previous),void 0!==r)return r>o&&(r=o),t.currentTimeout=setTimeout((function(){r!==o&&(t.paused||(t.maxRuns--,s()),t.previous=new Date),n.schedule(t,s)}),r),{stop:function(){t.kill=!0,t.currentTimeout&&clearTimeout(t.currentTimeout)},pause:function(){return(t.paused=!0)&&!t.kill},resume:function(){return!(t.paused=!1)&&!t.kill}}},t.exports=i}},e={},function s(r){var n=e[r];if(void 0!==n)return n.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,s),o.exports}(10);var t,e}));
{
"name": "croner",
"version": "1.1.29",
"version": "1.1.30",
"description": "Isomorphic JavaScript cron parser and scheduler.",

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

"test:lint:fix": "eslint --fix ./src/croner.js",
"build": "npm run test:lint && npm run build:typings && npm run build:webpack && npm run test:mocha",
"build": "npm run test:lint && npm run build:typings && npm run build:webpack && npm run test:mocha && npm run build:finalize",
"build:webpack": "webpack",
"build:typings": "tsc"
"build:typings": "tsc",
"build:finalize": "echo \"All good\n\nHOWEVER. You now need to change export = Cron; to export { Cron, Cron as default }; in types/croner.d.ts before publishing."
},

@@ -46,3 +47,3 @@ "main": "index.js",

"typescript": "^4.4.3",
"webpack": "^5.56.1",
"webpack": "^5.57.1",
"webpack-cli": "^4.8.0"

@@ -49,0 +50,0 @@ },

# Croner
[![Build status](https://travis-ci.org/Hexagon/croner.svg)](https://travis-ci.org/Hexagon/croner) [![npm version](https://badge.fury.io/js/croner.svg)](https://badge.fury.io/js/croner) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4978bdbf495941c087ecb32b120f28ff)](https://www.codacy.com/gh/Hexagon/croner/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Hexagon/croner&amp;utm_campaign=Badge_Grade)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://img.shields.io/badge/license-MIT-blue.svg)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Hexagon/croner/blob/master/LICENSE) [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/croner/badge?style=rounded)](https://www.jsdelivr.com/package/npm/croner)

@@ -13,3 +13,3 @@ Pure JavaScript minimal isomorphic cron parser and scheduler. Or simply speaking - setInterval on steroids.

```html
<script src="//cdn.56k.guru/js/croner/latest/croner.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/croner@1.1.30/dist/croner.min.js"></script>
```

@@ -39,3 +39,3 @@

```html
<script src="//cdn.56k.guru/js/croner/latest/croner.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/croner@1.1.30/dist/croner.min.js"></script>
```

@@ -74,3 +74,3 @@

<script type="module">
import Cron from 'https://cdn.jsdelivr.net/npm/croner@1.1.27/dist/croner.min.mjs';
import Cron from 'https://cdn.jsdelivr.net/npm/croner@1.1.30/dist/croner.min.mjs';

@@ -91,3 +91,3 @@ Cron('* * * * * *', () => {

"imports": {
"croner": "https://cdn.jsdelivr.net/npm/croner@1.1.27/dist/croner.min.mjs"
"croner": "https://cdn.jsdelivr.net/npm/croner@1.1.30/dist/croner.min.mjs"
}

@@ -235,2 +235,3 @@ }

o.msToNext();
o.previous();

@@ -237,0 +238,0 @@ // If Cron is initialized _with_ a scheduled function, the job is retured instead.

/* ------------------------------------------------------------------------------------
Croner 1.1.29 - MIT License - Hexagon <github.com/Hexagon>
Croner 1.1.30 - MIT License - Hexagon <github.com/Hexagon>

@@ -118,3 +118,3 @@ Pure JavaScript Isomorphic cron parser and scheduler without dependencies.

this.milliseconds = date.getMilliseconds();
this.seconds = date.getSeconds() + 1;
this.seconds = date.getSeconds();
this.minutes = date.getMinutes();

@@ -134,2 +134,5 @@ this.hours = date.getHours();

this.seconds += 1;
this.milliseconds = 0;
let self = this,

@@ -229,3 +232,3 @@

CronDate.prototype.getDate = function () {
return new Date(this.years, this.months, this.days, this.hours, this.minutes, this.seconds, 0);
return new Date(this.years, this.months, this.days, this.hours, this.minutes, this.seconds, this.milliseconds);
};

@@ -498,2 +501,11 @@

/**
* Return previos run time
*
* @returns {Date?} - Previous run time
*/
Cron.prototype.previous = function () {
return this.opts.previous;
};
/**
* Internal version of next. Cron needs millseconds internally, hence _next.

@@ -635,8 +647,2 @@ *

// Assume that the function was executed on the exakt time it should have
// ----
// DO NOT assume it was executed at new Date(), as this could lead to double
// runs in case of an early run
opts.previous = self._next(opts.previous);
if ( !opts.paused ) {

@@ -646,3 +652,4 @@ opts.maxRuns--;

}
opts.previous = new Date();
}

@@ -649,0 +656,0 @@

@@ -536,2 +536,3 @@

diff.should.be.below(1001);
diff.should.be.above(-1);
prevRun = new Date(prevRun.getTime() + 1000000);

@@ -558,2 +559,3 @@ }

diff.should.be.below(1001);
diff.should.be.above(-1);
prevRun = new Date(prevRun.getTime() + 1000000);

@@ -560,0 +562,0 @@ }

@@ -1,2 +0,2 @@

export = Cron;
export { Cron, Cron as default };
/**

@@ -37,2 +37,8 @@ * Cron entrypoint

/**
* Return previos run time
*
* @returns {Date?} - Previous run time
*/
previous(): Date | null;
/**
* Internal version of next. Cron needs millseconds internally, hence _next.

@@ -39,0 +45,0 @@ *

Sorry, the diff of this file is not supported yet

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