Skip to content

Commit 2a0f6cf

Browse files
authored
feat: rename minimal to stripped in lineMode for better clarity (#8)
1 parent d406a1b commit 2a0f6cf

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ Type: `String`
105105
Default: `'original'`
106106

107107
The `lineMode` option specifies how the parsed line should be formatted. The following values are supported:
108-
- `'original'`: Keeps the line unchanged, including comments and whitespace. (Default)
109-
- `'minimal'`: Removes comments, trims leading and trailing whitespace, but preserves inner whitespace.
110-
- `'compact'`: Removes both comments and all whitespace.
108+
- `'original'`: Retains the line exactly as is, including comments and whitespace. (This is the default when `lineMode` is not specified.)
109+
- `'stripped'`: Removes comments, trims leading and trailing whitespace (spaces and tabs), but keeps the inner whitespace between code elements.
110+
- `'compact'`: Removes both comments and all whitespace characters.
111111

112112
Example usage:
113113

114114
```js
115115
parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'original' });
116116
// => { line: 'G0 X0 Y0 ; comment', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] }
117117

118-
parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'minimal' });
118+
parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'stripped' });
119119
// => { line: 'G0 X0 Y0', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] }
120120

121121
parser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'compact' });

src/__tests__/index.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ describe('Invalid G-code words', () => {
5252
});
5353
});
5454

55-
describe('Using the `lineMode` option', () => {
56-
it('should return the original line with comments and whitespace in original mode', () => {
55+
describe('The `lineMode` option', () => {
56+
it('should retain the line exactly as is, including comments and whitespace for `lineMode="original"`', () => {
5757
const line = 'M6 (tool change;) T1 ; comment';
5858
const result = parseLine(line, { lineMode: 'original' });
5959
expect(result.line).toBe('M6 (tool change;) T1 ; comment');
6060
expect(result.words).toEqual([['M', 6], ['T', 1]]);
6161
});
6262

63-
it('should return the line without comments but with whitespace in minimal mode', () => {
63+
it('should remove comments, trims leading and trailing whitespace (spaces and tabs), but keeps the inner whitespace between code elements for `lineMode="stripped"`', () => {
6464
const line = 'M6 (tool change;) T1 ; comment';
65-
const result = parseLine(line, { lineMode: 'minimal' });
65+
const result = parseLine(line, { lineMode: 'stripped' });
6666
expect(result.line).toBe('M6 T1');
6767
expect(result.words).toEqual([['M', 6], ['T', 1]]);
6868
});
6969

70-
it('should return the line without comments and whitespace in compact mode', () => {
70+
it('should remove both comments and all whitespace characters for `lineMode="compact"`', () => {
7171
const line = 'M6 (tool change;) T1 ; comment';
7272
const result = parseLine(line, { lineMode: 'compact' });
7373
expect(result.line).toBe('M6T1');

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ const parseLine = (() => {
103103
options.flatten = !!options?.flatten;
104104

105105
const validLineModes = [
106-
'original', // Keeps the line unchanged, including comments and whitespace. (Default)
107-
'minimal', // Removes comments, trims leading and trailing whitespace, but preserves inner whitespace.
108-
'compact', // Removes both comments and all whitespace.
106+
'original', // Retains the line exactly as is, including comments and whitespace. (This is the default when `lineMode` is not specified.)
107+
'stripped', // Removes comments, trims leading and trailing whitespace (spaces and tabs), but keeps the inner whitespace between code elements.
108+
'compact', // Removes both comments and all whitespace characters.
109109
];
110110
if (!validLineModes.includes(options?.lineMode)) {
111111
options.lineMode = validLineModes[0];
@@ -119,13 +119,13 @@ const parseLine = (() => {
119119
let ln; // Line number
120120
let cs; // Checksum
121121
const originalLine = line;
122-
const [minimalLine, comments] = stripComments(line);
123-
const compactLine = stripWhitespace(minimalLine);
122+
const [strippedLine, comments] = stripComments(line);
123+
const compactLine = stripWhitespace(strippedLine);
124124

125125
if (options.lineMode === 'compact') {
126126
result.line = compactLine;
127-
} else if (options.lineMode === 'minimal') {
128-
result.line = minimalLine;
127+
} else if (options.lineMode === 'stripped') {
128+
result.line = strippedLine;
129129
} else {
130130
result.line = originalLine;
131131
}

0 commit comments

Comments
 (0)