@rulecad/variables 0.3.5 → 0.3.6

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/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  What changed in each release, for someone upgrading a workspace.
4
4
 
5
+ ## 0.3.6: material ranges
6
+ ### Added
7
+
8
+ - `checkRuleSet` holds a rule's range to its value: `low` at most it, `high` at least it, both numbers (`rules.range`).
9
+
5
10
  ## 0.3.5: points in a rule set
6
11
 
7
12
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/variables",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
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.mjs CHANGED
@@ -276,6 +276,8 @@ export function resolve(object, { sets = {}, set = {}, display = {}, load } = {}
276
276
  // { "ascending": ["tap_drill", "major_diameter", "clearance"], "says": "…" } the names it has, each larger than the last
277
277
  // { "near": "tap_drill", "to": "major_diameter - pitch", "within": "0.2 * pitch", "says": "…" } expressions over its own rules
278
278
  // and a field marked "list": true holds a list (the lengths a screw is sold in), which must ascend.
279
+ // A number may carry the range it is found in, "low" and "high" (a printed plastic's, which varies with the printer and
280
+ // the spool), each a number in its unit, low at most the value and high at least it.
279
281
  const KINDS = ['measured', 'spec', 'community', 'default', 'derived', 'estimate'];
280
282
  const finite = (x) => typeof x === 'number' && Number.isFinite(x);
281
283
  /**
@@ -294,6 +296,11 @@ export function checkRuleSet(set, vocabulary) {
294
296
  if (!(typeof r.rule === 'string' && r.rule.length > 5)) f('rules.says', `${name} doesn't say what it is ("rule")`, name);
295
297
  if (!KINDS.includes(r.kind)) f('rules.kind', `${name}: kind ${JSON.stringify(r.kind)} is not one of ${KINDS.join(', ')}`, name);
296
298
  if (!(typeof r.source === 'string' && r.source)) f('rules.source', `${name} has no source`, name);
299
+ for (const [k, ok] of [['low', (v) => v <= r.value], ['high', (v) => v >= r.value]]) {
300
+ if (r[k] == null) continue;
301
+ if (!finite(r[k]) || !finite(r.value)) f('rules.range', `${name}: ${k} is a number in the rule's unit, beside a number value (got ${JSON.stringify(r[k])})`, name);
302
+ else if (!ok(r[k])) f('rules.range', `${name}: ${k} (${r[k]}) is ${k === 'low' ? 'above' : 'below'} its value (${r.value}): the range it is found in holds the value`, name, { value: r.value, [k]: r[k] });
303
+ }
297
304
  if (!/^\d{4}-\d{2}-\d{2}$/.test(String(r.checked))) f('rules.checked', `${name}: checked is the date it was last checked, YYYY-MM-DD (got ${JSON.stringify(r.checked)})`, name);
298
305
  if (set.part) {
299
306
  if (r.unit != null && !units.includes(r.unit)) f('rules.unit', `${name}: unit ${JSON.stringify(r.unit)} is not one of ${units.filter(Boolean).join(', ')}`, name);