npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

gerberts

v0.0.3

Published

Gerber file format parser and serializer for TypeScript

Readme

gerberts

NPM Package · View Online

A TypeScript Gerber file parser and serializer, also render Gerbers to SVG

Installation

bun add gerberts

Usage

Parsing a Gerber file

import { parseGerberFile, GerberFile } from "gerberts"

// Parse from string
const source = `%FSLAX26Y26*%
%MOMM*%
%ADD10C,0.1*%
D10*
X0Y0D03*
M02*`

const gerber = parseGerberFile(source)
// or: GerberFile.parse(source)

// Access parsed data
console.log(gerber.formatSpecification) // FormatSpecification { ... }
console.log(gerber.unitMode?.unit) // "MM"
console.log(gerber.apertureDefinitions) // [ApertureDefinition { code: 10, ... }]

Serializing back to text

const output = gerber.getString()
// Returns the Gerber file as a string

Building a Gerber file programmatically

import {
  GerberFile,
  GerberNode,
  FormatSpecification,
  UnitMode,
  ApertureDefinition,
  SelectAperture,
  Move,
  Interpolate,
  Flash,
} from "gerberts"

const gerber = new GerberFile()

gerber.addCommand(
  new FormatSpecification({
    xIntegerDigits: 2,
    xDecimalDigits: 6,
    yIntegerDigits: 2,
    yDecimalDigits: 6,
  })
)
gerber.addCommand(new UnitMode("MM"))
gerber.addCommand(
  new ApertureDefinition({
    code: 10,
    template: "C",
    params: [0.1],
  })
)
gerber.addCommand(new SelectAperture(10))
gerber.addCommand(new Move({ x: 0, y: 0 }))
gerber.addCommand(new Interpolate({ x: 1000000, y: 1000000 }))
gerber.ensureEndOfFile()

console.log(gerber.getString())

Adding commands from strings

You can add commands directly from Gerber command strings:

const gerber = new GerberFile()

// Add commands using raw Gerber syntax
gerber.addCommand("%FSLAX26Y26*%")
gerber.addCommand("%MOMM*%")
gerber.addCommand("%ADD10C,0.1*%")
gerber.addCommand("D10*")
gerber.addCommand("X0Y0D02*")
gerber.addCommand("X1000000Y1000000D01*")
gerber.addCommand("M02*")

// Or parse a command explicitly with GerberNode.parse
const flashCommand = GerberNode.parse("X500000Y500000D03*")
gerber.addCommand(flashCommand)

Rendering to SVG

Convert a parsed Gerber file into an SVG string for visualization:

import { parseGerberFile, renderGerberToSvg } from "gerberts"

const gerber = parseGerberFile(`%FSLAX26Y26*%
%MOMM*%
%ADD10C,0.1*%
D10*
X0Y0D03*
M02*`)

const svg = renderGerberToSvg(gerber, {
  strokeColor: "#0070f3",
  fillColor: "#111",
  backgroundColor: "#f5f5f5",
  scale: 2,
})

console.log(svg)

renderGerberToSvg accepts optional settings such as strokeColor, fillColor, backgroundColor, scale, and padding to tailor the output SVG.

API

Root Class

  • GerberFile - Root document class representing a complete Gerber file
    • GerberFile.parse(source) - Parse a Gerber file from text
    • gerber.getString() - Serialize back to Gerber format
    • gerber.commands - Array of all commands
    • gerber.formatSpecification - Get the format specification
    • gerber.unitMode - Get the unit mode
    • gerber.apertureDefinitions - Get all aperture definitions
    • gerber.fileAttributes - Get all file attributes (X2)
    • gerber.operations - Get all operations

Parse Functions

  • parseGerberFile(source) - Parse a Gerber file (alias for GerberFile.parse)
  • parseGerber(source) - Low-level parse returning array of nodes

Entity Classes

Configuration Commands:

  • FormatSpecification - Format specification (%FS)
  • UnitMode - Unit mode (%MO)
  • ApertureDefinition - Aperture definition (%AD)
  • ApertureMacro - Aperture macro (%AM)

State Commands:

  • LoadPolarity - Load polarity (%LP)
  • LoadMirroring - Load mirroring (%LM)
  • LoadRotation - Load rotation (%LR)
  • LoadScaling - Load scaling (%LS)
  • StepRepeat - Step and repeat (%SR)
  • SelectAperture - Select aperture (Dnn)
  • SetInterpolationMode - Set interpolation (G01/G02/G03)

Attribute Commands (X2):

  • FileAttribute - File attribute (%TF)
  • ApertureAttribute - Aperture attribute (%TA)
  • ObjectAttribute - Object attribute (%TO)
  • DeleteAttribute - Delete attribute (%TD)

Drawing Commands:

  • Interpolate - Draw/interpolate operation (D01)
  • Move - Move without drawing (D02)
  • Flash - Flash aperture at position (D03)
  • Operation - Base class for D-code operations
  • RegionStart - Start region (G36)
  • RegionEnd - End region (G37)

Other:

  • Comment - Comment (G04)
  • EndOfFile - End of file (M02)
  • UnknownCommand - Unrecognized commands (preserved for round-trip)

Development

# Install dependencies
bun install

# Run tests
bun test

# Type check
bun run typecheck

License

MIT