@rulecad/variables 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +2 -2
- package/variables.d.mts +1 -1
- package/variables.mjs +3 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Design values you can trace. Every measurement is a variable, and every variable can say where it comes from: a
|
|
4
4
|
printer's spec, a standard, a community figure, or something you measured (`kind`: spec, community, measured or
|
|
5
5
|
estimate, with its `source`). Expressions are parsed, never `eval`'d, so a JSON file can't run code. No dependencies;
|
|
6
|
-
browsers and Node
|
|
6
|
+
browsers and Node 20+.
|
|
7
7
|
|
|
8
8
|
```js
|
|
9
9
|
import { resolve } from '@rulecad/variables';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/variables",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Design values you can trace: every number says where it comes from, and expressions are parsed, never run.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"provenance"
|
|
23
23
|
],
|
|
24
24
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
25
|
+
"node": ">=20"
|
|
26
26
|
},
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"repository": {
|
package/variables.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function checkName(name: any, d: any, v: any): string;
|
|
1
|
+
export function checkName(name: any, d: any, v: any): string | number;
|
|
2
2
|
/**
|
|
3
3
|
* One expression: + - * / and brackets, min, max, round, sind, cosd, tand, over numbers and names. Never runs code.
|
|
4
4
|
* @param {string | number} src
|
package/variables.mjs
CHANGED
|
@@ -17,10 +17,10 @@ export const ANCHORS = ['tl', 'tc', 'tr', 'ml', 'mc', 'mr', 'bl', 'bc', 'br'];
|
|
|
17
17
|
export const isName = (d) => !!(d.choice || ['text', 'anchor', 'layout'].includes(d.type));
|
|
18
18
|
export const options = (d) => (d.type === 'anchor' ? ANCHORS : d.type === 'text' ? null : d.choice);
|
|
19
19
|
export function checkName(name, d, v) {
|
|
20
|
-
const s = String(v), opts = options(d);
|
|
21
|
-
if (opts &&
|
|
20
|
+
const s = String(v), opts = options(d), match = opts?.find((o) => String(o) === s);
|
|
21
|
+
if (opts && match === undefined) throw new Error(`${name} is one of ${opts.join(', ')} (got "${s}")`);
|
|
22
22
|
if (!opts && s.length > (d.max ?? 16)) throw new Error(`${name} is at most ${d.max ?? 16} characters`);
|
|
23
|
-
return s;
|
|
23
|
+
return typeof match === 'number' ? match : s; // choices can be numbers too (a rotation: 0, 90, 180, 270)
|
|
24
24
|
}
|
|
25
25
|
const DEG = Math.PI / 180;
|
|
26
26
|
const FNS = { min: Math.min, max: Math.max, round: (x, step = 1) => Math.round(x / step) * step,
|