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

svg2gcode-wasm

v0.1.10

Published

WebAssembly (WASM) bindings for the Rust `svg2gcode` library. Convert SVG vector graphics into G-Code directly in browsers or Node.js.

Readme

svg2gcode-wasm

WebAssembly (WASM) bindings for the Rust svg2gcode library. Convert SVG vector graphics into G-Code directly in browsers or Node.js.

This fork adds some extra parameters I needed.

Install

npm install svg2gcode-wasm
# or
pnpm add svg2gcode-wasm
# or
yarn add svg2gcode-wasm

Usage (ESM / Bundlers)

import init, { convert_svg, param_schema_json } from 'svg2gcode-wasm';

// Ensure the WASM module is initialized (most bundlers handle the fetch automatically)
await init();

const svg = `<svg viewBox='0 0 10 10'><rect x='1' y='1' width='8' height='8' stroke='black' fill='none'/></svg>`;

const options = {
  tolerance: 0.002,
  feedrate: 300,
  dpi: 96,
  origin_x: 0,
  origin_y: 0,
  circular_interpolation: false,
  tool_on_sequence: null,
  tool_off_sequence: null,
  begin_sequence: null,
  end_sequence: null,
  between_layers_sequence: null,
  checksums: false,
  line_numbers: false,
  newline_before_comment: false,
  // New (dimension / alignment / trim) parameters:
  override_width: "210mm",   // optional length (px, mm, cm, in, etc.)
  override_height: "297mm",  // optional length
  h_align: "center",         // left | center | right (applies if override_* set or trim = true)
  v_align: "bottom",         // top | center | bottom
  trim: true                  // true = scale drawing bbox to fit inside override dims (preserve aspect)
};

const gcode = convert_svg(svg, options);
console.log(gcode);

// Discover option schema (JSON Schema for dynamic UIs)
console.log(param_schema_json());

API

convert_svg(svg: string, options: GCodeConversionOptions) -> string

Convert SVG markup to a G-Code program string. Throws a string (error message) on failure.

param_schema_json() -> string

Returns a JSON Schema describing the options structure.

Option Structure

The options object flattens three logical groups:

  • Conversion: tolerance, feedrate, dpi, origin_x, origin_y, extra_attribute_name
  • Machine: circular_interpolation, tool_on_sequence, tool_off_sequence, begin_sequence, end_sequence, between_layers_sequence
  • Postprocess: checksums, line_numbers, newline_before_comment

Additional layout fields (all optional except trim which defaults false):

| Field | Type | Description | |-------|------|-------------| | override_width | string | Target width with unit (e.g. 210mm, 8.5in, 100px). | | override_height | string | Target height with unit. | | h_align | "left"|"center"|"right" | Horizontal alignment within target box / viewport. | | v_align | "top"|"center"|"bottom" | Vertical alignment within target box / viewport. | | trim | boolean | Scale drawing’s tight bounding box to fit inside override dims; if only one dimension provided, scales uniformly by that dimension. |

Behavior summary:

  • If trim is false and overrides are present: overrides define the viewport size; drawing coordinates keep their scale (only alignment translation may occur if size differs).
  • If trim is true: the drawing bbox is uniformly scaled to fit inside the provided dimensions (paper-fit). Alignment then positions the scaled content.
  • Alignment is applied whenever trim is true OR any override dimension is provided.

You can introspect the authoritative JSON Schema at runtime via param_schema_json() for dynamic form generation.

TypeScript Helper Interface (example)

interface GCodeConversionOptions {
  // Conversion
  tolerance: number; feedrate: number; dpi: number;
  origin_x?: number|null; origin_y?: number|null; extra_attribute_name?: string|null;
  // Machine
  circular_interpolation: boolean;
  tool_on_sequence?: string|null; tool_off_sequence?: string|null;
  begin_sequence?: string|null; end_sequence?: string|null; between_layers_sequence?: string|null;
  // Postprocess
  checksums: boolean; line_numbers: boolean; newline_before_comment: boolean;
  // Layout
  override_width?: string; override_height?: string;
  h_align?: 'left'|'center'|'right';
  v_align?: 'top'|'center'|'bottom';
  trim: boolean;
}

Use param_schema_json() if you need to build forms dynamically or validate user input.

Building Locally

Requires a Rust toolchain and wasm-pack:

cargo install wasm-pack # if not already installed
npm run build:wasm

Outputs artifacts to pkg/ which are published to npm.

Versioning

The npm package version tracks the Rust crate version manually. Tag a release (vX.Y.Z) to trigger the publish workflow.

License

MIT