@rulecad/variables 0.3.4 → 0.3.5
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 +11 -0
- package/package.json +3 -2
- package/variables.d.mts +2 -1
- package/variables.mjs +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog: @rulecad/variables
|
|
2
|
+
|
|
3
|
+
What changed in each release, for someone upgrading a workspace.
|
|
4
|
+
|
|
5
|
+
## 0.3.5: points in a rule set
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- A vocabulary field may be `points` (so many numbers each, one after another), and a rule set's list is checked to
|
|
10
|
+
hold whole points.
|
|
11
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/variables",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"variables.mjs",
|
|
12
12
|
"variables.d.mts",
|
|
13
13
|
"README.md",
|
|
14
|
-
"LICENSE"
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"CHANGELOG.md"
|
|
15
16
|
],
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"keywords": [
|
package/variables.d.mts
CHANGED
|
@@ -33,7 +33,7 @@ export function resolve(object: DesignObject, { sets, set, display, load }?: {
|
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* @param {RuleSet & { part?: string, interface?: Record<string, string> }} set
|
|
36
|
-
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
36
|
+
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean, points?: number }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
37
37
|
* @returns {{ level: 'fail', code: string, text: string, rule?: string, values?: Record<string, number> }[]} what's wrong with it: nothing, if it passes
|
|
38
38
|
*/
|
|
39
39
|
export function checkRuleSet(set: RuleSet & {
|
|
@@ -46,6 +46,7 @@ export function checkRuleSet(set: RuleSet & {
|
|
|
46
46
|
unit?: string;
|
|
47
47
|
choice?: string[];
|
|
48
48
|
list?: boolean;
|
|
49
|
+
points?: number;
|
|
49
50
|
}>;
|
|
50
51
|
parts: Record<string, string[]>;
|
|
51
52
|
checks?: Record<string, {
|
package/variables.mjs
CHANGED
|
@@ -280,7 +280,7 @@ const KINDS = ['measured', 'spec', 'community', 'default', 'derived', 'estimate'
|
|
|
280
280
|
const finite = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
281
281
|
/**
|
|
282
282
|
* @param {RuleSet & { part?: string, interface?: Record<string, string> }} set
|
|
283
|
-
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
283
|
+
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean, points?: number }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
284
284
|
* @returns {{ level: 'fail', code: string, text: string, rule?: string, values?: Record<string, number> }[]} what's wrong with it: nothing, if it passes
|
|
285
285
|
*/
|
|
286
286
|
export function checkRuleSet(set, vocabulary) {
|
|
@@ -289,6 +289,7 @@ export function checkRuleSet(set, vocabulary) {
|
|
|
289
289
|
for (const [name, r] of Object.entries(rules)) {
|
|
290
290
|
const list = Array.isArray(r.value);
|
|
291
291
|
if (!(list ? r.value.length && r.value.every(finite) : finite(r.value) || (typeof r.value === 'string' && r.value))) f('rules.value', list ? `${name} is a list, so every entry is a number and there is at least one` : `${name} has no value`, name);
|
|
292
|
+
else if (list && fields?.[name]?.points) { const n = fields[name].points; if (r.value.length % n) f('rules.list', `${name} is points of ${n} numbers each, one after another: ${r.value.length} numbers is not a whole number of them`, name); } // (points: in the order they are, not ascending)
|
|
292
293
|
else if (list) { const i = r.value.findIndex((x, k) => k && x <= r.value[k - 1]); if (i > 0) f('rules.order', `${name} is a list in ascending order: ${r.value[i]} follows ${r.value[i - 1]}`, name, { before: r.value[i - 1], after: r.value[i] }); }
|
|
293
294
|
if (!(typeof r.rule === 'string' && r.rule.length > 5)) f('rules.says', `${name} doesn't say what it is ("rule")`, name);
|
|
294
295
|
if (!KINDS.includes(r.kind)) f('rules.kind', `${name}: kind ${JSON.stringify(r.kind)} is not one of ${KINDS.join(', ')}`, name);
|