@rulecad/variables

Variables that say where each number comes from: expressions over rule sets, resolved, and a lint that keeps numbers out of code.

npm 0.3.7sourceMITNode >=20runs in this page
npm install @rulecad/variables

Try it

A design's variables, resolved against the published x1c printer rules as you type. Change a rule name, a sum or a value.

The lint that keeps measurements out of the shape's code: only 0, 1 and 2 may appear.

Reference

Design values you can trace. Every measurement is a variable, and every variable can say where it comes from: a printer's spec, a standard, a community figure, or something you measured (kind: spec, community, measured or estimate, with its source). Expressions are parsed, never eval'd, so a JSON file can't run code. No dependencies; browsers and Node 20+.

import { resolve } from '@rulecad/variables';

const printer = { name: 'printer', rules: {
  line: { value: 0.42, unit: 'mm', kind: 'spec', source: 'Bambu Lab wiki' },
  wall: { value: 'line * 3' },
} };
const tray = {
  uses: ['printer'],
  variables: {
    wall:   { value: 'printer.wall', label: 'Wall' },
    length: { value: 120, unit: 'mm', tweak: { min: 80, max: 160 } },
    inner:  { value: 'length - 2 * wall' },
  },
};

const { values, entries } = resolve(tray, { sets: { printer }, set: { length: 140 } });
values.inner          // 137.48
entries               // every variable and rule with its value, source and whether anything used it