🚀 Launch Week Day 3:Introducing Supply Chain Attack Campaigns Tracking.Learn More →
Socket
Book a DemoInstallSign in
Socket

gcode-parser

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gcode-parser

G-code parser for Node.js

npmnpm
Version
1.2.0
Version published
Weekly downloads
729
30.88%
Maintainers
1
Weekly downloads
 
Created
Source

gcode-parser build status Coverage Status

NPM

Install

npm install --save gcode-parser

Usage

var fs = require('fs');
var parser = require('gcode-parser');

// parseLine
var line = 'G0 X0 Y0';
var result = parser.parseLine(line);
console.log(result);

// parseFile
var file = 'example.nc';
parser.parseFile(file, function(err, results) {
    console.log(results);
});

// Synchronous version of parseFile.
results = parser.parseFileSync(file);

// parseStream
var stream = fs.createReadStream(file, { encoding: 'utf8' });
parser.parseStream(stream, function(err, results) {
    console.log(results);
});

// parseString
var str = fs.readFileSync(file, 'utf8');
parser.parseString(str, function(err, results) {
    console.log(results);
});

// Synchronous version of parseString.
results = parser.parseStringSync(file);

Advanced Usage

var _ = require('lodash');
var parser = require('gcode-parser');

parser.parseFile('example.nc', function(err, results) {
    if (err) {
        console.error(err);
        return;
    }

    // Compose G-code
    var list = _(results)
        .map('words')
        .map(function(words) {
            return _.map(words, function(word) {
                return word[0] + word[1];
            }).join(' ');
        })
        .value();

    console.log(list);
})
.on('data', function(data) {
    console.log(data);
})
.on('end', function(results) {
    console.log(results);
})

Options

batchSize

Type: Number Default: 1000

The batch size.

noParseLine

Type: Boolean Default: false

True to not parse line, false otherwise.

parser.parseFile('/path/to/file', { noParseLine: true }, function(err, results) {
});

G-code Interpreter

https://github.com/cncjs/gcode-interpreter

G-code Toolpath

https://github.com/cncjs/gcode-toolpath

G-code Toolpath Visualizer

Check out the source code at https://github.com/cncjs/cncjs/blob/master/src/web/widgets/Visualizer/GCodeVisualizer.js

Keywords

cnc

FAQs

Package last updated on 28 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts