@rulecad/variables 0.1.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/variables",
3
- "version": "0.1.2",
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": {
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 && !opts.includes(s)) throw new Error(`${name} is one of ${opts.join(', ')} (got "${s}")`);
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,