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

node-cron

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-cron - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

src/convert-expression/asterisk-to-range-conversion.js

2

LICENSE.md

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

## ISC License
Copyright (c) 2016, Lucas Merencia \<lucas.merencia@gmail.com\>

@@ -2,0 +4,0 @@

8

package.json
{
"name": "node-cron",
"version": "1.1.1",
"version": "1.1.2",
"description": "A simple cron-like task scheduler for Node.js",

@@ -10,4 +10,4 @@ "author": "Lucas Merencia",

"scripts": {
"test": "mocha -t 20000",
"coverage": "istanbul cover _mocha -- -t 2000000",
"test": "./node_modules/mocha/bin/mocha --recursive",
"coverage": "istanbul cover _mocha -- --recursive",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",

@@ -34,5 +34,5 @@ "check": "npm run coverage && npm run coveralls"

"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"mocha": "^3.0.2",
"sinon": "^1.17.3"
}
}

@@ -11,3 +11,3 @@ # Node Cron

The node-cron module is tiny task scheduler in pure JavaScrip for node.js based on [GNU crontab](https://www.gnu.org/software/mcron/manual/html_node/Crontab-file.html). This module allows you to schedule task in node.js using full crontab syntax.
The node-cron module is tiny task scheduler in pure JavaScript for node.js based on [GNU crontab](https://www.gnu.org/software/mcron/manual/html_node/Crontab-file.html). This module allows you to schedule task in node.js using full crontab syntax.

@@ -14,0 +14,0 @@

'use strict';
var interprete = require('./pattern-interpreter');
var convertExpression = require('./convert-expression');
module.exports = ( function(){
function removeStepValue(expression){
var multiplePattern = /^((\d+(\,\d+){0,})|\*)\/(\d+)$/g;
var match = multiplePattern.exec(expression);
if(match !== null && match.length > 0 ) {
expression = match[1];
}
return expression;
}
function isValidExpression(expression, min, max){
expression = removeStepValue(expression);
var options = expression.split(',');

@@ -56,3 +45,3 @@ var regexValidation = /^\d+$|^\*$|^\*\/\d+$/;

var patterns = pattern.split(' ');
var executablePattern = interprete(pattern);
var executablePattern = convertExpression(pattern);
var executablePatterns = executablePattern.split(' ');

@@ -62,3 +51,2 @@

patterns = ['0'].concat(patterns);
executablePatterns = ['0'].concat(executablePatterns);
}

@@ -65,0 +53,0 @@

'use strict';
var interpretPattern = require('./pattern-interpreter');
var convertExpression = require('./convert-expression');
var validatePattern = require('./pattern-validation');

@@ -8,20 +8,6 @@

function matchPattern(pattern, value){
var stepValuePattern = /^((\d+(\,\d+){0,})|\*)\/(\d+)$/g;
var match = stepValuePattern.exec(pattern);
var isStepValue = match !== null && match.length > 0;
if (pattern === '*') {
return true;
}
if (isStepValue) {
var values = match[1].split(',');
if(values[0] === '*' || values.indexOf(value.toString()) !== -1) {
return value % parseInt(match[4], 10) === 0;
}
}
else if( pattern.indexOf(',') !== -1 ){
if( pattern.indexOf(',') !== -1 ){
var patterns = pattern.split(',');
return patterns.indexOf(value.toString()) !== -1;
}
return pattern === value.toString();

@@ -36,7 +22,3 @@ }

var runOnMonth = matchPattern(task.expressions[4], date.getMonth() + 1);
var weekDay = date.getDay();
if (weekDay === 0 ) {
weekDay = 7;
}
var runOnDayOfWeek = matchPattern(task.expressions[5], weekDay);
var runOnDayOfWeek = matchPattern(task.expressions[5], date.getDay());
return runInSecond && runOnMinute && runOnHour && runOnDayOfMonth &&

@@ -48,8 +30,5 @@ runOnMonth && runOnDayOfWeek;

validatePattern(pattern);
this.pattern = interpretPattern(pattern);
this.pattern = convertExpression(pattern);
this.execution = execution;
this.expressions = this.pattern.split(' ');
if (this.expressions.length === 5 ){
this.expressions = [ '0' ].concat(this.expressions);
}
}

@@ -56,0 +35,0 @@

@@ -71,4 +71,21 @@ 'use strict';

});
it('should run every hour on range', function(){
var task = new Task('* 8-20 * * *', function(){
this.executed += 1;
});
task.executed = 0;
var date = new Date(2016, 1, 1);
date.setHours(0);
task.update(date);
date.setHours(8);
task.update(date);
date.setHours(19);
task.update(date);
date.setHours(21);
task.update(date);
expect(2).to.equal(task.executed);
});
});
});

@@ -18,3 +18,3 @@ 'use strict';

expect(function(){
validate('* * 15 * *');
validate('0 * * 15 * *');
}).to.not.throwException();

@@ -21,0 +21,0 @@ });

@@ -33,3 +33,9 @@ 'use strict';

});
it('should accept range for hours', function(){
expect(function(){
validate('* 3-20 * * *');
}).to.not.throwException();
});
});
});
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