G-code parser for Node.js, current stable version 2.2.0. Maintained as part of the cncjs ecosystem. Provides synchronous and asynchronous parsing of G-code strings, lines, files, and streams. Key differentiators: supports line modes (original, stripped, compact) and flatten option for word representation. Used widely in CNC toolpath generation and visualization.
npm install gcode-parserNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a single line, async file parsing, and sync string parsing.
Use callback for results, and attach listeners for 'data' or 'end' if needed.
Correct: parser.parseLine('G0 X0', { flatten: true }); Incorrect: parser.parseLine('G0 X0', true);Access word[0] for letter and word[1] for value, or use flatten: true to get strings like 'G0'.
Use const parser = require('gcode-parser'); and run in Node.js CJS environment.Check for empty array before accessing elements: if (result.words.length > 0) { ... }Always provide a callback: parser.parseFile('file.nc', (err, result) => { ... });No dependency data recorded yet.