entities 7.0.1 → 8.1.0

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 (143) hide show
  1. package/dist/decode-codepoint.d.ts +28 -0
  2. package/dist/decode-codepoint.d.ts.map +1 -0
  3. package/dist/decode-codepoint.js +61 -0
  4. package/dist/decode-codepoint.js.map +1 -0
  5. package/dist/{esm/decode.d.ts → decode.d.ts} +66 -44
  6. package/dist/decode.d.ts.map +1 -0
  7. package/dist/decode.js +1132 -0
  8. package/dist/decode.js.map +1 -0
  9. package/dist/{commonjs/encode.d.ts → encode.d.ts} +4 -0
  10. package/dist/encode.d.ts.map +1 -0
  11. package/dist/encode.js +295 -0
  12. package/dist/encode.js.map +1 -0
  13. package/dist/{esm/escape.d.ts → escape.d.ts} +23 -9
  14. package/dist/escape.d.ts.map +1 -0
  15. package/dist/escape.js +172 -0
  16. package/dist/escape.js.map +1 -0
  17. package/dist/generated/decode-data-html.d.ts +3 -0
  18. package/dist/generated/decode-data-html.d.ts.map +1 -0
  19. package/dist/generated/decode-data-html.js +5 -0
  20. package/dist/generated/decode-data-html.js.map +1 -0
  21. package/dist/generated/decode-data-xml.d.ts +3 -0
  22. package/dist/generated/decode-data-xml.d.ts.map +1 -0
  23. package/dist/generated/decode-data-xml.js +7 -0
  24. package/dist/generated/decode-data-xml.js.map +1 -0
  25. package/dist/generated/encode-html.d.ts +3 -0
  26. package/dist/generated/encode-html.d.ts.map +1 -0
  27. package/dist/generated/encode-html.js +3 -0
  28. package/dist/generated/encode-html.js.map +1 -0
  29. package/dist/{commonjs/index.d.ts → index.d.ts} +11 -18
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/{esm/index.js → index.js} +9 -29
  32. package/dist/index.js.map +1 -0
  33. package/dist/internal/bin-trie-flags.d.ts +48 -0
  34. package/dist/internal/bin-trie-flags.d.ts.map +1 -0
  35. package/dist/internal/bin-trie-flags.js +49 -0
  36. package/dist/internal/bin-trie-flags.js.map +1 -0
  37. package/dist/internal/decode-shared.d.ts +38 -0
  38. package/dist/internal/decode-shared.d.ts.map +1 -0
  39. package/dist/internal/decode-shared.js +195 -0
  40. package/dist/internal/decode-shared.js.map +1 -0
  41. package/package.json +28 -65
  42. package/readme.md +4 -16
  43. package/src/decode-codepoint.ts +51 -63
  44. package/src/decode.ts +944 -261
  45. package/src/encode.ts +289 -45
  46. package/src/escape.ts +114 -88
  47. package/src/generated/decode-data-html.ts +9 -3
  48. package/src/generated/decode-data-xml.ts +5 -4
  49. package/src/generated/encode-html.ts +1 -15
  50. package/src/index.ts +14 -41
  51. package/src/internal/bin-trie-flags.ts +38 -7
  52. package/src/internal/decode-shared.ts +203 -24
  53. package/decode.d.ts +0 -3
  54. package/decode.js +0 -3
  55. package/dist/commonjs/decode-codepoint.d.ts +0 -19
  56. package/dist/commonjs/decode-codepoint.d.ts.map +0 -1
  57. package/dist/commonjs/decode-codepoint.js +0 -77
  58. package/dist/commonjs/decode-codepoint.js.map +0 -1
  59. package/dist/commonjs/decode.d.ts +0 -205
  60. package/dist/commonjs/decode.d.ts.map +0 -1
  61. package/dist/commonjs/decode.js +0 -568
  62. package/dist/commonjs/decode.js.map +0 -1
  63. package/dist/commonjs/encode.d.ts.map +0 -1
  64. package/dist/commonjs/encode.js +0 -92
  65. package/dist/commonjs/encode.js.map +0 -1
  66. package/dist/commonjs/escape.d.ts +0 -46
  67. package/dist/commonjs/escape.d.ts.map +0 -1
  68. package/dist/commonjs/escape.js +0 -138
  69. package/dist/commonjs/escape.js.map +0 -1
  70. package/dist/commonjs/generated/decode-data-html.d.ts +0 -2
  71. package/dist/commonjs/generated/decode-data-html.d.ts.map +0 -1
  72. package/dist/commonjs/generated/decode-data-html.js +0 -7
  73. package/dist/commonjs/generated/decode-data-html.js.map +0 -1
  74. package/dist/commonjs/generated/decode-data-xml.d.ts +0 -2
  75. package/dist/commonjs/generated/decode-data-xml.d.ts.map +0 -1
  76. package/dist/commonjs/generated/decode-data-xml.js +0 -7
  77. package/dist/commonjs/generated/decode-data-xml.js.map +0 -1
  78. package/dist/commonjs/generated/encode-html.d.ts +0 -3
  79. package/dist/commonjs/generated/encode-html.d.ts.map +0 -1
  80. package/dist/commonjs/generated/encode-html.js +0 -14
  81. package/dist/commonjs/generated/encode-html.js.map +0 -1
  82. package/dist/commonjs/index.d.ts.map +0 -1
  83. package/dist/commonjs/index.js +0 -131
  84. package/dist/commonjs/index.js.map +0 -1
  85. package/dist/commonjs/internal/bin-trie-flags.d.ts +0 -17
  86. package/dist/commonjs/internal/bin-trie-flags.d.ts.map +0 -1
  87. package/dist/commonjs/internal/bin-trie-flags.js +0 -21
  88. package/dist/commonjs/internal/bin-trie-flags.js.map +0 -1
  89. package/dist/commonjs/internal/decode-shared.d.ts +0 -2
  90. package/dist/commonjs/internal/decode-shared.d.ts.map +0 -1
  91. package/dist/commonjs/internal/decode-shared.js +0 -31
  92. package/dist/commonjs/internal/decode-shared.js.map +0 -1
  93. package/dist/commonjs/internal/encode-shared.d.ts +0 -32
  94. package/dist/commonjs/internal/encode-shared.d.ts.map +0 -1
  95. package/dist/commonjs/internal/encode-shared.js +0 -94
  96. package/dist/commonjs/internal/encode-shared.js.map +0 -1
  97. package/dist/commonjs/package.json +0 -3
  98. package/dist/esm/decode-codepoint.d.ts +0 -19
  99. package/dist/esm/decode-codepoint.d.ts.map +0 -1
  100. package/dist/esm/decode-codepoint.js +0 -72
  101. package/dist/esm/decode-codepoint.js.map +0 -1
  102. package/dist/esm/decode.d.ts.map +0 -1
  103. package/dist/esm/decode.js +0 -554
  104. package/dist/esm/decode.js.map +0 -1
  105. package/dist/esm/encode.d.ts +0 -22
  106. package/dist/esm/encode.d.ts.map +0 -1
  107. package/dist/esm/encode.js +0 -88
  108. package/dist/esm/encode.js.map +0 -1
  109. package/dist/esm/escape.d.ts.map +0 -1
  110. package/dist/esm/escape.js +0 -134
  111. package/dist/esm/escape.js.map +0 -1
  112. package/dist/esm/generated/decode-data-html.d.ts +0 -2
  113. package/dist/esm/generated/decode-data-html.d.ts.map +0 -1
  114. package/dist/esm/generated/decode-data-html.js +0 -4
  115. package/dist/esm/generated/decode-data-html.js.map +0 -1
  116. package/dist/esm/generated/decode-data-xml.d.ts +0 -2
  117. package/dist/esm/generated/decode-data-xml.d.ts.map +0 -1
  118. package/dist/esm/generated/decode-data-xml.js +0 -4
  119. package/dist/esm/generated/decode-data-xml.js.map +0 -1
  120. package/dist/esm/generated/encode-html.d.ts +0 -3
  121. package/dist/esm/generated/encode-html.d.ts.map +0 -1
  122. package/dist/esm/generated/encode-html.js +0 -11
  123. package/dist/esm/generated/encode-html.js.map +0 -1
  124. package/dist/esm/index.d.ts +0 -96
  125. package/dist/esm/index.d.ts.map +0 -1
  126. package/dist/esm/index.js.map +0 -1
  127. package/dist/esm/internal/bin-trie-flags.d.ts +0 -17
  128. package/dist/esm/internal/bin-trie-flags.d.ts.map +0 -1
  129. package/dist/esm/internal/bin-trie-flags.js +0 -18
  130. package/dist/esm/internal/bin-trie-flags.js.map +0 -1
  131. package/dist/esm/internal/decode-shared.d.ts +0 -2
  132. package/dist/esm/internal/decode-shared.d.ts.map +0 -1
  133. package/dist/esm/internal/decode-shared.js +0 -28
  134. package/dist/esm/internal/decode-shared.js.map +0 -1
  135. package/dist/esm/internal/encode-shared.d.ts +0 -32
  136. package/dist/esm/internal/encode-shared.d.ts.map +0 -1
  137. package/dist/esm/internal/encode-shared.js +0 -91
  138. package/dist/esm/internal/encode-shared.js.map +0 -1
  139. package/dist/esm/package.json +0 -3
  140. package/escape.d.ts +0 -3
  141. package/escape.js +0 -3
  142. package/src/generated/.eslintrc.json +0 -10
  143. package/src/internal/encode-shared.ts +0 -121
@@ -1,30 +1,209 @@
1
1
  /*
2
- * Shared base64 decode helper for generated decode data.
3
- * Assumes global atob is available.
2
+ * Inverse of the encoder's SAFE alphabet (0x21..0x7E minus 0x22, 0x24, 0x5C),
3
+ * precomputed once at module load. Entries for excluded chars stay 0 but
4
+ * are never read.
4
5
  */
5
- export function decodeBase64(input: string): Uint16Array {
6
- const binary: string =
7
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
8
- typeof atob === "function"
9
- ? // Browser (and Node >=16)
10
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
11
- atob(input)
12
- : // Older Node versions (<16)
13
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
14
- typeof Buffer.from === "function"
15
- ? // eslint-disable-next-line n/no-unsupported-features/node-builtins
16
- Buffer.from(input, "base64").toString("binary")
17
- : // eslint-disable-next-line unicorn/no-new-buffer, n/no-deprecated-api
18
- new Buffer(input, "base64").toString("binary");
19
-
20
- const evenLength = binary.length & ~1; // Round down to even length
21
- const out = new Uint16Array(evenLength / 2);
22
-
23
- for (let index = 0, outIndex = 0; index < evenLength; index += 2) {
24
- const lo = binary.charCodeAt(index);
25
- const hi = binary.charCodeAt(index + 1);
26
- out[outIndex++] = lo | (hi << 8);
6
+ const BASE91_INVERSE = /* #__PURE__ */ (() => {
7
+ const table = new Uint8Array(127);
8
+ let code = 0;
9
+ for (let char = 0x21; char <= 0x7e; char++) {
10
+ if (char !== 0x22 && char !== 0x24 && char !== 0x5c) {
11
+ table[char] = code++;
12
+ }
27
13
  }
14
+ return table;
15
+ })();
28
16
 
17
+ /**
18
+ * Decode a dictionary-encoded trie string back into its Uint16Array.
19
+ *
20
+ * Stream layout (consumed in this order):
21
+ * 1. dict1 atoms — `dict1AtomCount` uint16 values, delta+RLE encoded.
22
+ * 2. dict2 atoms — `atomCount - dict1AtomCount` values, delta+RLE.
23
+ * 3. dict2 ngrams — `ngramCount - (dictSize - dict1AtomCount)` entries,
24
+ * each a pair of slot codes that resolve to earlier slots.
25
+ * 4. dict1 ngrams — `dictSize - dict1AtomCount` entries, same shape.
26
+ * 5. data — slot codes, each expanding to one or more uint16 values.
27
+ *
28
+ * Codes use a 91-char base (printable ASCII minus `"`, `$`, `\`):
29
+ * - char1 < dictSize → 1-char code, slot = char1
30
+ * - char1 ≥ dictSize → 2-char code, slot = dictSize + (char1 - dictSize)*91 + char2
31
+ *
32
+ * Slot index → token kind:
33
+ * [0, A) dict1 atoms (1-char codes)
34
+ * [A, dictSize) dict1 ngrams (1-char codes)
35
+ * [dictSize, dictSize+D) dict2 atoms (2-char codes)
36
+ * [dictSize+D, end) dict2 ngrams (2-char codes)
37
+ *
38
+ * Both atom dicts decode before any ngram, and dict2 ngrams decode before
39
+ * dict1 ngrams. So every ngram entry references slots whose contents are
40
+ * already filled — no forward references to handle.
41
+ *
42
+ * This runs on library import. Flat typed arrays store each slot as either
43
+ * a plain value (`single`, covering every atom) or a range in a shared
44
+ * `pool` (ngrams).
45
+ * @param input Packed trie string.
46
+ * @param resultLength Expected number of uint16 values in the output.
47
+ * @param atomCount Total number of distinct uint16 values in the trie.
48
+ * @param dict1AtomCount Atoms in the 1-char range (`A` above).
49
+ * @param ngramCount Total number of ngram entries (dict1 + dict2).
50
+ * @param dictSize Number of 1-char code slots; the rest of `BASE - dictSize`
51
+ * first-byte values are 2-char codes.
52
+ */
53
+ export function decodeTrieDict(
54
+ input: string,
55
+ resultLength: number,
56
+ atomCount: number,
57
+ dict1AtomCount: number,
58
+ ngramCount: number,
59
+ dictSize: number,
60
+ ): Uint16Array {
61
+ const base = 91;
62
+ const inputLength = input.length;
63
+ // For 2-char codes, slot = char1 * base - twoCharBias + char2.
64
+ const twoCharBias = dictSize * (base - 1);
65
+
66
+ let pos = 0;
67
+
68
+ /** Read one slot code at `pos` and return its slot index, advancing pos. */
69
+ const readSlotCode = (): number => {
70
+ const c1 = BASE91_INVERSE[input.charCodeAt(pos++)];
71
+ return c1 < dictSize
72
+ ? c1
73
+ : c1 * base - twoCharBias + BASE91_INVERSE[input.charCodeAt(pos++)];
74
+ };
75
+
76
+ const dict2AtomCount = atomCount - dict1AtomCount;
77
+ const slotCount = atomCount + ngramCount;
78
+
79
+ /*
80
+ * Per-slot contents: atoms (always a single value) live directly in
81
+ * `single`; ngram slots hold -1 there and expand to
82
+ * `pool[start[slot] .. start[slot] + length[slot])`.
83
+ */
84
+ const single = new Int32Array(slotCount);
85
+ single.fill(-1, dict1AtomCount, dictSize);
86
+ single.fill(-1, dictSize + dict2AtomCount, slotCount);
87
+ const start = new Int32Array(slotCount);
88
+ const length = new Int32Array(slotCount);
89
+
90
+ /**
91
+ * Decode `count` ascending uint16 values from a delta+RLE stream into
92
+ * `single[off..off+count)`.
93
+ *
94
+ * code < 89 → delta = code
95
+ * code == 89 → run-length: next char encodes runLength-2; emit `runLength` consecutive +1 values
96
+ * code == 90, next < 90 → escape: delta = 89 + next * BASE + after-next
97
+ * code == 90, next == 90 → double-escape: extra char for very large deltas
98
+ * @param count
99
+ * @param off
100
+ */
101
+ function decodeDelta(count: number, off: number): void {
102
+ let previous = 0;
103
+ let slot = off;
104
+ const end = off + count;
105
+ while (slot < end) {
106
+ const code = BASE91_INVERSE[input.charCodeAt(pos++)];
107
+ if (code < 89) {
108
+ previous += code;
109
+ single[slot++] = previous;
110
+ } else if (code === 89) {
111
+ let runLength = BASE91_INVERSE[input.charCodeAt(pos++)] + 2;
112
+ while (runLength--) single[slot++] = ++previous;
113
+ } else {
114
+ const next = BASE91_INVERSE[input.charCodeAt(pos++)];
115
+ previous +=
116
+ 89 +
117
+ // eslint-disable-next-line unicorn/prefer-minimal-ternary -- branches read a different number of side-effecting input bytes
118
+ (next < 90
119
+ ? next * base + BASE91_INVERSE[input.charCodeAt(pos++)]
120
+ : BASE91_INVERSE[input.charCodeAt(pos++)] * 8281 +
121
+ BASE91_INVERSE[input.charCodeAt(pos++)] * base +
122
+ BASE91_INVERSE[input.charCodeAt(pos++)]);
123
+ single[slot++] = previous;
124
+ }
125
+ }
126
+ }
127
+
128
+ // Streams 1 & 2: atoms decoded into their slot ranges.
129
+ decodeDelta(dict1AtomCount, 0);
130
+ decodeDelta(dict2AtomCount, dictSize);
131
+
132
+ /*
133
+ * Streams 3 & 4 are read in two passes: first collect every ngram's two
134
+ * references and derive its expanded length (each ref resolves to an earlier
135
+ * slot, so lengths are already known), which sizes the shared pool.
136
+ * Pool ranges are handed out in decode order, so the second pass fills
137
+ * the pool contiguously with a single write cursor.
138
+ */
139
+ const references = new Int32Array(ngramCount * 2);
140
+ let poolSize = 0;
141
+ let ngramIndex = 0;
142
+
143
+ /**
144
+ * Read `count` ngram entries (each = 2 slot-code references) for the slots
145
+ * starting at `startSlot`, recording references and assigning pool ranges.
146
+ * @param count
147
+ * @param startSlot
148
+ */
149
+ function readNgramReferences(count: number, startSlot: number): void {
150
+ for (let index = 0; index < count; index++) {
151
+ const slot = startSlot + index;
152
+ const a = readSlotCode();
153
+ const b = readSlotCode();
154
+ references[ngramIndex * 2] = a;
155
+ references[ngramIndex * 2 + 1] = b;
156
+ ngramIndex += 1;
157
+ start[slot] = poolSize;
158
+ const entryLength =
159
+ (single[a] < 0 ? length[a] : 1) +
160
+ (single[b] < 0 ? length[b] : 1);
161
+ length[slot] = entryLength;
162
+ poolSize += entryLength;
163
+ }
164
+ }
165
+ readNgramReferences(
166
+ ngramCount - dictSize + dict1AtomCount,
167
+ dictSize + dict2AtomCount,
168
+ );
169
+ readNgramReferences(dictSize - dict1AtomCount, dict1AtomCount);
170
+
171
+ // Second pass: concatenate each ngram's two halves into the pool.
172
+ const pool = new Uint16Array(poolSize);
173
+ let write = 0;
174
+ for (let index = 0; index < ngramIndex; index++) {
175
+ for (let half = 0; half < 2; half++) {
176
+ const source = references[index * 2 + half];
177
+ const value = single[source];
178
+ if (value < 0) {
179
+ let read = start[source];
180
+ const readEnd = read + length[source];
181
+ while (read < readEnd) pool[write++] = pool[read++];
182
+ } else {
183
+ pool[write++] = value;
184
+ }
185
+ }
186
+ }
187
+
188
+ // Stream 5: data. Each code expands to its slot's stored values.
189
+ const out = new Uint16Array(resultLength);
190
+ let outIndex = 0;
191
+ while (pos < inputLength) {
192
+ let slot = BASE91_INVERSE[input.charCodeAt(pos++)];
193
+ if (slot >= dictSize) {
194
+ slot =
195
+ slot * base -
196
+ twoCharBias +
197
+ BASE91_INVERSE[input.charCodeAt(pos++)];
198
+ }
199
+ const value = single[slot];
200
+ if (value < 0) {
201
+ let read = start[slot];
202
+ const readEnd = read + length[slot];
203
+ while (read < readEnd) out[outIndex++] = pool[read++];
204
+ } else {
205
+ out[outIndex++] = value;
206
+ }
207
+ }
29
208
  return out;
30
209
  }
package/decode.d.ts DELETED
@@ -1,3 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-ignore
3
- export * from "./dist/commonjs/decode.js";
package/decode.js DELETED
@@ -1,3 +0,0 @@
1
- // Make exports work in Node < 12
2
- // eslint-disable-next-line no-undef, unicorn/prefer-module
3
- module.exports = require("./dist/commonjs/decode.js");
@@ -1,19 +0,0 @@
1
- /**
2
- * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
3
- */
4
- export declare const fromCodePoint: (...codePoints: number[]) => string;
5
- /**
6
- * Replace the given code point with a replacement character if it is a
7
- * surrogate or is outside the valid range. Otherwise return the code
8
- * point unchanged.
9
- */
10
- export declare function replaceCodePoint(codePoint: number): number;
11
- /**
12
- * Replace the code point if relevant, then convert it to a string.
13
- *
14
- * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.
15
- * @param codePoint The code point to decode.
16
- * @returns The decoded code point.
17
- */
18
- export declare function decodeCodePoint(codePoint: number): string;
19
- //# sourceMappingURL=decode-codepoint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode-codepoint.d.ts","sourceRoot":"","sources":["../../src/decode-codepoint.ts"],"names":[],"mappings":"AAkCA;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,KAAK,MAgBnD,CAAC;AAEP;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS1D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzD"}
@@ -1,77 +0,0 @@
1
- "use strict";
2
- // Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
3
- var _a;
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.fromCodePoint = void 0;
6
- exports.replaceCodePoint = replaceCodePoint;
7
- exports.decodeCodePoint = decodeCodePoint;
8
- const decodeMap = new Map([
9
- [0, 65533],
10
- // C1 Unicode control character reference replacements
11
- [128, 8364],
12
- [130, 8218],
13
- [131, 402],
14
- [132, 8222],
15
- [133, 8230],
16
- [134, 8224],
17
- [135, 8225],
18
- [136, 710],
19
- [137, 8240],
20
- [138, 352],
21
- [139, 8249],
22
- [140, 338],
23
- [142, 381],
24
- [145, 8216],
25
- [146, 8217],
26
- [147, 8220],
27
- [148, 8221],
28
- [149, 8226],
29
- [150, 8211],
30
- [151, 8212],
31
- [152, 732],
32
- [153, 8482],
33
- [154, 353],
34
- [155, 8250],
35
- [156, 339],
36
- [158, 382],
37
- [159, 376],
38
- ]);
39
- /**
40
- * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
41
- */
42
- exports.fromCodePoint =
43
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, n/no-unsupported-features/es-builtins
44
- (_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : ((codePoint) => {
45
- let output = "";
46
- if (codePoint > 65535) {
47
- codePoint -= 65536;
48
- output += String.fromCharCode(((codePoint >>> 10) & 1023) | 55296);
49
- codePoint = 56320 | (codePoint & 1023);
50
- }
51
- output += String.fromCharCode(codePoint);
52
- return output;
53
- });
54
- /**
55
- * Replace the given code point with a replacement character if it is a
56
- * surrogate or is outside the valid range. Otherwise return the code
57
- * point unchanged.
58
- */
59
- function replaceCodePoint(codePoint) {
60
- var _a;
61
- if ((codePoint >= 55296 && codePoint <= 57343) ||
62
- codePoint > 1114111) {
63
- return 65533;
64
- }
65
- return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
66
- }
67
- /**
68
- * Replace the code point if relevant, then convert it to a string.
69
- *
70
- * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.
71
- * @param codePoint The code point to decode.
72
- * @returns The decoded code point.
73
- */
74
- function decodeCodePoint(codePoint) {
75
- return (0, exports.fromCodePoint)(replaceCodePoint(codePoint));
76
- }
77
- //# sourceMappingURL=decode-codepoint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode-codepoint.js","sourceRoot":"","sources":["../../src/decode-codepoint.ts"],"names":[],"mappings":";AAAA,qHAAqH;;;;AA4DrH,4CASC;AASD,0CAEC;AA9ED,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACtB,CAAC,CAAC,EAAE,KAAM,CAAC;IACX,sDAAsD;IACtD,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,E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Only allow entities terminated with a semicolon. */
5
- Strict = 1,
6
- /** Entities in attributes have limitations on ending characters. */
7
- Attribute = 2
8
- }
9
- /**
10
- * Producers for character reference errors as defined in the HTML spec.
11
- */
12
- export interface EntityErrorProducer {
13
- missingSemicolonAfterCharacterReference(): void;
14
- absenceOfDigitsInNumericCharacterReference(consumedCharacters: number): void;
15
- validateNumericCharacterReference(code: number): void;
16
- }
17
- /**
18
- * Token decoder with support of writing partial entities.
19
- */
20
- export declare class EntityDecoder {
21
- /** The tree used to decode entities. */
22
- private readonly decodeTree;
23
- /**
24
- * The function that is called when a codepoint is decoded.
25
- *
26
- * For multi-byte named entities, this will be called multiple times,
27
- * with the second codepoint, and the same `consumed` value.
28
- *
29
- * @param codepoint The decoded codepoint.
30
- * @param consumed The number of bytes consumed by the decoder.
31
- */
32
- private readonly emitCodePoint;
33
- /** An object that is used to produce errors. */
34
- private readonly errors?;
35
- constructor(
36
- /** The tree used to decode entities. */
37
- decodeTree: Uint16Array,
38
- /**
39
- * The function that is called when a codepoint is decoded.
40
- *
41
- * For multi-byte named entities, this will be called multiple times,
42
- * with the second codepoint, and the same `consumed` value.
43
- *
44
- * @param codepoint The decoded codepoint.
45
- * @param consumed The number of bytes consumed by the decoder.
46
- */
47
- emitCodePoint: (cp: number, consumed: number) => void,
48
- /** An object that is used to produce errors. */
49
- errors?: EntityErrorProducer | undefined);
50
- /** The current state of the decoder. */
51
- private state;
52
- /** Characters that were consumed while parsing an entity. */
53
- private consumed;
54
- /**
55
- * The result of the entity.
56
- *
57
- * Either the result index of a numeric entity, or the codepoint of a
58
- * numeric entity.
59
- */
60
- private result;
61
- /** The current index in the decode tree. */
62
- private treeIndex;
63
- /** The number of characters that were consumed in excess. */
64
- private excess;
65
- /** The mode in which the decoder is operating. */
66
- private decodeMode;
67
- /** The number of characters that have been consumed in the current run. */
68
- private runConsumed;
69
- /** Resets the instance to make it reusable. */
70
- startEntity(decodeMode: DecodingMode): void;
71
- /**
72
- * Write an entity to the decoder. This can be called multiple times with partial entities.
73
- * If the entity is incomplete, the decoder will return -1.
74
- *
75
- * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
76
- * entity is incomplete, and resume when the next string is written.
77
- *
78
- * @param input The string containing the entity (or a continuation of the entity).
79
- * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
80
- * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
81
- */
82
- write(input: string, offset: number): number;
83
- /**
84
- * Switches between the numeric decimal and hexadecimal states.
85
- *
86
- * Equivalent to the `Numeric character reference state` in the HTML spec.
87
- *
88
- * @param input The string containing the entity (or a continuation of the entity).
89
- * @param offset The current offset.
90
- * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
91
- */
92
- private stateNumericStart;
93
- /**
94
- * Parses a hexadecimal numeric entity.
95
- *
96
- * Equivalent to the `Hexademical character reference state` in the HTML spec.
97
- *
98
- * @param input The string containing the entity (or a continuation of the entity).
99
- * @param offset The current offset.
100
- * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
101
- */
102
- private stateNumericHex;
103
- /**
104
- * Parses a decimal numeric entity.
105
- *
106
- * Equivalent to the `Decimal character reference state` in the HTML spec.
107
- *
108
- * @param input The string containing the entity (or a continuation of the entity).
109
- * @param offset The current offset.
110
- * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
111
- */
112
- private stateNumericDecimal;
113
- /**
114
- * Validate and emit a numeric entity.
115
- *
116
- * Implements the logic from the `Hexademical character reference start
117
- * state` and `Numeric character reference end state` in the HTML spec.
118
- *
119
- * @param lastCp The last code point of the entity. Used to see if the
120
- * entity was terminated with a semicolon.
121
- * @param expectedLength The minimum number of characters that should be
122
- * consumed. Used to validate that at least one digit
123
- * was consumed.
124
- * @returns The number of characters that were consumed.
125
- */
126
- private emitNumericEntity;
127
- /**
128
- * Parses a named entity.
129
- *
130
- * Equivalent to the `Named character reference state` in the HTML spec.
131
- *
132
- * @param input The string containing the entity (or a continuation of the entity).
133
- * @param offset The current offset.
134
- * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
135
- */
136
- private stateNamedEntity;
137
- /**
138
- * Emit a named entity that was not terminated with a semicolon.
139
- *
140
- * @returns The number of characters consumed.
141
- */
142
- private emitNotTerminatedNamedEntity;
143
- /**
144
- * Emit a named entity.
145
- *
146
- * @param result The index of the entity in the decode tree.
147
- * @param valueLength The number of bytes in the entity.
148
- * @param consumed The number of characters consumed.
149
- *
150
- * @returns The number of characters consumed.
151
- */
152
- private emitNamedEntityData;
153
- /**
154
- * Signal to the parser that the end of the input was reached.
155
- *
156
- * Remaining data will be emitted and relevant errors will be produced.
157
- *
158
- * @returns The number of characters consumed.
159
- */
160
- end(): number;
161
- }
162
- /**
163
- * Determines the branch of the current node that is taken given the current
164
- * character. This function is used to traverse the trie.
165
- *
166
- * @param decodeTree The trie.
167
- * @param current The current node.
168
- * @param nodeIdx The index right after the current node and its value.
169
- * @param char The current character.
170
- * @returns The index of the next node, or -1 if no branch is taken.
171
- */
172
- export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIndex: number, char: number): number;
173
- /**
174
- * Decodes an HTML string.
175
- *
176
- * @param htmlString The string to decode.
177
- * @param mode The decoding mode.
178
- * @returns The decoded string.
179
- */
180
- export declare function decodeHTML(htmlString: string, mode?: DecodingMode): string;
181
- /**
182
- * Decodes an HTML string in an attribute.
183
- *
184
- * @param htmlAttribute The string to decode.
185
- * @returns The decoded string.
186
- */
187
- export declare function decodeHTMLAttribute(htmlAttribute: string): string;
188
- /**
189
- * Decodes an HTML string, requiring all entities to be terminated by a semicolon.
190
- *
191
- * @param htmlString The string to decode.
192
- * @returns The decoded string.
193
- */
194
- export declare function decodeHTMLStrict(htmlString: string): string;
195
- /**
196
- * Decodes an XML string, requiring all entities to be terminated by a semicolon.
197
- *
198
- * @param xmlString The string to decode.
199
- * @returns The decoded string.
200
- */
201
- export declare function decodeXML(xmlString: string): string;
202
- export { decodeCodePoint, fromCodePoint, replaceCodePoint, } from "./decode-codepoint.js";
203
- export { htmlDecodeTree } from "./generated/decode-data-html.js";
204
- export { xmlDecodeTree } from "./generated/decode-data-xml.js";
205
- //# sourceMappingURL=decode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AA4DA,oBAAY,YAAY;IACpB,8DAA8D;IAC9D,MAAM,IAAI;IACV,uDAAuD;IACvD,MAAM,IAAI;IACV,oEAAoE;IACpE,SAAS,IAAI;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,uCAAuC,IAAI,IAAI,CAAC;IAChD,0CAA0C,CACtC,kBAAkB,EAAE,MAAM,GAC3B,IAAI,CAAC;IACR,iCAAiC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACzD;AAED;;GAEG;AACH,qBAAa,aAAa;IAElB,wCAAwC;IAExC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;;IAdxB,wCAAwC;IAEvB,UAAU,EAAE,WAAW;IACxC;;;;;;;;OAQG;IACc,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI;IACtE,gDAAgD;IAC/B,MAAM,CAAC,EAAE,mBAAmB,GAAG,SAAS;IAG7D,wCAAwC;IACxC,OAAO,CAAC,KAAK,CAAkC;IAC/C,6DAA6D;IAC7D,OAAO,CAAC,QAAQ,CAAK;IACrB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAK;IAEnB,4CAA4C;IAC5C,OAAO,CAAC,SAAS,CAAK;IACtB,6DAA6D;IAC7D,OAAO,CAAC,MAAM,CAAK;IACnB,kDAAkD;IAClD,OAAO,CAAC,UAAU,CAAuB;IACzC,2EAA2E;IAC3E,OAAO,CAAC,WAAW,CAAK;IAExB,+CAA+C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