@rulecad/variables 0.1.2 → 0.1.4
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 +1 -1
- package/variables.d.mts +1 -1
- package/variables.mjs +6 -4
package/package.json
CHANGED
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,
|
|
@@ -119,7 +119,8 @@ export function resolve(object, { sets = {}, set = {}, display = {}, load } = {}
|
|
|
119
119
|
busy.add(name);
|
|
120
120
|
let src, where;
|
|
121
121
|
if (name.includes('.')) {
|
|
122
|
-
|
|
122
|
+
let [s, r] = name.split('.');
|
|
123
|
+
if (!ruleSets[s] && ruleSets[s.replace(/_/g, '-')]) s = s.replace(/_/g, '-'); // pod_th.width reads the set named pod-th (a - is a minus here)
|
|
123
124
|
if (!ruleSets[s]) throw new Error(`"${name}": rule set "${s}" isn't in uses (${Object.keys(ruleSets).join(', ') || 'none'})`);
|
|
124
125
|
if (!ruleSets[s].rules[r]) throw new Error(`"${name}": no rule "${r}" in ${s}`);
|
|
125
126
|
src = ruleSets[s].rules[r].value; where = (n) => (n.includes('.') ? n : `${s}.${n}`); // a rule's names are its own set's
|
|
@@ -146,6 +147,7 @@ export function resolve(object, { sets = {}, set = {}, display = {}, load } = {}
|
|
|
146
147
|
values[s][r] = lookup(`${s}.${r}`);
|
|
147
148
|
entries.push({ name: `${s}.${r}`, ...d, value: values[s][r], expr: typeof d.value === 'string' ? d.value : undefined, used: used.has(`${s}.${r}`) });
|
|
148
149
|
}
|
|
150
|
+
if (rs.footprints) values[s].footprints = rs.footprints; // pad data for boards (v.esp32c6.footprints.module), as the set gives it
|
|
149
151
|
}
|
|
150
152
|
return { values, entries };
|
|
151
153
|
}
|