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

@cadit-app/script-params

v0.5.2

Published

Type-safe parameter definitions for CADit scripts

Readme

@cadit-app/script-params

Type-safe parameter definitions for CADit parametric scripts.

Installation

npm install @cadit-app/script-params

Quick Start

import { defineParams } from '@cadit-app/script-params';

export default defineParams({
  params: {
    size: { type: 'number', default: 10, min: 1, max: 100 },
    label: { type: 'text', default: 'Hello' },
    hollow: { type: 'boolean', default: false },
  },
  main: (params) => {
    // params.size is number
    // params.label is string
    // params.hollow is boolean
    return createModel(params.size, params.label, params.hollow);
  },
});

Features

  • Type-safe parameters - Full TypeScript inference without as const
  • Default values - Scripts work standalone when params are undefined
  • UI generation - Schema can be converted to UI controls
  • Exporters - Define custom export formats (SVG, PNG, etc.)
  • Simple API - Just one function to learn

Parameter Types

| Type | Value Type | Additional Options | |------|------------|-------------------| | number | number | min, max, step | | int | number | min, max, step | | text | string | maxLength, placeholder | | boolean | boolean | - | | choice | string | options: string[] or options: { value, label }[] | | slider | number | min, max, step (required: min, max) | | buttonGrid | string | options: { value, image?, caption? }[] | | image | ImageFileValue \| null | - | | embedded | EmbeddedParamValue | params, enabled?, showSettings? |

API Reference

defineParams(config)

Define parameters for a script. Pass a config object with params (required), and optionally main and exporters.

Basic usage:

export default defineParams({
  params: {
    size: { type: 'number', default: 10 },
  },
  main: (params) => Manifold.cube([params.size, params.size, params.size]),
});
// Returns a callable ScriptModule

With exporters:

export default defineParams({
  params: {
    size: { type: 'number', default: 10 },
  },
  exporters: {
    svg: {
      name: 'SVG',
      label: 'Download SVG',
      export: async (params) => ({
        mimeType: 'image/svg+xml',
        fileName: 'model.svg',
        data: generateSvg(params),
      }),
    },
  },
  main: (params) => Manifold.cube([params.size, params.size, params.size]),
});

Without main (add main separately):

const script = defineParams({
  params: { size: { type: 'number', default: 10 } },
  exporters: { svg: svgExporter },
});

export default createMain(script, myMainFunction);

createMain(scriptModule, main)

Add a main function to a ScriptModule. Preserves any exporters.

const script = defineParams({
  params: { size: { type: 'number', default: 10 } },
  exporters: { svg: svgExporter },
});

export default createMain(script, (p) => Manifold.cube([p.size, ...]));

Params<S>

Type helper to get the params object type from a schema.

const script = defineParams({
  params: {
    size: { type: 'number', default: 10 },
  },
});

type MyParams = Params<typeof script.params>;
// { size: number }

schemaToArray(schema)

Convert object-based schema to array format for legacy UI compatibility.

const array = schemaToArray({
  size: { type: 'number', default: 10 },
});
// [{ name: 'size', type: 'number', initial: 10, caption: 'size' }]

getDefaults(schema)

Extract default values from a schema.

const defaults = getDefaults({
  size: { type: 'number', default: 10 },
  label: { type: 'text', default: 'Hi' },
});
// { size: 10, label: 'Hi' }

isScriptModule(value)

Check if a value is a ScriptModule created by defineParams.

const mod = await import('./script.ts');
if (isScriptModule(mod.default)) {
  const result = mod.default({ size: 20 });
}

getParams(source)

Extract the parameter schema from a ScriptModule.

const qrParams = getParams(qrCodeScript);

getExporters(module)

Extract exporters from a ScriptModule.

const exporters = getExporters(script);
// { svg: { name: 'SVG', ... }, png: { name: 'PNG', ... } }

Exporters

Exporters allow scripts to define custom download formats:

import { defineParams, Exporter, ExportResult } from '@cadit-app/script-params';

const svgExporter: Exporter = {
  name: 'SVG',
  label: 'Download SVG',
  description: 'Export as scalable vector graphic',
  export: async (params): Promise<ExportResult> => ({
    mimeType: 'image/svg+xml',
    fileName: 'output.svg',
    data: generateSvgFromParams(params),
  }),
};

export default defineParams({
  params: {
    size: { type: 'number', default: 10 },
  },
  exporters: { svg: svgExporter },
  main: (params) => generateGeometry(params),
});

License

MIT