# grbl-gcode-parser

> Parse a gcode string into objects

Latest version **1.0.0** (published 2023-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install grbl-gcode-parser
pnpm add grbl-gcode-parser
yarn add grbl-gcode-parser
bun add grbl-gcode-parser
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-08-08 |
| First published | 2023-08-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | imivi |
| Maintainers | imivi |
| Keywords | g-code, gcode, parser, cnc |

## Links

- npm: https://www.npmjs.com/package/grbl-gcode-parser
- Repository: https://github.com/imivi/grbl-gcode-parser
- Homepage: https://github.com/imivi/grbl-gcode-parser#readme
- Issues: https://github.com/imivi/grbl-gcode-parser/issues
- npm.io page: https://npm.io/package/grbl-gcode-parser

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-08-08

## README

# GRBL G-Code Parser

[![NPM badge](https://github.com/imivi/grbl-gcode-parser/blob/main/docs/badge_npm.svg?raw=true)](https://www.npmjs.com/package/grbl-gcode-parser)

![GRBL G-Code Parser Banner](https://github.com/imivi/grbl-gcode-parser/blob/main/docs/banner.png?raw=true)

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**

```js
[
    { "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`

```js
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:

```js
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)
```

---
_Source: https://npm.io/package/grbl-gcode-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
