{"id":19069567,"url":"https://github.com/cncjs/gcode-interpreter","last_synced_at":"2025-04-28T14:11:12.883Z","repository":{"id":57245434,"uuid":"47560935","full_name":"cncjs/gcode-interpreter","owner":"cncjs","description":"G-code Interpreter","archived":false,"fork":false,"pushed_at":"2024-11-17T14:48:57.000Z","size":132,"stargazers_count":40,"open_issues_count":0,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-18T16:31:32.317Z","etag":null,"topics":["gcode","gcode-interpreter"],"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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-12-07T15:31:49.000Z","updated_at":"2025-03-01T18:57:05.000Z","dependencies_parsed_at":"2025-04-18T04:57:36.736Z","dependency_job_id":null,"html_url":"https://github.com/cncjs/gcode-interpreter","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-interpreter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-interpreter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-interpreter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cncjs%2Fgcode-interpreter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cncjs","download_url":"https://codeload.github.com/cncjs/gcode-interpreter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251326849,"owners_count":21571636,"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-interpreter"],"created_at":"2024-11-09T01:14:47.601Z","updated_at":"2025-04-28T14:11:12.860Z","avatar_url":"https://github.com/cncjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcode-interpreter [![codecov](https://codecov.io/gh/cncjs/gcode-interpreter/graph/badge.svg?token=F8Z89O65FJ)](https://codecov.io/gh/cncjs/gcode-interpreter)\n\n[![NPM](https://nodei.co/npm/gcode-interpreter.png?downloads=true\u0026stars=true)](https://www.npmjs.com/package/gcode-interpreter)\n\n## Install\n\n`npm install --save gcode-interpreter`\n\n## Usage\n\n```js\nconst Interpreter = require('gcode-interpreter');\n\nconst Runner = function() {\n    const handlers = {\n        'G0': (params) =\u003e {\n            console.log('G0', params);\n        },\n        'G1': (params) =\u003e {\n            console.log('G1', params);\n        }\n    };\n\n    return new Interpreter({\n        handlers: handlers,\n        defaultHandler: (cmd, params) =\u003e {\n        }\n    });\n};\n\nconst runner = new Runner()\nconst file = 'example.nc';\nconst stream = fs.createReadStream(file, { encoding: 'utf8' });\nconst content = fs.readFileSync(file, 'utf8');\n\n// Load G-code from stream\nrunner.loadFromStream(stream, function(err, data) {\n});\n\n// loadFromFile\nrunner.loadFromFile(file, function(err, data) {\n});\n\n// Synchronous version of loadFromFile\nrunner.loadFromFileSync(file);\n\n// loadFromString\nconst content = fs.readFileSync(file, 'utf8');\nrunner.loadFromString(content, function(err, data) {\n});\n\n// Synchronous version of loadFromString\nrunner.loadFromStringSync(content);\n```\n\n## Examples\n\nRun this example with babel-node:\n```js\nimport Interpreter from 'gcode-interpreter';\n\nconst GCODE = [\n    'N1 G17 G20 G90 G94 G54',\n    'N2 G0 Z0.25',\n    'N3 X-0.5 Y0.',\n    'N4 Z0.1',\n    'N5 G01 Z0. F5.',\n    'N6 G02 X0. Y0.5 I0.5 J0. F2.5',\n    'N7 X0.5 Y0. I0. J-0.5',\n    'N8 X0. Y-0.5 I-0.5 J0.',\n    'N9 X-0.5 Y0. I0. J0.5',\n    'N10 G01 Z0.1 F5.',\n    'N11 G00 X0. Y0. Z0.25'\n].join('\\n');\n\nclass Toolpath {\n    handlers = {\n        'G0': (params) =\u003e {\n            console.log('G0', params);\n        },\n        'G1': (params) =\u003e {\n            console.log('G1', params);\n        },\n        'G2': (params) =\u003e {\n            console.log('G2', params);\n        },\n        'G17': (params) =\u003e {\n            console.log('G17');\n        },\n        'G20': (params) =\u003e {\n            console.log('G20');\n        },\n        'G90': (params) =\u003e {\n            console.log('G90');\n        },\n        'G94': (params) =\u003e {\n            console.log('G94');\n        },\n        'G54': (params) =\u003e {\n            console.log('G54');\n        }\n    };\n\n    constructor(options) {\n        options = options || {};\n\n        return new Interpreter({\n            handlers: this.handlers,\n            defaultHandler: (cmd, params) =\u003e {\n            }\n        });\n    }\n}\n\nconst toolpath = new Toolpath();\n\ntoolpath\n    .loadFromString(GCODE, (err, results) =\u003e {\n        if (err) {\n            console.error(err);\n            return;\n        }\n    })\n    .on('data', (data) =\u003e {\n        // 'data' event listener\n    })\n    .on('end', (results) =\u003e {\n        // 'end' event listener\n    });\n```\n\nand you will see the output as below:\n```\nG17\nG20\nG90\nG94\nG54\nG0 { Z: 0.25 }\nG0 { X: -0.5, Y: 0 }\nG0 { Z: 0.1 }\nG1 { Z: 0, F: 5 }\nG2 { X: 0, Y: 0.5, I: 0.5, J: 0, F: 2.5 }\nG2 { X: 0.5, Y: 0, I: 0, J: -0.5 }\nG2 { X: 0, Y: -0.5, I: -0.5, J: 0 }\nG2 { X: -0.5, Y: 0, I: 0, J: 0.5 }\nG1 { Z: 0.1, F: 5 }\nG0 { X: 0, Y: 0, Z: 0.25 }\n```\n\n## G-code Toolpath\nhttps://github.com/cncjs/gcode-toolpath\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcncjs%2Fgcode-interpreter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcncjs%2Fgcode-interpreter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcncjs%2Fgcode-interpreter/lists"}