cognova 0.2.17 → 0.2.18

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.
@@ -105,6 +105,8 @@ class EntityDecoder {
105
105
  this.excess = 1;
106
106
  /** The mode in which the decoder is operating. */
107
107
  this.decodeMode = DecodingMode.Strict;
108
+ /** The number of characters that have been consumed in the current run. */
109
+ this.runConsumed = 0;
108
110
  }
109
111
  /** Resets the instance to make it reusable. */
110
112
  startEntity(decodeMode) {
@@ -114,6 +116,7 @@ class EntityDecoder {
114
116
  this.treeIndex = 0;
115
117
  this.excess = 1;
116
118
  this.consumed = 1;
119
+ this.runConsumed = 0;
117
120
  }
118
121
  /**
119
122
  * Write an entity to the decoder. This can be called multiple times with partial entities.
@@ -276,43 +279,40 @@ class EntityDecoder {
276
279
  // Handle compact runs (possibly inline): valueLength == 0 and SEMI_REQUIRED bit set.
277
280
  if (valueLength === 0 && (current & bin_trie_flags_js_1.BinTrieFlags.FLAG13) !== 0) {
278
281
  const runLength = (current & bin_trie_flags_js_1.BinTrieFlags.BRANCH_LENGTH) >> 7; /* 2..63 */
279
- const firstChar = current & bin_trie_flags_js_1.BinTrieFlags.JUMP_TABLE;
280
- // Fast-fail if we don't have enough remaining input for the full run (incomplete entity)
281
- if (offset + runLength > input.length)
282
- return -1;
283
- // Verify first char
284
- if (input.charCodeAt(offset) !== firstChar) {
285
- return this.result === 0
286
- ? 0
287
- : this.emitNotTerminatedNamedEntity();
288
- }
289
- offset++;
290
- this.excess++;
291
- // Remaining characters after the first
292
- const remaining = runLength - 1;
293
- // Iterate over packed 2-char words
294
- for (let runPos = 1; runPos < runLength; runPos += 2) {
295
- const packedWord = decodeTree[this.treeIndex + 1 + ((runPos - 1) >> 1)];
296
- const low = packedWord & 0xff;
297
- if (input.charCodeAt(offset) !== low) {
282
+ // If we are starting a run, check the first char.
283
+ if (this.runConsumed === 0) {
284
+ const firstChar = current & bin_trie_flags_js_1.BinTrieFlags.JUMP_TABLE;
285
+ if (input.charCodeAt(offset) !== firstChar) {
298
286
  return this.result === 0
299
287
  ? 0
300
288
  : this.emitNotTerminatedNamedEntity();
301
289
  }
302
290
  offset++;
303
291
  this.excess++;
304
- const high = (packedWord >> 8) & 0xff;
305
- if (runPos + 1 < runLength) {
306
- if (input.charCodeAt(offset) !== high) {
307
- return this.result === 0
308
- ? 0
309
- : this.emitNotTerminatedNamedEntity();
310
- }
311
- offset++;
312
- this.excess++;
292
+ this.runConsumed++;
293
+ }
294
+ // Check remaining characters in the run.
295
+ while (this.runConsumed < runLength) {
296
+ if (offset >= input.length) {
297
+ return -1;
313
298
  }
299
+ const charIndexInPacked = this.runConsumed - 1;
300
+ const packedWord = decodeTree[this.treeIndex + 1 + (charIndexInPacked >> 1)];
301
+ const expectedChar = charIndexInPacked % 2 === 0
302
+ ? packedWord & 0xff
303
+ : (packedWord >> 8) & 0xff;
304
+ if (input.charCodeAt(offset) !== expectedChar) {
305
+ this.runConsumed = 0;
306
+ return this.result === 0
307
+ ? 0
308
+ : this.emitNotTerminatedNamedEntity();
309
+ }
310
+ offset++;
311
+ this.excess++;
312
+ this.runConsumed++;
314
313
  }
315
- this.treeIndex += 1 + ((remaining + 1) >> 1);
314
+ this.runConsumed = 0;
315
+ this.treeIndex += 1 + (runLength >> 1);
316
316
  current = decodeTree[this.treeIndex];
317
317
  valueLength = (current & bin_trie_flags_js_1.BinTrieFlags.VALUE_LENGTH) >> 14;
318
318
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "entities",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Encode & decode XML and HTML entities with ease & speed",
5
5
  "keywords": [
6
6
  "html entities",
@@ -61,12 +61,14 @@
61
61
  "escape.js",
62
62
  "escape.d.ts",
63
63
  "dist",
64
- "src"
64
+ "src",
65
+ "!**/*.spec.ts"
65
66
  ],
66
67
  "scripts": {
67
68
  "build:docs": "typedoc --hideGenerator src/index.ts",
68
69
  "build:encode-trie": "node --import=tsx scripts/write-encode-map.ts",
69
70
  "build:trie": "node --import=tsx scripts/write-decode-map.ts",
71
+ "benchmark": "node --import=tsx scripts/benchmark.ts",
70
72
  "format": "npm run format:es && npm run format:biome",
71
73
  "format:es": "npm run lint:es -- --fix",
72
74
  "format:biome": "biome check --fix .",
@@ -79,19 +81,24 @@
79
81
  "test:vi": "vitest run"
80
82
  },
81
83
  "devDependencies": {
82
- "@biomejs/biome": "^2.2.3",
83
- "@types/node": "^24.3.1",
84
- "@typescript-eslint/eslint-plugin": "^8.42.0",
85
- "@typescript-eslint/parser": "^8.33.1",
84
+ "@biomejs/biome": "^2.3.11",
85
+ "@types/node": "^25.0.9",
86
+ "@typescript-eslint/eslint-plugin": "^8.53.1",
87
+ "@typescript-eslint/parser": "^8.53.1",
86
88
  "@vitest/coverage-v8": "^3.2.4",
89
+ "@types/he": "^1.2.3",
87
90
  "eslint": "^8.57.1",
88
91
  "eslint-config-biome": "^2.1.3",
89
- "eslint-plugin-n": "^17.21.3",
92
+ "eslint-plugin-n": "^17.23.2",
90
93
  "eslint-plugin-unicorn": "^56.0.1",
91
- "tshy": "^3.0.2",
92
- "tsx": "^4.20.5",
93
- "typedoc": "^0.28.12",
94
- "typescript": "^5.9.2",
94
+ "he": "^1.2.0",
95
+ "html-entities": "^2.6.0",
96
+ "parse-entities": "^4.0.2",
97
+ "tinybench": "^5.1.0",
98
+ "tshy": "^3.1.0",
99
+ "tsx": "^4.21.0",
100
+ "typedoc": "^0.28.16",
101
+ "typescript": "^5.9.3",
95
102
  "vitest": "^3.2.4"
96
103
  },
97
104
  "engines": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cognova",
3
3
  "type": "module",
4
- "version": "0.2.17",
4
+ "version": "0.2.18",
5
5
  "description": "Personal knowledge management system with Claude Code integration",
6
6
  "repository": {
7
7
  "type": "git",
@@ -83,6 +83,7 @@
83
83
  "dotenv": "^17.2.3",
84
84
  "drizzle-kit": "^0.31.8",
85
85
  "drizzle-orm": "^0.45.1",
86
+ "entities": "^7.0.1",
86
87
  "gray-matter": "^4.0.3",
87
88
  "node-pty": "^1.1.0",
88
89
  "nuxt": "^4.2.2",
@@ -1 +0,0 @@
1
- {"id":"193167ad-c68a-48dc-8ed4-2336a5a7b3bc","timestamp":1771877208314,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}