Skip to content

About

Dependency-free TypeScript and JavaScript library for 3D printer G-code analysis.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

G-code Seer

npm version License: MIT

G-code Seer is a dependency-free TypeScript and JavaScript library for 3D printer G-code analysis. Analyze motion, extrusion, heater targets and printer constraints from text or streaming files, with explicit diagnostics when information is incomplete.

Use it to build G-code inspection tools, check print jobs against printer profiles, or process large files without retaining the toolpath. It includes Bambu Lab and Prusa printer profiles and exports ESM with TypeScript declarations. The core performs no file or network I/O and works in Bun and modern browsers.

Install

bun add gcode-seer

The published package is available on npm.

Quick start

import { analyze } from "gcode-seer";

const report = analyze("G21\nG90\nM82\nG92 E0\nG1 X3 Y4 E1 F600", {
	initialPosition: { x: 0, y: 0, z: 0 }, // Supply only a known starting position.
});

console.log(report.distance.total); // 5 mm
console.log(report.maxAxisSpeed.x); // 6 mm/s
console.log(report.validity); // "valid"
console.log(report.complete); // true
console.log(report.diagnostics); // []

Save this as analyze.ts and run it with bun run analyze.ts. Position starts unknown unless established by the input or supplied explicitly. Output uses millimeters, seconds and Celsius.

Check printer limits

import { analyze, createPrinterProfile } from "gcode-seer";

const printer = createPrinterProfile("prusa-mk4s");
const report = analyze("M104 S291", { printer });

console.log(report.constraints); // "violated": exceeds the 290 °C hotend target limit.
console.log(report.diagnostics);

Choose a built-in profile and installed hardware from the printer catalog, or supply a custom printer profile.

Stream a file

import { analyzeStream } from "gcode-seer";

const report = await analyzeStream(Bun.file("part.gcode").stream(), {
	maxDiagnostics: 500,
});

console.log(report.distance.total);
console.log(report.complete);

analyzeStream accepts iterable or async iterable text and UTF-8 chunks. For an existing line reader, use GcodeAnalyzer.

Read metrics alongside complete and diagnostics: unsupported behavior can leave parts of a file unanalyzed. A passed constraint result applies to configured limits and modeled commands; it does not certify a print as safe. See report semantics and supported commands and limitations.

Documentation

Contributing

Bug reports, documentation improvements and pull requests are welcome. Use the Bun version pinned in .bun-version, then run bun install --frozen-lockfile and bun run check in your clone. See CONTRIBUTING.md for setup, tests and Conventional Commits, and the release guide for publishing.

Maintained by Andrew Lemons. Licensed under the MIT License.

About

Dependency-free TypeScript and JavaScript library for 3D printer G-code analysis.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages