diff --git a/src/convert-expression/step-values-conversion.js b/src/convert-expression/step-values-conversion.js index e85218a..01b13ab 100644 --- a/src/convert-expression/step-values-conversion.js +++ b/src/convert-expression/step-values-conversion.js @@ -2,16 +2,20 @@ module.exports = (() => { function convertSteps(expressions){ - const stepValuePattern = /^(.+)\/(\d+)$/; - for(let i = 0; i < expressions.length; i++){ - const match = stepValuePattern.exec(expressions[i]); - const isStepValue = match !== null && match.length > 0; + var stepValuePattern = /^(.+)\/(\w+)$/; + for(var i = 0; i < expressions.length; i++){ + var match = stepValuePattern.exec(expressions[i]); + var isStepValue = match !== null && match.length > 0; if(isStepValue){ - const values = match[1].split(','); - const stepValues = []; - const divider = parseInt(match[2], 10); - for(let j = 0; j <= values.length; j++){ - const value = parseInt(values[j], 10); + var baseDivider = match[2]; + if(isNaN(baseDivider)){ + throw baseDivider + ' is not a valid step value'; + } + var values = match[1].split(','); + var stepValues = []; + var divider = parseInt(baseDivider, 10); + for(var j = 0; j <= values.length; j++){ + var value = parseInt(values[j], 10); if(value % divider === 0){ stepValues.push(value); } diff --git a/test/convert-expression/step-values-conversion-test.js b/test/convert-expression/step-values-conversion-test.js index dde2377..9221d96 100644 --- a/test/convert-expression/step-values-conversion-test.js +++ b/test/convert-expression/step-values-conversion-test.js @@ -4,10 +4,16 @@ const { expect } = require('chai'); const conversion = require('../../src/convert-expression/step-values-conversion'); describe('step-values-conversion.js', () => { - it('shuld convert step values', () => { - let expressions = '1,2,3,4,5,6,7,8,9,10/2 0,1,2,3,4,5,6,7,8,9/5 * * * *'.split(' '); + it('should convert step values', () => { + var expressions = '1,2,3,4,5,6,7,8,9,10/2 0,1,2,3,4,5,6,7,8,9/5 * * * *'.split(' '); expressions = conversion(expressions); expect(expressions[0]).to.equal('2,4,6,8,10'); expect(expressions[1]).to.equal('0,5'); }); + + it('should throw an error if step value is not a number', () => { + var expressions = '1,2,3,4,5,6,7,8,9,10/someString 0,1,2,3,4,5,6,7,8,9/5 * * * *'.split(' '); + expect(() => conversion(expressions)).to.throw('someString is not a valid step value'); + }); + });