Comparing version 1.1.2 to 1.1.3
@@ -0,0 +0,0 @@ { |
@@ -202,3 +202,3 @@ /* ------------------------------------------------------------------------------------ | ||
i, | ||
reValidCron = /[^0-9,-]+/, | ||
reValidCron = /[^\/\*0-9,-]+/, | ||
hasMonths, | ||
@@ -218,3 +218,3 @@ hasDaysOfWeek, | ||
// Check that part only contain legal characters ^[0-9-,]+$ | ||
if (part !== "*" && reValidCron.test(part)) { | ||
if (reValidCron.test(part)) { | ||
raise("configuration entry " + (i + 1) + " (" + part + ") contains illegal characters."); | ||
@@ -260,3 +260,4 @@ } | ||
lower, | ||
upper; | ||
upper, | ||
steps; | ||
@@ -272,2 +273,5 @@ // First off, handle wildcard | ||
// Then, handle steps | ||
if (conf.indexOf("/")) | ||
// Check if we need to split | ||
@@ -285,14 +289,5 @@ confParts = conf.split(","); | ||
// Didn"t need to recurse, determine if this is a range or a number | ||
if (conf.indexOf("-") === -1) { | ||
// Got a number | ||
index = (parseInt(conf, 10) + valueIndexOffset); | ||
// Didn"t need to recurse, determine if this is a range, steps or a number | ||
if (conf.indexOf("-") !== -1) { | ||
if (index < 0 || index >= arr.length) { | ||
raise(type + " value out of range: '" + conf + "'"); | ||
} | ||
arr[index] = 1; | ||
} else { | ||
// Got a range | ||
@@ -327,2 +322,44 @@ split = conf.split("-"); | ||
} | ||
} else if (conf.indexOf("/") !== -1) { | ||
// Got a step | ||
split = conf.split("/"); | ||
if (split.length !== 2) { | ||
raise("Syntax error, illegal stepping: '" + conf + "'"); | ||
} | ||
if (split[0] !== "*") { | ||
raise("Syntax error, left part of / needs to be * : '" + conf + "'"); | ||
} | ||
steps = parseInt(split[1], 10); | ||
if (isNaN(steps)) { | ||
raise("Syntax error, illegal stepping: (NaN)"); | ||
} | ||
if (steps == 0) { | ||
raise("Syntax error, illegal stepping: 0"); | ||
} | ||
if (steps > arr.length) { | ||
raise("Syntax error, steps cannot be greater than maximum value of part ("+arr.length+")") | ||
} | ||
for (x = 0; x < arr.length; x+= steps) { | ||
arr[(x + valueIndexOffset)] = 1; | ||
} | ||
} else { | ||
// Got a number | ||
index = (parseInt(conf, 10) + valueIndexOffset); | ||
if (index < 0 || index >= arr.length) { | ||
raise(type + " value out of range: '" + conf + "'"); | ||
} | ||
arr[index] = 1; | ||
} | ||
@@ -329,0 +366,0 @@ }; |
{ | ||
"name": "croner", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Isomorphic JavaScript cron parser and scheduler.", | ||
@@ -5,0 +5,0 @@ "author": "Hexagon <github.com/hexagon>", |
@@ -30,2 +30,18 @@ | ||
## Minimalist scheduling with stepping | ||
```javascript | ||
// Run a function each second | ||
Cron('*/5 * * * * *', function () { | ||
console.log('This will run every fifth second'); | ||
}); | ||
``` | ||
## Minimalist scheduling with range | ||
```javascript | ||
// Run a function each second | ||
Cron('0-4 * * * * *', function () { | ||
console.log('This will run the first five seconds every minute'); | ||
}); | ||
``` | ||
## Minimalist scheduling with options | ||
@@ -32,0 +48,0 @@ ```javascript |
@@ -80,2 +80,51 @@ /* | ||
it("Slash in pattern should not throw", function () { | ||
(function(){ | ||
var scheduler = new Cron("* */5 * * * *"); | ||
scheduler.next(); | ||
}).should.not.throw(); | ||
}); | ||
it("Slash in pattern without following number should throw", function () { | ||
(function(){ | ||
var scheduler = new Cron("* */ * * * *"); | ||
scheduler.next(); | ||
}).should.throw(); | ||
}); | ||
it("Slash in pattern with preceding number should throw", function () { | ||
(function(){ | ||
var scheduler = new Cron("* 1/5 * * * *"); | ||
scheduler.next(); | ||
}).should.throw(); | ||
}); | ||
it("Slash in pattern with wildcards both pre and post should throw", function () { | ||
(function(){ | ||
var scheduler = new Cron("* */* * * * *"); | ||
scheduler.next(); | ||
}).should.throw(); | ||
}); | ||
it("Slash in pattern with zero stepping should throw", function () { | ||
(function(){ | ||
var scheduler = new Cron("* */0 * * * *"); | ||
scheduler.next(); | ||
}).should.throw(); | ||
}); | ||
it("Slash in pattern with letter after should throw should throw", function () { | ||
(function(){ | ||
var scheduler = new Cron("* */a * * * *"); | ||
scheduler.next(); | ||
}).should.throw(); | ||
}); | ||
it("Slash in pattern with too high stepping should throw", function () { | ||
(function(){ | ||
var scheduler = new Cron("* */61 * * * *"); | ||
scheduler.next(); | ||
}).should.throw(); | ||
}); | ||
it("Missing lower range should throw", function () { | ||
@@ -306,3 +355,3 @@ (function(){ | ||
if(target.getTime() == scheduler.next().getTime()) { | ||
if(target.getTime() === scheduler.next().getTime()) { | ||
while(prevRun < target) { | ||
@@ -309,0 +358,0 @@ left = scheduler.msToNext(prevRun); |
@@ -305,3 +305,3 @@ /* | ||
if(target.getTime() == scheduler.next().getTime()) { | ||
if(target.getTime() === scheduler.next().getTime()) { | ||
while(prevRun < target) { | ||
@@ -308,0 +308,0 @@ left = scheduler.msToNext(prevRun); |
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
43712
975
154