Skip to content

Commit 0bd09e0

Browse files
committed
Number conversions
1 parent a4705be commit 0bd09e0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ function run()
88
console.log(`VERSION: ${version}`);
99
console.log(`INCREMENT_POSITION: ${position}`);
1010

11-
const versionRegex = /^\d+(\.\d+){0,3}$/;
12-
13-
if (!versionRegex.test(version))
11+
if (!/^\d+(\.\d+){0,3}$/.test(version))
1412
throw new Error(`Invalid version provided: ${version}`);
13+
14+
if (position && !/^\d$/.test(position))
15+
throw new Error(`Invalid position provided: ${position}`);
1516

1617
let positionToIncrement = 2;
1718

1819
if (position)
19-
positionToIncrement = position - 1;
20+
positionToIncrement = Number(position) - 1;
2021

2122
const versionSplit = version.split('.');
2223

@@ -25,7 +26,7 @@ function run()
2526
if (position && position > versionSplit.length)
2627
throw new Error(`Invalid increment position specified. Position specified, ${position}, is outside the bounds of the specified version, ${version}.`);
2728

28-
versionSplit[positionToIncrement] = versionSplit[positionToIncrement] + 1;
29+
versionSplit[positionToIncrement] = Number(versionSplit[positionToIncrement]) + 1;
2930

3031
for (var i = positionToIncrement + 1; i < 4; i++){
3132
versionSplit[i] = 0;

0 commit comments

Comments
 (0)