@stll/template-conditions 0.6.0 → 0.6.2

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.
Files changed (2) hide show
  1. package/dist/index.js +12 -4
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -15,14 +15,14 @@ import { Temporal } from "temporal-polyfill/full";
15
15
  * (`parties.1.name`), and rejecting arrays would silently resolve those to
16
16
  * `undefined`.
17
17
  */
18
- const isRecord = (v) => typeof v === "object" && v !== null;
18
+ const isNonNullObject = (v) => typeof v === "object" && v !== null;
19
19
  /** Resolve a dotted path like `company.name` against data. */
20
20
  const resolvePath = (path, data) => {
21
21
  if (Object.hasOwn(data, path)) return data[path];
22
22
  const parts = path.split(".");
23
23
  let current = data;
24
24
  for (const part of parts) {
25
- if (!isRecord(current)) return;
25
+ if (!isNonNullObject(current)) return;
26
26
  current = current[part];
27
27
  }
28
28
  return current;
@@ -55,6 +55,14 @@ const NUMERIC_FUNCTION_NAMES = Object.freeze([
55
55
  "ceil"
56
56
  ]);
57
57
  const isNumericFunctionName = (name) => NUMERIC_FUNCTION_NAMES.some((candidate) => candidate === name);
58
+ const OPERATORS = [
59
+ "+",
60
+ "-",
61
+ "*",
62
+ "/",
63
+ "%"
64
+ ];
65
+ const isOperator = (value) => OPERATORS.some((candidate) => candidate === value);
58
66
  const TOKEN_RE = /(?<numeric>[0-9][0-9_]*(?:\.[0-9]+)?)|(?<ident>[\p{L}_][\p{L}\p{N}_.]*(?:-[\p{L}\p{N}_.]+)*)|(?<punct>[+\-*/%(),])|(?<invalid>\S)/gu;
59
67
  const PRECEDENCE = {
60
68
  "+": 1,
@@ -79,7 +87,7 @@ const tokenize$1 = (expression) => {
79
87
  else if (punct === "(") tokens.push({ t: "lp" });
80
88
  else if (punct === ")") tokens.push({ t: "rp" });
81
89
  else if (punct === ",") tokens.push({ t: "comma" });
82
- else if (punct !== void 0) tokens.push({
90
+ else if (punct !== void 0 && isOperator(punct)) tokens.push({
83
91
  t: "op",
84
92
  v: punct
85
93
  });
@@ -208,7 +216,7 @@ const RESERVED_WORDS = new Set(CONDITION_RESERVED_WORDS);
208
216
  const isConditionKeyword = (raw) => raw !== "true" && raw !== "false" && RESERVED_WORDS.has(raw);
209
217
  /** The keyword alternation of the tokenizer, derived from the same list. */
210
218
  const KEYWORD_PATTERN = CONDITION_RESERVED_WORDS.filter(isConditionKeyword).map((word) => String.raw`${word}\b`).join("|");
211
- const COMPARE_SYMBOL_PATTERN = Object.keys(COMPARE_SYMBOL_TO_OP).sort((left, right) => right.length - left.length).map(escapeRegexLiteral).join("|");
219
+ const COMPARE_SYMBOL_PATTERN = Object.keys(COMPARE_SYMBOL_TO_OP).toSorted((left, right) => right.length - left.length).map(escapeRegexLiteral).join("|");
212
220
  const NON_STRING_TOKEN_RE = new RegExp(String.raw`(?<token>${COMPARE_SYMBOL_PATTERN}|${KEYWORD_PATTERN}|[()]|-?\d[\p{N}_.]*|[\p{L}\p{N}_.]+(?:-[\p{L}\p{N}_.]+)*)`, "uy");
213
221
  const STARTS_WITH_DIGIT_RE = /^-?\d/u;
214
222
  const isCompareSymbol = (raw) => Object.hasOwn(COMPARE_SYMBOL_TO_OP, raw);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/template-conditions",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "A document-template marker and condition engine: {{...}} marker grammar, parse, compute, serialize, field values.",
5
5
  "keywords": [
6
6
  "condition",
@@ -43,7 +43,7 @@
43
43
  "test": "bun test",
44
44
  "test:property": "bun test --preload @stll/property-testing/preload $(grep -rlF 'fc.assert' src --include='*.test.ts')",
45
45
  "typecheck": "bun ../../packages/scripts/src/tsc-native.ts --noEmit",
46
- "lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --deny-warnings --type-aware packages/template-conditions",
46
+ "lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --type-aware packages/template-conditions",
47
47
  "lint:fix": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --type-aware --fix packages/template-conditions",
48
48
  "format": "bun ../../scripts/run-oxfmt.ts .",
49
49
  "prepack": "bun run build"
@@ -51,13 +51,13 @@
51
51
  "dependencies": {
52
52
  "@stll/conditions": "^0.4.0",
53
53
  "better-result": "3.0.1",
54
- "temporal-polyfill": "1.0.4"
54
+ "temporal-polyfill": "1.0.5"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@stll/property-testing": "0.0.0",
58
58
  "@stll/typescript-config": "0.0.0",
59
59
  "bun-types": "1.4.2",
60
- "fast-check": "^4.9.0",
60
+ "fast-check": "^4.10.1",
61
61
  "tsdown": "0.23.0"
62
62
  },
63
63
  "main": "./dist/index.js",