grbl-gcode-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

GRBL G-Code Parser

NPM badge

GRBL G-Code Parser Banner

Parse G-Code strings into JS objects. Works in the browser. For example:

input

G90
G21
G17 G64 P0.001 M3 S3000
F127.0
G0 Z6.350
G0 X-16.922 Y-12.459

output

[
    { "type": "G90",  "params": {} },
    { "type": "G21",  "params": {} },
    { "type": "G17",  "params": {} },
    {
        "type": "G64",
        "params": {
            "P": 0.001
        }
    },
    {
        "type": "M3",
        "params": {
            "S": 3000
        }
    },
    {
        "type": "G0",
        "params": {
            "F": 127
        }
    },
    {
        "type": "G0",
        "params": {
            "Z": 6.35
        }
    },
    {
        "type": "G0",
        "params": {
            "X": -16.922,
            "Y": -12.459
        }
    },
]

How to use

npm install grbl-gcode-parser

import { parseGcode } from "grbl-gcode-parser"

const gcode = [
    "G90",
    "G21",
    "G17 G64 P0.001 M3 S3000",
]
const commands = parseGcode(gcode, options)

You can customize the output with a few options:

const options = {
    addImplicitMoves: true, // If a line has a missing G0 or G1, infer it from the previous lines
    flatten: true, // If true, the commands are returned as an array of objects. If false, parseGcode() will return an array of arrays (each line is an array of commands).
}
const commands = parseGcode(gcode, options)

Readme

Keywords

Package Sidebar

Install

npm i grbl-gcode-parser

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

17.7 kB

Total Files

6

Last publish

Collaborators

  • imivi