{"id":19069568,"url":"https://github.com/cncjs/gcode-parser","last_synced_at":"2025-04-15T10:29:32.199Z","repository":{"id":57245475,"uuid":"47326347","full_name":"cncjs/gcode-parser","owner":"cncjs","description":"G-code Parser","archived":false,"fork":false,"pushed_at":"2024-12-08T13:08:10.000Z","size":166,"stargazers_count":72,"open_issues_count":1,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-11T02:07:20.216Z","etag":null,"topics":["gcode","gcode-parser"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cncjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-03T10:57:51.000Z","updated_at":"2025-03-01T12:14:10.000Z","dependencies_parsed_at":"2022-09-01T04:20:32.156Z","dependency_job_id":null,"html_url":"https://github.com/cncjs/gcode-parser","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cncjs","download_url":"https://codeload.github.com/cncjs/gcode-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249051238,"owners_count":21204779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gcode","gcode-parser"],"created_at":"2024-11-09T01:14:47.646Z","updated_at":"2025-04-15T10:29:32.189Z","avatar_url":"https://github.com/cncjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcode-parser [![codecov](https://codecov.io/gh/cncjs/gcode-parser/graph/badge.svg?token=T1D2XQJRXC)](https://codecov.io/gh/cncjs/gcode-parser)\n\n[![NPM](https://nodei.co/npm/gcode-parser.png?downloads=true\u0026stars=true)](https://www.npmjs.com/package/gcode-parser)\n\n## Install\n\n`npm install --save gcode-parser`\n\n## Usage\n```js\nvar fs = require('fs');\nvar parser = require('gcode-parser');\n\n// parseLine\nparser.parseLine('G0 X0 Y0');\n// =\u003e { line: 'G0 X0 Y0', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] }\n\n// parseLine (flatten mode)\nparser.parseLine('G0 X0 Y0', { flatten: true });\n// =\u003e { line: 'G0 X0 Y0', words: [ 'G0', 'X0', 'Y0' ] }\n\n// parseFile\nvar file = 'example.nc';\nparser.parseFile(file, function(err, results) {\n    console.log(results);\n});\n\n// Synchronous version of parseFile.\nresults = parser.parseFileSync(file);\n\n// parseStream\nvar stream = fs.createReadStream(file, { encoding: 'utf8' });\nparser.parseStream(stream, function(err, results) {\n    console.log(results);\n});\n\n// parseString\nvar str = fs.readFileSync(file, 'utf8');\nparser.parseString(str, function(err, results) {\n    console.log(results);\n});\n\n// Synchronous version of parseString.\nresults = parser.parseStringSync(file);\n```\n\n## Advanced Usage\n```js\nvar _ = require('lodash');\nvar parser = require('gcode-parser');\n\nparser.parseFile('example.nc', function(err, results) {\n    if (err) {\n        console.error(err);\n        return;\n    }\n\n    // Compose G-code\n    var list = _(results)\n        .map('words')\n        .map(function(words) {\n            return _.map(words, function(word) {\n                return word[0] + word[1];\n            }).join(' ');\n        })\n        .value();\n\n    console.log(list);\n})\n.on('data', function(data) {\n    console.log(data);\n})\n.on('end', function(results) {\n    console.log(results);\n})\n```\n\n## Options\n\n### batchSize\n\nType: `Number`\nDefault: 1000\n\nThe batch size.\n\n### flatten\n\nType: `Boolean`\nDefault: `false`\n\nTrue to flatten the array, false otherwise.\n\n```js\nparser.parseLine('G0 X0 Y0');\n// =\u003e { line: 'G0 X0 Y0', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] }\n\nparser.parseLine('G0 X0 Y0', { flatten: true });\n// =\u003e { line: 'G0 X0 Y0', words: [ 'G0', 'X0', 'Y0' ] }\n```\n\n### lineMode\n\nType: `String`  \nDefault: `'original'`\n\nThe `lineMode` option specifies how the parsed line should be formatted. The following values are supported:\n- `'original'`: Retains the line exactly as is, including comments and whitespace. (This is the default when `lineMode` is not specified.)\n- `'stripped'`: Removes comments, trims leading and trailing whitespace (spaces and tabs), but keeps the inner whitespace between code elements.\n- `'compact'`: Removes both comments and all whitespace characters.\n\nExample usage:\n\n```js\nparser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'original' });\n// =\u003e { line: 'G0 X0 Y0 ; comment', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] }\n\nparser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'stripped' });\n// =\u003e { line: 'G0 X0 Y0', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] }\n\nparser.parseLine('G0 X0 Y0 ; comment', { lineMode: 'compact' });\n// =\u003e { line: 'G0X0Y0', words: [ [ 'G', 0 ], [ 'X', 0 ], [ 'Y', 0 ] ] }\n```\n\n## G-code Interpreter\nhttps://github.com/cncjs/gcode-interpreter\n\n## G-code Toolpath\nhttps://github.com/cncjs/gcode-toolpath\n\n## G-code Toolpath Visualizer\nCheck out the source code at https://github.com/cncjs/cncjs/blob/master/src/web/widgets/Visualizer/GCodeVisualizer.js\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcncjs%2Fgcode-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcncjs%2Fgcode-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcncjs%2Fgcode-parser/lists"}