Skip to content

Commit

Permalink
Remove leading zero(s) for M codes like M01, M02, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Nov 15, 2017
1 parent 978b2f9 commit d21fff1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,15 @@ const parseLine = (() => {
continue;
}

let value = Number(argument);
if (Number.isNaN(value)) {
value = argument;
}

if (options.flatten) {
result.words.push(`${letter}${argument}`);
result.words.push(letter + value);
} else {
result.words.push([letter, Number(argument)]);
result.words.push([letter, value]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ describe('gcode-parser', () => {
'$H',
'F1000',
'(*** LAYER: 0 ***)',
'T5 M6',
'T5 M06',
'S200',
'(* SHAPE Nr: 0 *)',
'G0 X 180.327 Y 137.080',
'M3'
'M03'
].join('\n');
const expectedResults = [
'',
Expand Down

0 comments on commit d21fff1

Please sign in to comment.