Skip to content

Commit

Permalink
Merge pull request #104 from merencia/node8
Browse files Browse the repository at this point in the history
Update to Node v6.9.0 (LTS)
  • Loading branch information
merencia committed Sep 10, 2018
2 parents e573dc6 + 3efb712 commit f48f8d0
Show file tree
Hide file tree
Showing 47 changed files with 530 additions and 526 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
@@ -1,4 +1,5 @@
{
"esversion": 6,
"node": true,
"bitwise": true,
"curly": true,
Expand All @@ -11,7 +12,7 @@
"maxcomplexity": 8,
"maxparams": 4,
"nonbsp": true,
"nonew": true,
"nonew": false,
"quotmark": "single",
"shadow": false,
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
language: node_js
node_js:
- stable
- "8"
before_script:
- export TZ=America/Sao_Paulo
- echo '$TZ' | sudo tee /etc/timezone
Expand Down
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -26,7 +26,7 @@ Import node-cron and schedule a task:
```javascript
var cron = require('node-cron');

cron.schedule('* * * * *', function(){
cron.schedule('* * * * *', () => {
console.log('running a task every minute');
});
```
Expand Down Expand Up @@ -68,7 +68,7 @@ You may use multiples values separated by comma:
```javascript
var cron = require('node-cron');

cron.schedule('1,2,4,5 * * * *', function(){
cron.schedule('1,2,4,5 * * * *', () => {
console.log('running every minute 1, 2, 4 and 5');
});
```
Expand All @@ -80,7 +80,7 @@ You may also define a range of values:
```javascript
var cron = require('node-cron');

cron.schedule('1-5 * * * *', function(){
cron.schedule('1-5 * * * *', () => {
console.log('running every minute to 1 from 5');
});
```
Expand All @@ -92,7 +92,7 @@ Step values can be used in conjunction with ranges, following a range with '/' a
```javascript
var cron = require('node-cron');

cron.schedule('*/2 * * * *', function(){
cron.schedule('*/2 * * * *', () => {
console.log('running a task every two minutes');
});
```
Expand All @@ -104,7 +104,7 @@ For month and week day you also may use names or short names. e.g:
```javascript
var cron = require('node-cron');

cron.schedule('* * * January,September Sunday', function(){
cron.schedule('* * * January,September Sunday', () => {
console.log('running on Sundays of January and September');
});
```
Expand All @@ -114,7 +114,7 @@ Or with short names:
```javascript
var cron = require('node-cron');

cron.schedule('* * * Jan,Sep Sun', function(){
cron.schedule('* * * Jan,Sep Sun', () => {
console.log('running on Sundays of January and September');
});
```
Expand All @@ -140,7 +140,7 @@ Starts the scheduled task.
```javascript
var cron = require('node-cron');

var task = cron.schedule('* * * * *', function() {
var task = cron.schedule('* * * * *', () => {
console.log('immediately started');
}, false);

Expand All @@ -154,7 +154,7 @@ The task won't be executed unless re-started.
```javascript
var cron = require('node-cron');

var task = cron.schedule('* * * * *', function() {
var task = cron.schedule('* * * * *', () => {
console.log('will execute every minute until stopped');
});

Expand All @@ -168,7 +168,7 @@ The task will be stopped and completely destroyed.
```javascript
var cron = require('node-cron');

var task = cron.schedule('* * * * *', function() {
var task = cron.schedule('* * * * *', () => {
console.log('will not execute anymore, nor be able to restart');
});

Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -12,6 +12,9 @@
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"check": "npm run coverage && npm run coveralls"
},
"engines" : {
"node" : ">=6.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/merencia/node-cron.git"
Expand Down
4 changes: 2 additions & 2 deletions src/convert-expression/asterisk-to-range-conversion.js
@@ -1,5 +1,5 @@
'use strict';
module.exports = (function() {
module.exports = (() => {
function convertAsterisk(expression, replecement){
if(expression.indexOf('*') !== -1){
return expression.replace('*', replecement);
Expand All @@ -18,4 +18,4 @@ module.exports = (function() {
}

return convertAsterisksToRanges;
}());
})();
4 changes: 2 additions & 2 deletions src/convert-expression/index.js
Expand Up @@ -6,7 +6,7 @@ var convertAsterisksToRanges = require('./asterisk-to-range-conversion');
var convertRanges = require('./range-conversion');
var convertSteps = require('./step-values-conversion');

module.exports = (function() {
module.exports = (() => {

function appendSeccondExpression(expressions){
if(expressions.length === 5){
Expand Down Expand Up @@ -49,4 +49,4 @@ module.exports = (function() {
}

return interprete;
}());
})();
4 changes: 2 additions & 2 deletions src/convert-expression/month-names-conversion.js
@@ -1,5 +1,5 @@
'use strict';
module.exports = (function() {
module.exports = (() => {
var months = ['january','february','march','april','may','june','july',
'august','september','october','november','december'];
var shortMonths = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
Expand All @@ -19,4 +19,4 @@ module.exports = (function() {
}

return interprete;
}());
})();
4 changes: 2 additions & 2 deletions src/convert-expression/range-conversion.js
@@ -1,5 +1,5 @@
'use strict';
module.exports = (function() {
module.exports = ( () => {
function replaceWithRange(expression, text, init, end) {

var numbers = [];
Expand Down Expand Up @@ -36,7 +36,7 @@ module.exports = (function() {
}

return convertAllRanges;
}());
})();



4 changes: 2 additions & 2 deletions src/convert-expression/step-values-conversion.js
@@ -1,6 +1,6 @@
'use strict';

module.exports = (function() {
module.exports = (() => {
function convertSteps(expressions){
var stepValuePattern = /^(.+)\/(\d+)$/;
for(var i = 0; i < expressions.length; i++){
Expand All @@ -23,5 +23,5 @@ module.exports = (function() {
}

return convertSteps;
}());
})();

16 changes: 8 additions & 8 deletions src/convert-expression/week-day-names-conversion.js
@@ -1,21 +1,21 @@
'use strict';
module.exports = (function() {
module.exports = (() => {
var weekDays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
'friday', 'saturday'];
var shortWeekDays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];

function convertWeekDays(expression){
expression = expression.replace('7', '0');
expression = convertWeekDayName(expression, weekDays);
return convertWeekDayName(expression, shortWeekDays);
}

function convertWeekDayName(expression, items){
for(var i = 0; i < items.length; i++){
expression = expression.replace(new RegExp(items[i], 'gi'), parseInt(i, 10));
}
return expression;
}

function convertWeekDays(expression){
expression = expression.replace('7', '0');
expression = convertWeekDayName(expression, weekDays);
return convertWeekDayName(expression, shortWeekDays);
}

return convertWeekDays;
}());
})();
4 changes: 2 additions & 2 deletions src/node-cron.js
Expand Up @@ -4,7 +4,7 @@ var Task = require('./task'),
ScheduledTask = require('./scheduled-task'),
validation = require('./pattern-validation');

module.exports = (function() {
module.exports = (() => {

/**
* Creates a new task to execute given function when the cron
Expand Down Expand Up @@ -48,4 +48,4 @@ module.exports = (function() {
schedule: createTask,
validate: validate
};
}());
})();
35 changes: 20 additions & 15 deletions src/pattern-validation.js
Expand Up @@ -2,7 +2,8 @@

var convertExpression = require('./convert-expression');

module.exports = ( function(){

module.exports = ( () => {
function isValidExpression(expression, min, max){
var options = expression.split(',');
var regexValidation = /^\d+$|^\*$|^\*\/\d+$/;
Expand Down Expand Up @@ -40,19 +41,7 @@ module.exports = ( function(){
return !isValidExpression(expression, 0, 7);
}

function validate(pattern){
if (typeof pattern !== 'string'){
throw 'pattern must be a string!';
}

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

if(patterns.length === 5){
patterns = ['0'].concat(patterns);
}

function validateFields(patterns, executablePatterns){
if (isInvalidSecond(executablePatterns[0])) {
throw patterns[0] + ' is a invalid expression for second';
}
Expand All @@ -78,5 +67,21 @@ module.exports = ( function(){
}
}

function validate(pattern){
if (typeof pattern !== 'string'){
throw 'pattern must be a string!';
}

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

if(patterns.length === 5){
patterns = ['0'].concat(patterns);
}

validateFields(patterns, executablePatterns);
}

return validate;
}());
})();

0 comments on commit f48f8d0

Please sign in to comment.