cron-converter
Advanced tools
Comparing version 1.0.1 to 1.0.2
The MIT License (MIT) | ||
Copyright (c) 2015-2016 Rouslan Placella (https://github.com/roccivic) | ||
Copyright (c) 2015-2021 Rouslan Placella (https://github.com/roccivic) | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "cron-converter", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Cron string converter", | ||
@@ -5,0 +5,0 @@ "main": "src/cron.js", |
@@ -87,37 +87,37 @@ 'use strict'; | ||
Part.prototype.fromString = function(str) { | ||
var unit = this.unit; | ||
var stringParts = str.split('/'); | ||
if (stringParts.length > 2) { | ||
this.throw('Invalid value "%s"', str); | ||
} | ||
var rangeString = this.replaceAlternatives(stringParts[0]); | ||
var parsedValues; | ||
if (rangeString === '*') { | ||
parsedValues = util.range(unit.min, unit.max); | ||
} else { | ||
parsedValues = util.sort( | ||
util.dedup( | ||
this.fixSunday( | ||
util.flatten( | ||
rangeString.split(',').map( | ||
function(range) { | ||
return this.parseRange(range, str); | ||
}, | ||
this | ||
) | ||
) | ||
var values = util.sort( | ||
util.dedup( | ||
this.fixSunday( | ||
util.flatten( | ||
this.replaceAlternatives(str) | ||
.split(',') | ||
.map(function(value) { | ||
var valueParts = value.split('/'); | ||
if (valueParts.length > 2) { | ||
this.throw('Invalid value "%s"', str); | ||
} | ||
var parsedValues; | ||
var left = valueParts[0]; | ||
var right = valueParts[1]; | ||
if (left === '*') { | ||
parsedValues = util.range(this.unit.min, this.unit.max); | ||
} else { | ||
parsedValues = this.parseRange(left, str); | ||
} | ||
var step = this.parseStep(right); | ||
var intervalValues = this.applyInterval(parsedValues, step); | ||
if (!intervalValues.length) { | ||
this.throw('Empty interval value "%s"', str); | ||
} | ||
return intervalValues; | ||
}, this) | ||
) | ||
) | ||
); | ||
var value = this.outOfRange(parsedValues); | ||
if (typeof value !== 'undefined') { | ||
this.throw('Value "%s" out of range', value); | ||
} | ||
) | ||
); | ||
var value = this.outOfRange(values); | ||
if (typeof value !== 'undefined') { | ||
this.throw('Value "%s" out of range', value); | ||
} | ||
var step = this.parseStep(stringParts[1]); | ||
var intervalValues = this.applyInterval(parsedValues, step); | ||
if (!intervalValues.length) { | ||
this.throw('Empty interval value "%s"', str); | ||
} | ||
this.values = intervalValues; | ||
this.values = values; | ||
}; | ||
@@ -124,0 +124,0 @@ |
@@ -50,2 +50,10 @@ 'use strict'; | ||
out: '*/5 0,5 * * *' | ||
}, | ||
{ | ||
in: '* 2-10,19-23/2 * * *', | ||
out: '* 2-10,19,21,23 * * *' | ||
}, | ||
{ | ||
in: '* 2-6/2,19-23/2 * * *', | ||
out: '* 2,4,6,19,21,23 * * *' | ||
} | ||
@@ -52,0 +60,0 @@ ]; |
@@ -96,4 +96,4 @@ 'use strict'; | ||
input: '5-20,35-45/5', | ||
arr: [5,10,15,20,35,40,45], | ||
output: '5,10,15,20,35,40,45', | ||
arr: [5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,35,40,45], | ||
output: '5-20,35,40,45', | ||
min: 0, | ||
@@ -100,0 +100,0 @@ max: 59 |
45008
1647