Comparing version 1.1.3 to 1.2.0
{ | ||
"name": "node-cron", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "A simple cron-like task scheduler for Node.js", | ||
@@ -5,0 +5,0 @@ "author": "Lucas Merencia", |
@@ -13,3 +13,5 @@ # Node Cron | ||
[![NPM](https://nodei.co/npm/node-cron.png?downloads=true&downloadRank=true&stars=false)](https://nodei.co/npm/node-cron/) | ||
## Getting Started | ||
@@ -177,2 +179,13 @@ | ||
### Validate | ||
Validate that the given string is a valid cron expression. | ||
```javascript | ||
var cron = require('node-cron'); | ||
var valid = cron.validate('59 * * * *'); | ||
var invalid = cron.validate('60 * * * *'); | ||
``` | ||
## Issues | ||
@@ -179,0 +192,0 @@ |
'use strict'; | ||
module.exports = (function() { | ||
function replaceWithRange(expression, text, init, end) { | ||
var numbers = []; | ||
var last = parseInt(end); | ||
for(var i = parseInt(init); i <= last; i++) { | ||
var first = parseInt(init); | ||
if(first > last){ | ||
last = parseInt(init); | ||
first = parseInt(end); | ||
} | ||
for(var i = first; i <= last; i++) { | ||
numbers.push(i); | ||
} | ||
return expression.replace(new RegExp(text, 'gi'), numbers.join()); | ||
@@ -10,0 +19,0 @@ } |
'use strict'; | ||
var Task = require('./task'), | ||
ScheduledTask = require('./scheduled-task'); | ||
ScheduledTask = require('./scheduled-task'), | ||
validation = require('./pattern-validation'); | ||
@@ -23,5 +24,16 @@ module.exports = (function() { | ||
function validate(expression) { | ||
try { | ||
validation(expression); | ||
} catch(e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
return { | ||
schedule: createTask | ||
schedule: createTask, | ||
validate: validate | ||
}; | ||
}()); |
@@ -47,3 +47,15 @@ 'use strict'; | ||
}); | ||
it('should not fail with Monday-Sunday for week day', function(){ | ||
expect(function(){ | ||
validate('* * * * Monday-Sunday'); | ||
}).to.not.throwException(); | ||
}); | ||
it('should not fail with 1-7 for week day', function(){ | ||
expect(function(){ | ||
validate('0 0 1 1 1-7'); | ||
}).to.not.throwException(); | ||
}); | ||
}); | ||
}); |
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
53490
49
1455
208