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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@steeringwaves/openscad-js

v0.0.5

Published

openscad code generator for javascript

Readme

openscad-js

workflow

Javascript/typescript based code generator for openscad.

usage

import fs from "fs";
import Scad from "@steeringwaves/openscad-js";

const scad = new Scad.Module({
	fs: fs // Only required when calling toScadFile()
});

const origin = scad.modules.translate([0, 0, 0]);

scad.specials.$fn = 200;
scad.specials.$vpr = [0, 0, 0];

const default_fn = scad.addVariable("default_fn", 200);

const sphere_diameter = scad.addVariable("sphere_diameter", 5, { section: "Options", comment: "Diameter of the sphere" });
const cube1 = scad.addVariable<Scad.IVector3>("cube1", [1, 2, 3], {
	section: "Options",
	comment: "Dimensions of first cube"
});
const cube2 = scad.addVariable<Scad.IVector3>("cube2", [5, 5, 5], {
	section: "Options",
	comment: "Dimensions of second cube"
});

const sphere = origin(scad.modules.sphere({ r: sphere_diameter, $fn: 200 }));

scad.add(sphere);
scad.add(scad.modules.translate([10, 0, 0])(sphere));
scad.add(scad.modules.translate([-10, 0, 0])(scad.modules.sphere({ r: 5, $fn: 8 })));
scad.add(scad.modules.translate([20, 0, 0])(scad.modules.cube(cube1)));
scad.add(scad.modules.translate([20, 10, 0])(scad.modules.cube(cube2)));
scad.add(scad.modules.translate([20, 40, 0])(scad.modules.resize(cube2)(scad.modules.cube(cube1))));
scad.add(scad.modules.translate([20, -10, 0])(scad.modules.cube(5)));
scad.add(scad.modules.translate([40, 0, 0])(scad.modules.cylinder({ r1: 3, r2: 5, h: 25, center: true })));
scad.add(scad.modules.translate([40, 20, 0])(scad.modules.cylinder({ r: 5, h: 25 })));

console.log(scad.toString());

scad.toScadFile(__filename);
const Scad = require("@steeringwaves/openscad-js");

const scad = new Scad.Module({});

const origin = scad.modules.translate([0, 0, 0]);

scad.specials.$fn = 200;
scad.specials.$vpr = [0, 0, 0];

const sphere_diameter = scad.addVariable("sphere_diameter", 5, { section: "Options", comment: "Diameter of the sphere" });
const sphere = origin(scad.modules.sphere({ r: sphere_diameter }));

scad.add(sphere);

console.log(scad.toString());

js2scad cli

This package ships a small cli that runs a model and (optionally) re-runs it whenever a source file changes. It boots node with ts-node for typescript models, so there is nothing to configure beyond having ts-node and typescript installed alongside your models.

installing it

# as a project dependency, gives you node_modules/.bin/js2scad
npm install --save-dev @steeringwaves/openscad-js
npx js2scad model.ts          # or `yarn js2scad model.ts`, or plain `js2scad` inside a package.json script

# or globally, gives you a js2scad on your PATH anywhere
npm install -g @steeringwaves/openscad-js
js2scad model.ts

A bare js2scad in your shell only works with the global install, a project install puts the command in node_modules/.bin which npm/yarn add to the path for npx, yarn and package scripts. Without any install you would need npx -p @steeringwaves/openscad-js js2scad model.ts, since npx js2scad alone looks for a package named js2scad.

using it

# run a model once, it writes its own .scad (via scad.toScadFile(__filename))
js2scad jscad/models/example1/example1.ts

# same thing, but re-run on every save
js2scad --watch jscad/models/example1/example1.ts

# type checking is the slow part, skip it while iterating
js2scad --watch --transpile-only jscad/models/example1/example1.ts

# anything after -- is handed to the model itself as process.argv
js2scad model.ts -- --width 40
usage:
  js2scad [options] <file> [-- <model args>]

options:
  -w, --watch            re-run whenever the model or one of its local imports changes
  -T, --transpile-only   skip typescript type checking (much faster rebuilds)
  -C, --cwd <dir>        working directory used to run the model (default: current directory)
  -c, --clear            clear the screen before each re-run (watch mode only)
  -q, --quiet            only report failures
  -h, --help             show this help
  -v, --version          show the js2scad version

Notes:

  • The model decides where its output lands, js2scad never writes the .scad itself. It only reports the file when it notices one was written next to the model.
  • Watch mode tracks the model's real dependency list (every non node_modules file it loaded), so editing a shared helper triggers a rebuild too.
  • Status output goes to stderr, so js2scad model.ts > model.scad still works for models that print with console.log(scad.toString()).
  • Both .js and .ts models are supported, ts-node is only required for the typescript ones.

unsupported methods

All the known methods of writing this document are supported with types in this library under the modules object. However in order to future proof a bit we also support a special object named any which allows you to call any new/unsupported methods anyways.

// modules.color is a supported method and has type checking
scad.modules.color([255, 0, 0])(scad.modules.sphere({ r: 5 }));

// any.color is identical to the above except that it has no type checking
scad.any.color([255, 0, 0])(scad.modules.sphere({ r: 5 }));

// any.dosomethingcool allows this module to support newer versions or custom modifications
scad.any.dosomethingcool(100)(scad.modules.sphere({ r: 5 }));

available functions under the modules object

  union
  difference
  intersection
  translate
  mirror
  rotate
  color
  scale
  resize
  multimatrix
  offset
  fill
  hull
  minkowski
  sphere
  cube
  cylinder
  polyhedron
  linear_extrude
  rotate_extrude
  square
  circle
  polygon
  text
  projection

Special variables available under the specials object

  $fa
  $fs
  $fn
  $t
  $vpr
  $vpt
  $vpd
  $vpf
  $children
  $preview

custom variables

Customizable variables are support by calling the addVariable method which will return a special type that can be reference in your code. NOTE: This is a bit of a hack because if the user changes this value from within openscad our javascript has already executed and will be unable to react to changes that aren't coded in already.

const sphere_diameter = scad.addVariable("sphere_diameter", 5, { section: "Options", comment: "Diameter of the sphere" });
const sphere = origin(scad.modules.sphere({ r: sphere_diameter }));

development

yarn install
yarn run format && yarn run ci