@stll/template-conditions 0.2.0 → 0.2.1

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 +7 -4
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -175,8 +175,6 @@ const evaluateNumericExpression = (expression, data) => {
175
175
  };
176
176
  //#endregion
177
177
  //#region src/parse.ts
178
- const NON_STRING_TOKEN_RE = /(?<token>==|!=|>=|<=|>|<|!(?!=)|and\b|or\b|contains\b|[()]|-?\d[\p{N}_.]*|[\p{L}\p{N}_.]+(?:-[\p{L}\p{N}_.]+)*)/uy;
179
- const STARTS_WITH_DIGIT_RE = /^-?\d/u;
180
178
  const COMPARE_SYMBOL_TO_OP = {
181
179
  "==": "eq",
182
180
  "!=": "neq",
@@ -185,6 +183,11 @@ const COMPARE_SYMBOL_TO_OP = {
185
183
  ">=": "gte",
186
184
  "<=": "lte"
187
185
  };
186
+ const escapeRegexLiteral = (value) => value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
187
+ const COMPARE_SYMBOL_PATTERN = Object.keys(COMPARE_SYMBOL_TO_OP).sort((left, right) => right.length - left.length).map(escapeRegexLiteral).join("|");
188
+ const NON_STRING_TOKEN_RE = new RegExp(String.raw`(?<token>${COMPARE_SYMBOL_PATTERN}|!(?!=)|and\b|or\b|contains\b|[()]|-?\d[\p{N}_.]*|[\p{L}\p{N}_.]+(?:-[\p{L}\p{N}_.]+)*)`, "uy");
189
+ const STARTS_WITH_DIGIT_RE = /^-?\d/u;
190
+ const isCompareSymbol = (raw) => Object.hasOwn(COMPARE_SYMBOL_TO_OP, raw);
188
191
  /**
189
192
  * Scan a `"..."` literal starting at `expr[start]` (the opening quote),
190
193
  * honoring `\\`-escapes without interpreting them. A single linear pass:
@@ -213,7 +216,7 @@ const classifyNonString = (raw) => {
213
216
  if (raw === "and") return { type: "and" };
214
217
  if (raw === "or") return { type: "or" };
215
218
  if (raw === "!") return { type: "not" };
216
- if (raw === "contains" || Object.hasOwn(COMPARE_SYMBOL_TO_OP, raw)) return {
219
+ if (raw === "contains" || isCompareSymbol(raw)) return {
217
220
  type: "op",
218
221
  raw
219
222
  };
@@ -371,7 +374,7 @@ const parseCondition = (expression) => {
371
374
  return {
372
375
  type: "compare",
373
376
  left,
374
- op: COMPARE_SYMBOL_TO_OP[opTok.raw] ?? "eq",
377
+ op: COMPARE_SYMBOL_TO_OP[opTok.raw],
375
378
  right: operandFromToken(rightTok)
376
379
  };
377
380
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/template-conditions",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A document-template marker and condition engine: {{...}} marker grammar, parse, compute, serialize, field values.",
5
5
  "keywords": [
6
6
  "condition",
@@ -41,7 +41,7 @@
41
41
  "build": "tsdown",
42
42
  "pack:dry-run": "bun pm pack --dry-run",
43
43
  "test": "bun test",
44
- "test:property": "bun test $(grep -rlF 'fc.assert' src --include='*.test.ts')",
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
46
  "lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --deny-warnings --type-aware packages/template-conditions",
47
47
  "lint:fix": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --type-aware --fix packages/template-conditions",
@@ -49,13 +49,13 @@
49
49
  "prepack": "bun run build"
50
50
  },
51
51
  "dependencies": {
52
- "@stll/conditions": "^0.2.0",
52
+ "@stll/conditions": "^0.3.0",
53
53
  "better-result": "3.0.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@stll/property-testing": "0.0.0",
57
57
  "@stll/typescript-config": "0.0.0",
58
- "@types/bun": "1.3.14",
58
+ "bun-types": "1.4.0",
59
59
  "fast-check": "^4.9.0",
60
60
  "tsdown": "0.22.14"
61
61
  },