diff --git a/README.md b/README.md index e2cd9cd..15de1e8 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ Type: `String` Default: `'original'` The `lineMode` option specifies how the parsed line should be formatted. The following values are supported: -- `'original'`: Keeps the line unchanged, including comments and whitespace. (Default) -- `'minimal'`: Removes comments, trims leading and trailing whitespace, but preserves inner whitespace. -- `'compact'`: Removes both comments and all whitespace. +- `'original'`: Retains the line exactly as is, including comments and whitespace. (This is the default when `lineMode` is not specified.) +- `'stripped'`: Removes comments, trims leading and trailing whitespace (spaces and tabs), but keeps the inner whitespace between code elements. +- `'compact'`: Removes both comments and all whitespace characters. Example usage: @@ -115,7 +115,7 @@ Example usage: parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'original' }); // => { line: 'G0 X0 Y0 ; comment', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] } -parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'minimal' }); +parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'stripped' }); // => { line: 'G0 X0 Y0', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] } parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'compact' }); diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index 909c615..14ed1af 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -52,22 +52,22 @@ describe('Invalid G-code words', () => { }); }); -describe('Using the `lineMode` option', () => { - it('should return the original line with comments and whitespace in original mode', () => { +describe('The `lineMode` option', () => { + it('should retain the line exactly as is, including comments and whitespace for `lineMode="original"`', () => { const line = 'M6 (tool change;) T1 ; comment'; const result = parseLine(line, { lineMode: 'original' }); expect(result.line).toBe('M6 (tool change;) T1 ; comment'); expect(result.words).toEqual([['M', 6], ['T', 1]]); }); - it('should return the line without comments but with whitespace in minimal mode', () => { + it('should remove comments, trims leading and trailing whitespace (spaces and tabs), but keeps the inner whitespace between code elements for `lineMode="stripped"`', () => { const line = 'M6 (tool change;) T1 ; comment'; - const result = parseLine(line, { lineMode: 'minimal' }); + const result = parseLine(line, { lineMode: 'stripped' }); expect(result.line).toBe('M6 T1'); expect(result.words).toEqual([['M', 6], ['T', 1]]); }); - it('should return the line without comments and whitespace in compact mode', () => { + it('should remove both comments and all whitespace characters for `lineMode="compact"`', () => { const line = 'M6 (tool change;) T1 ; comment'; const result = parseLine(line, { lineMode: 'compact' }); expect(result.line).toBe('M6T1'); diff --git a/src/index.js b/src/index.js index 0100bf9..39ad352 100644 --- a/src/index.js +++ b/src/index.js @@ -103,9 +103,9 @@ const parseLine = (() => { options.flatten = !!options?.flatten; const validLineModes = [ - 'original', // Keeps the line unchanged, including comments and whitespace. (Default) - 'minimal', // Removes comments, trims leading and trailing whitespace, but preserves inner whitespace. - 'compact', // Removes both comments and all whitespace. + 'original', // Retains the line exactly as is, including comments and whitespace. (This is the default when `lineMode` is not specified.) + 'stripped', // Removes comments, trims leading and trailing whitespace (spaces and tabs), but keeps the inner whitespace between code elements. + 'compact', // Removes both comments and all whitespace characters. ]; if (!validLineModes.includes(options?.lineMode)) { options.lineMode = validLineModes[0]; @@ -119,13 +119,13 @@ const parseLine = (() => { let ln; // Line number let cs; // Checksum const originalLine = line; - const [minimalLine, comments] = stripComments(line); - const compactLine = stripWhitespace(minimalLine); + const [strippedLine, comments] = stripComments(line); + const compactLine = stripWhitespace(strippedLine); if (options.lineMode === 'compact') { result.line = compactLine; - } else if (options.lineMode === 'minimal') { - result.line = minimalLine; + } else if (options.lineMode === 'stripped') { + result.line = strippedLine; } else { result.line = originalLine; }