Comparing version 1.1.23 to 1.1.24
@@ -21,4 +21,5 @@ { | ||
2, | ||
15 | ||
] | ||
22 | ||
], | ||
"no-var": 1 | ||
}, | ||
@@ -25,0 +26,0 @@ "globals": { |
var croner = require("./lib/croner.js"); | ||
module.exports = croner; |
@@ -37,3 +37,3 @@ /* ------------------------------------------------------------------------------------ | ||
var root = this, | ||
let root = this, | ||
@@ -61,3 +61,3 @@ // Many JS engines stores the delay as a 32-bit signed integer internally. | ||
// Simple "Polyfill" for Array.fill on pre ES6 environments | ||
for(var i = 0; i < arr.length; i++) { | ||
for(let i = 0; i < arr.length; i++) { | ||
arr[i] = val; | ||
@@ -88,9 +88,9 @@ } | ||
var self = this, | ||
let self = this, | ||
findNext = function (target, pattern, offset, override) { | ||
var startPos = (override === void 0) ? self[target] + offset : 0 + offset; | ||
let startPos = (override === void 0) ? self[target] + offset : 0 + offset; | ||
for( var i = startPos; i < pattern[target].length; i++ ) { | ||
for( let i = startPos; i < pattern[target].length; i++ ) { | ||
if( pattern[target][i] ) { | ||
@@ -113,3 +113,3 @@ self[target] = i-offset; | ||
// ] | ||
var toDo = [ | ||
let toDo = [ | ||
["seconds", "minutes", 0], | ||
@@ -198,6 +198,6 @@ ["minutes", "hours", 0], | ||
// Split configuration on whitespace | ||
var parts = this.pattern.trim().replace(/\s+/g, " ").split(" "), | ||
let parts = this.pattern.trim().replace(/\s+/g, " ").split(" "), | ||
part, | ||
i, | ||
reValidCron = /[^\/\*0-9,-]+/, | ||
reValidCron = /[^/*0-9,-]+/, | ||
hasMonths, | ||
@@ -249,3 +249,3 @@ hasDaysOfWeek, | ||
var i, | ||
let i, | ||
split, | ||
@@ -262,7 +262,5 @@ lower, | ||
} | ||
return; | ||
} | ||
// Recurse into comma separated entries | ||
@@ -363,3 +361,3 @@ split = conf.split(","); | ||
function Cron (pattern, options, fn) { | ||
var self = this; | ||
let self = this; | ||
@@ -403,6 +401,6 @@ // Optional "new" keyword | ||
Cron.prototype.next = function (prev) { | ||
var dirtyDate = this._next(prev); | ||
let dirtyDate = this._next(prev); | ||
if (dirtyDate) dirtyDate.setMilliseconds(0); | ||
return dirtyDate; | ||
} | ||
}; | ||
@@ -425,3 +423,3 @@ // Cron needs millseconds internally, hence _next | ||
var | ||
let | ||
stopAt = this.opts.stopAt || this.schedulerDefaults.stopAt, | ||
@@ -469,3 +467,3 @@ cronDate = new CronDate(prev), | ||
prev = prev || new Date(); | ||
var next = this._next(prev); | ||
let next = this._next(prev); | ||
if( next ) { | ||
@@ -480,3 +478,3 @@ return (this._next(prev) - prev.getTime()); | ||
var self = this, | ||
let self = this, | ||
waitMs, | ||
@@ -483,0 +481,0 @@ |
// Licenced under MIT - croner 1.1.21 - ©2015-2017 Hexagon <github.com/hexagon> | ||
(function(){"use strict";function t(t){throw new TypeError("Cron parser: "+t)}function e(t,e){for(var s=0;s<t.length;s++)t[s]=e;return t}function s(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 r(t){this.pattern=t,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 n(t,e,s){var a=this;return this instanceof n?(a.pattern=new r(t),a.schedulerDefaults={stopAt:1/0,maxRuns:1/0,kill:!1},"function"==typeof e&&(s=e,e={}),a.opts=a.validateOpts(e||{}),void 0===s?a:this.schedule(e,s)):new n(t,e,s)}var a=this,i=Math.pow(2,31)-1;s.prototype.increment=function(t){for(var e=this,s=function(t,s,r,n){for(var a=void 0===n?e[t]+r:0+r;a<s[t].length;a++)if(s[t][a])return e[t]=a-r,!0;return!1},r=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],n=0;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},s.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,0)},r.prototype.parse=function(){"string"!=typeof this.pattern&&this.pattern.constructor!==String&&t("Pattern has to be of type string.");var e,s,r,n,a,i=this.pattern.trim().replace(/\s+/g," ").split(" "),o=/[^\/\*0-9,-]+/;for(6!==i.length&&t("invalid configuration format ('"+this.pattern+"'), exacly five space separated parts required."),s=0;s<i.length;s++)e=i[s].trim(),o.test(e)&&t("configuration entry "+(s+1)+" ("+e+") contains illegal characters.");r="*"!==i[4],n="*"!==i[5],a="*"!==i[3],n&&(r||a)&&t("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)},r.prototype.partToArray=function(e,s,r){var n,a,i,o,u,l=this[e];if("*"!==s)if((a=s.split(",")).length>1)for(n=0;n<a.length;n++)this.partToArray(e,a[n],r);else if(-1!==s.indexOf("-"))for(2!==(a=s.split("-")).length&&t("Syntax error, illegal range: '"+s+"'"),i=parseInt(a[0],10)+r,o=parseInt(a[1],10)+r,isNaN(i)?t("Syntax error, illegal lower range (NaN)"):isNaN(o)&&t("Syntax error, illegal upper range (NaN)"),(i<0||o>=l.length)&&t("Value out of range: '"+s+"'"),i>o&&t("From value is larger than to value: '"+s+"'"),n=i;n<=o;n++)l[n+r]=1;else if(-1!==s.indexOf("/"))for(2!==(a=s.split("/")).length&&t("Syntax error, illegal stepping: '"+s+"'"),"*"!==a[0]&&t("Syntax error, left part of / needs to be * : '"+s+"'"),u=parseInt(a[1],10),isNaN(u)&&t("Syntax error, illegal stepping: (NaN)"),0===u&&t("Syntax error, illegal stepping: 0"),u>l.length&&t("Syntax error, steps cannot be greater than maximum value of part ("+l.length+")"),n=0;n<l.length;n+=u)l[n+r]=1;else((n=parseInt(s,10)+r)<0||n>=l.length)&&t(e+" value out of range: '"+s+"'"),l[n]=1;else for(n=0;n<l.length;n++)l[n]=1},n.prototype.next=function(t){var e=this._next(t);return e&&e.setMilliseconds(0),e},n.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)){var e,r=this.opts.stopAt||this.schedulerDefaults.stopAt,n=new s(t);return n.increment(this.pattern),e=n.getDate(),r&&e>=r?void 0:e}},n.prototype.validateOpts=function(e){return e.startAt&&(e.startAt.constructor!==Date?e.startAt=new Date(Date.parse(e.startAt)-1):e.startAt=new Date(e.startAt.getTime()-1),isNaN(e.startAt)&&t("Provided value for startAt could not be parsed as date.")),e.stopAt&&(e.stopAt.constructor!==Date&&(e.stopAt=new Date(Date.parse(e.stopAt))),isNaN(e.stopAt)&&t("Provided value for stopAt could not be parsed as date.")),e},n.prototype.msToNext=function(t){t=t||new Date;var e=this._next(t);return e?this._next(t)-t.getTime():e},n.prototype.schedule=function(t,e){var s,r=this,n=r.maxDelay||i;if(e||(e=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),r.opts=r.validateOpts(t||{}),void 0!==(s=this.msToNext(t.previous)))return s>n&&(s=n),t.currentTimeout=setTimeout(function(){s!==n&&(t.previous=r._next(t.previous),t.paused||(t.maxRuns--,e())),r.schedule(t,e)},s),{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}}},"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=n:"function"==typeof define&&define.amd?define([],function(){return n}):a.Cron=n}).call(this); |
{ | ||
"name": "croner", | ||
"version": "1.1.23", | ||
"version": "1.1.24", | ||
"description": "Isomorphic JavaScript cron parser and scheduler.", | ||
@@ -13,5 +13,10 @@ "author": "Hexagon <github.com/hexagon>", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "npm run test:lint && npm run test:mocha", | ||
"test:mocha": "mocha", | ||
"test:lint": "eslint ./lib/croner.js", | ||
"test:lint:fix": "eslint --fix ./lib/croner.js" | ||
}, | ||
"main": "index.js", | ||
"type": "commonjs", | ||
"module": "index.mjs", | ||
"browser": "./lib/croner.min.js", | ||
@@ -33,4 +38,4 @@ "repository": { | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"eslint": "^7.32.0", | ||
"mocha": "*", | ||
@@ -37,0 +42,0 @@ "should": "*" |
# 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://api.codacy.com/project/badge/Grade/1322c32f48454df5b7e28ea641dd13e7)](https://www.codacy.com/app/robinnilsson/croner?utm_source=github.com&utm_medium=referral&utm_content=Hexagon/croner&utm_campaign=Badge_Grade) | ||
[![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&utm_medium=referral&utm_content=Hexagon/croner&utm_campaign=Badge_Grade) | ||
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://img.shields.io/badge/license-MIT-blue.svg) | ||
@@ -25,3 +25,3 @@ | ||
## Node.js (server) | ||
## Node.js or browser ESM (e.g. WebPack) | ||
@@ -58,3 +58,3 @@ ```npm install croner``` | ||
## Node.js | ||
## Node.js commonjs | ||
@@ -69,2 +69,13 @@ ```javascript | ||
## Node.js ESM, Browser ESM | ||
```javascript | ||
import { Cron } from 'croner'; | ||
Cron('* * * * * *', function () { | ||
console.log('This will run every second'); | ||
}); | ||
``` | ||
## Browser, stand-alone | ||
@@ -71,0 +82,0 @@ |
@@ -0,0 +0,0 @@ /* |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
45625
10
950
240
3