entities 4.4.0 → 5.0.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 (120) hide show
  1. package/dist/commonjs/decode-codepoint.d.ts +19 -0
  2. package/dist/commonjs/decode-codepoint.d.ts.map +1 -0
  3. package/{lib/decode_codepoint.js → dist/commonjs/decode-codepoint.js} +30 -13
  4. package/dist/commonjs/decode-codepoint.js.map +1 -0
  5. package/dist/commonjs/decode.d.ts +209 -0
  6. package/dist/commonjs/decode.d.ts.map +1 -0
  7. package/dist/commonjs/decode.js +514 -0
  8. package/dist/commonjs/decode.js.map +1 -0
  9. package/{lib/esm → dist/commonjs}/encode.d.ts +2 -2
  10. package/dist/commonjs/encode.d.ts.map +1 -0
  11. package/{lib → dist/commonjs}/encode.js +32 -33
  12. package/dist/commonjs/encode.js.map +1 -0
  13. package/{lib/esm → dist/commonjs}/escape.d.ts +2 -2
  14. package/dist/commonjs/escape.d.ts.map +1 -0
  15. package/{lib → dist/commonjs}/escape.js +46 -38
  16. package/dist/commonjs/escape.js.map +1 -0
  17. package/dist/commonjs/generated/decode-data-html.d.ts.map +1 -0
  18. package/{lib → dist/commonjs}/generated/decode-data-html.js +1 -1
  19. package/dist/commonjs/generated/decode-data-html.js.map +1 -0
  20. package/dist/commonjs/generated/decode-data-xml.d.ts.map +1 -0
  21. package/{lib → dist/commonjs}/generated/decode-data-xml.js +1 -1
  22. package/dist/commonjs/generated/decode-data-xml.js.map +1 -0
  23. package/{lib/esm → dist/commonjs}/generated/encode-html.d.ts +1 -1
  24. package/dist/commonjs/generated/encode-html.d.ts.map +1 -0
  25. package/{lib → dist/commonjs}/generated/encode-html.js +4 -4
  26. package/dist/commonjs/generated/encode-html.js.map +1 -0
  27. package/{lib/esm → dist/commonjs}/index.d.ts +9 -15
  28. package/dist/commonjs/index.d.ts.map +1 -0
  29. package/{lib → dist/commonjs}/index.js +46 -55
  30. package/dist/commonjs/index.js.map +1 -0
  31. package/dist/commonjs/package.json +3 -0
  32. package/dist/esm/decode-codepoint.d.ts +19 -0
  33. package/dist/esm/decode-codepoint.d.ts.map +1 -0
  34. package/{lib/esm/decode_codepoint.js → dist/esm/decode-codepoint.js} +25 -8
  35. package/dist/esm/decode-codepoint.js.map +1 -0
  36. package/dist/esm/decode.d.ts +209 -0
  37. package/dist/esm/decode.d.ts.map +1 -0
  38. package/dist/esm/decode.js +497 -0
  39. package/dist/esm/decode.js.map +1 -0
  40. package/{lib → dist/esm}/encode.d.ts +2 -2
  41. package/dist/esm/encode.d.ts.map +1 -0
  42. package/{lib → dist}/esm/encode.js +25 -25
  43. package/dist/esm/encode.js.map +1 -0
  44. package/{lib → dist/esm}/escape.d.ts +2 -2
  45. package/dist/esm/escape.d.ts.map +1 -0
  46. package/{lib → dist}/esm/escape.js +39 -29
  47. package/dist/esm/escape.js.map +1 -0
  48. package/dist/esm/generated/decode-data-html.d.ts.map +1 -0
  49. package/dist/esm/generated/decode-data-html.js.map +1 -0
  50. package/dist/esm/generated/decode-data-xml.d.ts.map +1 -0
  51. package/dist/esm/generated/decode-data-xml.js.map +1 -0
  52. package/{lib → dist/esm}/generated/encode-html.d.ts +1 -1
  53. package/dist/esm/generated/encode-html.d.ts.map +1 -0
  54. package/{lib → dist}/esm/generated/encode-html.js +4 -4
  55. package/dist/esm/generated/encode-html.js.map +1 -0
  56. package/{lib → dist/esm}/index.d.ts +9 -15
  57. package/dist/esm/index.d.ts.map +1 -0
  58. package/{lib → dist}/esm/index.js +36 -45
  59. package/dist/esm/index.js.map +1 -0
  60. package/dist/esm/package.json +3 -0
  61. package/package.json +96 -66
  62. package/readme.md +5 -5
  63. package/src/decode-codepoint.ts +81 -0
  64. package/src/decode.spec.ts +320 -0
  65. package/src/decode.ts +620 -0
  66. package/src/encode.spec.ts +78 -0
  67. package/src/encode.ts +77 -0
  68. package/src/escape.spec.ts +14 -0
  69. package/src/escape.ts +144 -0
  70. package/src/generated/.eslintrc.json +10 -0
  71. package/src/generated/decode-data-html.ts +8 -0
  72. package/src/generated/decode-data-xml.ts +8 -0
  73. package/src/generated/encode-html.ts +17 -0
  74. package/src/index.spec.ts +125 -0
  75. package/src/index.ts +185 -0
  76. package/lib/decode.d.ts +0 -33
  77. package/lib/decode.d.ts.map +0 -1
  78. package/lib/decode.js +0 -179
  79. package/lib/decode.js.map +0 -1
  80. package/lib/decode_codepoint.d.ts +0 -4
  81. package/lib/decode_codepoint.d.ts.map +0 -1
  82. package/lib/decode_codepoint.js.map +0 -1
  83. package/lib/encode.d.ts.map +0 -1
  84. package/lib/encode.js.map +0 -1
  85. package/lib/escape.d.ts.map +0 -1
  86. package/lib/escape.js.map +0 -1
  87. package/lib/esm/decode.d.ts +0 -33
  88. package/lib/esm/decode.d.ts.map +0 -1
  89. package/lib/esm/decode.js +0 -166
  90. package/lib/esm/decode.js.map +0 -1
  91. package/lib/esm/decode_codepoint.d.ts +0 -4
  92. package/lib/esm/decode_codepoint.d.ts.map +0 -1
  93. package/lib/esm/decode_codepoint.js.map +0 -1
  94. package/lib/esm/encode.d.ts.map +0 -1
  95. package/lib/esm/encode.js.map +0 -1
  96. package/lib/esm/escape.d.ts.map +0 -1
  97. package/lib/esm/escape.js.map +0 -1
  98. package/lib/esm/generated/decode-data-html.d.ts.map +0 -1
  99. package/lib/esm/generated/decode-data-html.js.map +0 -1
  100. package/lib/esm/generated/decode-data-xml.d.ts.map +0 -1
  101. package/lib/esm/generated/decode-data-xml.js.map +0 -1
  102. package/lib/esm/generated/encode-html.d.ts.map +0 -1
  103. package/lib/esm/generated/encode-html.js.map +0 -1
  104. package/lib/esm/index.d.ts.map +0 -1
  105. package/lib/esm/index.js.map +0 -1
  106. package/lib/esm/package.json +0 -1
  107. package/lib/generated/decode-data-html.d.ts.map +0 -1
  108. package/lib/generated/decode-data-html.js.map +0 -1
  109. package/lib/generated/decode-data-xml.d.ts.map +0 -1
  110. package/lib/generated/decode-data-xml.js.map +0 -1
  111. package/lib/generated/encode-html.d.ts.map +0 -1
  112. package/lib/generated/encode-html.js.map +0 -1
  113. package/lib/index.d.ts.map +0 -1
  114. package/lib/index.js.map +0 -1
  115. /package/{lib/esm → dist/commonjs}/generated/decode-data-html.d.ts +0 -0
  116. /package/{lib/esm → dist/commonjs}/generated/decode-data-xml.d.ts +0 -0
  117. /package/{lib → dist/esm}/generated/decode-data-html.d.ts +0 -0
  118. /package/{lib → dist}/esm/generated/decode-data-html.js +0 -0
  119. /package/{lib → dist/esm}/generated/decode-data-xml.d.ts +0 -0
  120. /package/{lib → dist}/esm/generated/decode-data-xml.js +0 -0
package/src/index.ts ADDED
@@ -0,0 +1,185 @@
1
+ import { decodeXML, decodeHTML, DecodingMode } from "./decode.js";
2
+ import { encodeHTML, encodeNonAsciiHTML } from "./encode.js";
3
+ import {
4
+ encodeXML,
5
+ escapeUTF8,
6
+ escapeAttribute,
7
+ escapeText,
8
+ } from "./escape.js";
9
+
10
+ /** The level of entities to support. */
11
+ export enum EntityLevel {
12
+ /** Support only XML entities. */
13
+ XML = 0,
14
+ /** Support HTML entities, which are a superset of XML entities. */
15
+ HTML = 1,
16
+ }
17
+
18
+ export enum EncodingMode {
19
+ /**
20
+ * The output is UTF-8 encoded. Only characters that need escaping within
21
+ * XML will be escaped.
22
+ */
23
+ UTF8,
24
+ /**
25
+ * The output consists only of ASCII characters. Characters that need
26
+ * escaping within HTML, and characters that aren't ASCII characters will
27
+ * be escaped.
28
+ */
29
+ ASCII,
30
+ /**
31
+ * Encode all characters that have an equivalent entity, as well as all
32
+ * characters that are not ASCII characters.
33
+ */
34
+ Extensive,
35
+ /**
36
+ * Encode all characters that have to be escaped in HTML attributes,
37
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
38
+ */
39
+ Attribute,
40
+ /**
41
+ * Encode all characters that have to be escaped in HTML text,
42
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
43
+ */
44
+ Text,
45
+ }
46
+
47
+ export interface DecodingOptions {
48
+ /**
49
+ * The level of entities to support.
50
+ * @default {@link EntityLevel.XML}
51
+ */
52
+ level?: EntityLevel;
53
+ /**
54
+ * Decoding mode. If `Legacy`, will support legacy entities not terminated
55
+ * with a semicolon (`;`).
56
+ *
57
+ * Always `Strict` for XML. For HTML, set this to `true` if you are parsing
58
+ * an attribute value.
59
+ *
60
+ * The deprecated `decodeStrict` function defaults this to `Strict`.
61
+ *
62
+ * @default {@link DecodingMode.Legacy}
63
+ */
64
+ mode?: DecodingMode | undefined;
65
+ }
66
+
67
+ /**
68
+ * Decodes a string with entities.
69
+ *
70
+ * @param input String to decode.
71
+ * @param options Decoding options.
72
+ */
73
+ export function decode(
74
+ input: string,
75
+ options: DecodingOptions | EntityLevel = EntityLevel.XML,
76
+ ): string {
77
+ const level = typeof options === "number" ? options : options.level;
78
+
79
+ if (level === EntityLevel.HTML) {
80
+ const mode = typeof options === "object" ? options.mode : undefined;
81
+ return decodeHTML(input, mode);
82
+ }
83
+
84
+ return decodeXML(input);
85
+ }
86
+
87
+ /**
88
+ * Decodes a string with entities. Does not allow missing trailing semicolons for entities.
89
+ *
90
+ * @param input String to decode.
91
+ * @param options Decoding options.
92
+ * @deprecated Use `decode` with the `mode` set to `Strict`.
93
+ */
94
+ export function decodeStrict(
95
+ input: string,
96
+ options: DecodingOptions | EntityLevel = EntityLevel.XML,
97
+ ): string {
98
+ const normalizedOptions =
99
+ typeof options === "number" ? { level: options } : options;
100
+ normalizedOptions.mode ??= DecodingMode.Strict;
101
+
102
+ return decode(input, normalizedOptions);
103
+ }
104
+
105
+ /**
106
+ * Options for `encode`.
107
+ */
108
+ export interface EncodingOptions {
109
+ /**
110
+ * The level of entities to support.
111
+ * @default {@link EntityLevel.XML}
112
+ */
113
+ level?: EntityLevel;
114
+ /**
115
+ * Output format.
116
+ * @default {@link EncodingMode.Extensive}
117
+ */
118
+ mode?: EncodingMode;
119
+ }
120
+
121
+ /**
122
+ * Encodes a string with entities.
123
+ *
124
+ * @param input String to encode.
125
+ * @param options Encoding options.
126
+ */
127
+ export function encode(
128
+ input: string,
129
+ options: EncodingOptions | EntityLevel = EntityLevel.XML,
130
+ ): string {
131
+ const { mode = EncodingMode.Extensive, level = EntityLevel.XML } =
132
+ typeof options === "number" ? { level: options } : options;
133
+
134
+ switch (mode) {
135
+ case EncodingMode.UTF8: {
136
+ return escapeUTF8(input);
137
+ }
138
+ case EncodingMode.Attribute: {
139
+ return escapeAttribute(input);
140
+ }
141
+ case EncodingMode.Text: {
142
+ return escapeText(input);
143
+ }
144
+ default: {
145
+ if (level === EntityLevel.HTML) {
146
+ if (mode === EncodingMode.ASCII) {
147
+ return encodeNonAsciiHTML(input);
148
+ }
149
+ return encodeHTML(input);
150
+ }
151
+ return encodeXML(input);
152
+ }
153
+ }
154
+ }
155
+
156
+ export {
157
+ encodeXML,
158
+ escape,
159
+ escapeUTF8,
160
+ escapeAttribute,
161
+ escapeText,
162
+ } from "./escape.js";
163
+
164
+ export {
165
+ encodeHTML,
166
+ encodeNonAsciiHTML,
167
+ // Legacy aliases (deprecated)
168
+ encodeHTML as encodeHTML4,
169
+ encodeHTML as encodeHTML5,
170
+ } from "./encode.js";
171
+
172
+ export {
173
+ EntityDecoder,
174
+ DecodingMode,
175
+ decodeXML,
176
+ decodeHTML,
177
+ decodeHTMLStrict,
178
+ decodeHTMLAttribute,
179
+ // Legacy aliases (deprecated)
180
+ decodeHTML as decodeHTML4,
181
+ decodeHTML as decodeHTML5,
182
+ decodeHTMLStrict as decodeHTML4Strict,
183
+ decodeHTMLStrict as decodeHTML5Strict,
184
+ decodeXML as decodeXMLStrict,
185
+ } from "./decode.js";
package/lib/decode.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import htmlDecodeTree from "./generated/decode-data-html.js";
2
- import xmlDecodeTree from "./generated/decode-data-xml.js";
3
- import decodeCodePoint from "./decode_codepoint.js";
4
- export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };
5
- export { replaceCodePoint, fromCodePoint } from "./decode_codepoint.js";
6
- export declare enum BinTrieFlags {
7
- VALUE_LENGTH = 49152,
8
- BRANCH_LENGTH = 16256,
9
- JUMP_TABLE = 127
10
- }
11
- export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIdx: number, char: number): number;
12
- /**
13
- * Decodes an HTML string, allowing for entities not terminated by a semi-colon.
14
- *
15
- * @param str The string to decode.
16
- * @returns The decoded string.
17
- */
18
- export declare function decodeHTML(str: string): string;
19
- /**
20
- * Decodes an HTML string, requiring all entities to be terminated by a semi-colon.
21
- *
22
- * @param str The string to decode.
23
- * @returns The decoded string.
24
- */
25
- export declare function decodeHTMLStrict(str: string): string;
26
- /**
27
- * Decodes an XML string, requiring all entities to be terminated by a semi-colon.
28
- *
29
- * @param str The string to decode.
30
- * @returns The decoded string.
31
- */
32
- export declare function decodeXML(str: string): string;
33
- //# sourceMappingURL=decode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAC7D,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAcxE,oBAAY,YAAY;IACpB,YAAY,QAAwB;IACpC,aAAa,QAAwB;IACrC,UAAU,MAAwB;CACrC;AA8GD,wBAAgB,eAAe,CAC3B,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACb,MAAM,CAsCR;AAKD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
package/lib/decode.js DELETED
@@ -1,179 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.BinTrieFlags = exports.fromCodePoint = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
7
- var decode_data_html_js_1 = __importDefault(require("./generated/decode-data-html.js"));
8
- exports.htmlDecodeTree = decode_data_html_js_1.default;
9
- var decode_data_xml_js_1 = __importDefault(require("./generated/decode-data-xml.js"));
10
- exports.xmlDecodeTree = decode_data_xml_js_1.default;
11
- var decode_codepoint_js_1 = __importDefault(require("./decode_codepoint.js"));
12
- exports.decodeCodePoint = decode_codepoint_js_1.default;
13
- var decode_codepoint_js_2 = require("./decode_codepoint.js");
14
- Object.defineProperty(exports, "replaceCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.replaceCodePoint; } });
15
- Object.defineProperty(exports, "fromCodePoint", { enumerable: true, get: function () { return decode_codepoint_js_2.fromCodePoint; } });
16
- var CharCodes;
17
- (function (CharCodes) {
18
- CharCodes[CharCodes["NUM"] = 35] = "NUM";
19
- CharCodes[CharCodes["SEMI"] = 59] = "SEMI";
20
- CharCodes[CharCodes["ZERO"] = 48] = "ZERO";
21
- CharCodes[CharCodes["NINE"] = 57] = "NINE";
22
- CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A";
23
- CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F";
24
- CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X";
25
- /** Bit that needs to be set to convert an upper case ASCII character to lower case */
26
- CharCodes[CharCodes["To_LOWER_BIT"] = 32] = "To_LOWER_BIT";
27
- })(CharCodes || (CharCodes = {}));
28
- var BinTrieFlags;
29
- (function (BinTrieFlags) {
30
- BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
31
- BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH";
32
- BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
33
- })(BinTrieFlags = exports.BinTrieFlags || (exports.BinTrieFlags = {}));
34
- function getDecoder(decodeTree) {
35
- return function decodeHTMLBinary(str, strict) {
36
- var ret = "";
37
- var lastIdx = 0;
38
- var strIdx = 0;
39
- while ((strIdx = str.indexOf("&", strIdx)) >= 0) {
40
- ret += str.slice(lastIdx, strIdx);
41
- lastIdx = strIdx;
42
- // Skip the "&"
43
- strIdx += 1;
44
- // If we have a numeric entity, handle this separately.
45
- if (str.charCodeAt(strIdx) === CharCodes.NUM) {
46
- // Skip the leading "&#". For hex entities, also skip the leading "x".
47
- var start = strIdx + 1;
48
- var base = 10;
49
- var cp = str.charCodeAt(start);
50
- if ((cp | CharCodes.To_LOWER_BIT) === CharCodes.LOWER_X) {
51
- base = 16;
52
- strIdx += 1;
53
- start += 1;
54
- }
55
- do
56
- cp = str.charCodeAt(++strIdx);
57
- while ((cp >= CharCodes.ZERO && cp <= CharCodes.NINE) ||
58
- (base === 16 &&
59
- (cp | CharCodes.To_LOWER_BIT) >= CharCodes.LOWER_A &&
60
- (cp | CharCodes.To_LOWER_BIT) <= CharCodes.LOWER_F));
61
- if (start !== strIdx) {
62
- var entity = str.substring(start, strIdx);
63
- var parsed = parseInt(entity, base);
64
- if (str.charCodeAt(strIdx) === CharCodes.SEMI) {
65
- strIdx += 1;
66
- }
67
- else if (strict) {
68
- continue;
69
- }
70
- ret += (0, decode_codepoint_js_1.default)(parsed);
71
- lastIdx = strIdx;
72
- }
73
- continue;
74
- }
75
- var resultIdx = 0;
76
- var excess = 1;
77
- var treeIdx = 0;
78
- var current = decodeTree[treeIdx];
79
- for (; strIdx < str.length; strIdx++, excess++) {
80
- treeIdx = determineBranch(decodeTree, current, treeIdx + 1, str.charCodeAt(strIdx));
81
- if (treeIdx < 0)
82
- break;
83
- current = decodeTree[treeIdx];
84
- var masked = current & BinTrieFlags.VALUE_LENGTH;
85
- // If the branch is a value, store it and continue
86
- if (masked) {
87
- // If we have a legacy entity while parsing strictly, just skip the number of bytes
88
- if (!strict || str.charCodeAt(strIdx) === CharCodes.SEMI) {
89
- resultIdx = treeIdx;
90
- excess = 0;
91
- }
92
- // The mask is the number of bytes of the value, including the current byte.
93
- var valueLength = (masked >> 14) - 1;
94
- if (valueLength === 0)
95
- break;
96
- treeIdx += valueLength;
97
- }
98
- }
99
- if (resultIdx !== 0) {
100
- var valueLength = (decodeTree[resultIdx] & BinTrieFlags.VALUE_LENGTH) >> 14;
101
- ret +=
102
- valueLength === 1
103
- ? String.fromCharCode(decodeTree[resultIdx] & ~BinTrieFlags.VALUE_LENGTH)
104
- : valueLength === 2
105
- ? String.fromCharCode(decodeTree[resultIdx + 1])
106
- : String.fromCharCode(decodeTree[resultIdx + 1], decodeTree[resultIdx + 2]);
107
- lastIdx = strIdx - excess + 1;
108
- }
109
- }
110
- return ret + str.slice(lastIdx);
111
- };
112
- }
113
- function determineBranch(decodeTree, current, nodeIdx, char) {
114
- var branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
115
- var jumpOffset = current & BinTrieFlags.JUMP_TABLE;
116
- // Case 1: Single branch encoded in jump offset
117
- if (branchCount === 0) {
118
- return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1;
119
- }
120
- // Case 2: Multiple branches encoded in jump table
121
- if (jumpOffset) {
122
- var value = char - jumpOffset;
123
- return value < 0 || value >= branchCount
124
- ? -1
125
- : decodeTree[nodeIdx + value] - 1;
126
- }
127
- // Case 3: Multiple branches encoded in dictionary
128
- // Binary search for the character.
129
- var lo = nodeIdx;
130
- var hi = lo + branchCount - 1;
131
- while (lo <= hi) {
132
- var mid = (lo + hi) >>> 1;
133
- var midVal = decodeTree[mid];
134
- if (midVal < char) {
135
- lo = mid + 1;
136
- }
137
- else if (midVal > char) {
138
- hi = mid - 1;
139
- }
140
- else {
141
- return decodeTree[mid + branchCount];
142
- }
143
- }
144
- return -1;
145
- }
146
- exports.determineBranch = determineBranch;
147
- var htmlDecoder = getDecoder(decode_data_html_js_1.default);
148
- var xmlDecoder = getDecoder(decode_data_xml_js_1.default);
149
- /**
150
- * Decodes an HTML string, allowing for entities not terminated by a semi-colon.
151
- *
152
- * @param str The string to decode.
153
- * @returns The decoded string.
154
- */
155
- function decodeHTML(str) {
156
- return htmlDecoder(str, false);
157
- }
158
- exports.decodeHTML = decodeHTML;
159
- /**
160
- * Decodes an HTML string, requiring all entities to be terminated by a semi-colon.
161
- *
162
- * @param str The string to decode.
163
- * @returns The decoded string.
164
- */
165
- function decodeHTMLStrict(str) {
166
- return htmlDecoder(str, true);
167
- }
168
- exports.decodeHTMLStrict = decodeHTMLStrict;
169
- /**
170
- * Decodes an XML string, requiring all entities to be terminated by a semi-colon.
171
- *
172
- * @param str The string to decode.
173
- * @returns The decoded string.
174
- */
175
- function decodeXML(str) {
176
- return xmlDecoder(str, true);
177
- }
178
- exports.decodeXML = decodeXML;
179
- //# sourceMappingURL=decode.js.map
package/lib/decode.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["decode.ts"],"names":[],"mappings":";;;;;;AAAA,wFAA6D;AAKpD,yBALF,6BAAc,CAKE;AAJvB,sFAA2D;AAIlC,wBAJlB,4BAAa,CAIkB;AAHtC,8EAAoD;AAGZ,0BAHjC,6BAAe,CAGiC;AACvD,6DAAwE;AAA/D,uHAAA,gBAAgB,OAAA;AAAE,oHAAA,aAAa,OAAA;AAExC,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CC;AAED,IAAM,WAAW,GAAG,UAAU,CAAC,6BAAc,CAAC,CAAC;AAC/C,IAAM,UAAU,GAAG,UAAU,CAAC,4BAAa,CAAC,CAAC;AAE7C;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,GAAW;IAClC,OAAO,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAFD,gCAEC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,GAAW;IACxC,OAAO,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAFD,4CAEC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,GAAW;IACjC,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAFD,8BAEC"}
@@ -1,4 +0,0 @@
1
- export declare const fromCodePoint: (...codePoints: number[]) => string;
2
- export declare function replaceCodePoint(codePoint: number): number;
3
- export default function decodeCodePoint(codePoint: number): string;
4
- //# sourceMappingURL=decode_codepoint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["decode_codepoint.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,aAAa,qCAgBrB,CAAC;AAEN,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,UAMjD;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode_codepoint.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["decode_codepoint.ts"],"names":[],"mappings":";AAAA,qHAAqH;;;;AAErH,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACtB,CAAC,CAAC,EAAE,KAAK,CAAC;IACV,CAAC,GAA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,MAAM,CACxC,CAAC;QACF,SAAS,GAAG,MAAM,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;KAC5C;IAED,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEN,SAAgB,gBAAgB,CAAC,SAAiB;;IAC9C,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,CAAC,IAAI,SAAS,GAAG,QAAQ,EAAE;QACtE,OAAO,MAAM,CAAC;KACjB;IAED,OAAO,MAAA,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,mCAAI,SAAS,CAAC;AACjD,CAAC;AAND,4CAMC;AAED,SAAwB,eAAe,CAAC,SAAiB;IACrD,OAAO,IAAA,qBAAa,EAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;AACtD,CAAC;AAFD,kCAEC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["encode.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AACD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD"}
package/lib/encode.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"encode.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["encode.ts"],"names":[],"mappings":";;;;;;AAAA,8EAAkD;AAClD,yCAAwD;AAExD,IAAM,YAAY,GAAG,qCAAqC,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CAAC,IAAY;IACnC,OAAO,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AA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Z;aACJ;YAED,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;SACjB;QAED,6EAA6E;QAC7E,IAAI,IAAI,KAAK,SAAS,EAAE;YACpB,GAAG,IAAI,IAAI,CAAC;YACZ,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;SACnB;aAAM;YACH,IAAM,EAAE,GAAG,IAAA,wBAAY,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAChC,GAAG,IAAI,aAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAG,CAAC;YAChC,4CAA4C;YAC5C,OAAO,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;SACrD;KACJ;IAED,OAAO,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"escape.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["escape.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAyB,CAAC;AAWlD,eAAO,MAAM,YAAY,QAGT,MAAM,SAAS,MAAM,KAAG,MAQD,CAAC;AAExC;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA0B7C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,kBAAY,CAAC;AA2BhC;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,SA7Bb,MAAM,KAAK,MA6BuC,CAAC;AAE7D;;;;;GAKG;AACH,eAAO,MAAM,eAAe,SArClB,MAAM,KAAK,MA4CpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,SApDb,MAAM,KAAK,MA4DpB,CAAC"}
package/lib/escape.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"escape.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709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C,CAAE,CAAC;YAE3C,kCAAkC;YAClC,OAAO,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;SAC7B;QAED,OAAO,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC,CAAC;AACN,CAAC;AAED;;;;;;GAMG;AACU,QAAA,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAE7D;;;;;GAKG;AACU,QAAA,eAAe,GAAG,UAAU,CACrC,aAAa,EACb,IAAI,GAAG,CAAC;IACJ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,GAAG,EAAE,QAAQ,CAAC;CAClB,CAAC,CACL,CAAC;AAEF;;;;;GAKG;AACU,QAAA,UAAU,GAAG,UAAU,CAChC,cAAc,EACd,IAAI,GAAG,CAAC;IACJ,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,QAAQ,CAAC;CAClB,CAAC,CACL,CAAC"}
@@ -1,33 +0,0 @@
1
- import htmlDecodeTree from "./generated/decode-data-html.js";
2
- import xmlDecodeTree from "./generated/decode-data-xml.js";
3
- import decodeCodePoint from "./decode_codepoint.js";
4
- export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };
5
- export { replaceCodePoint, fromCodePoint } from "./decode_codepoint.js";
6
- export declare enum BinTrieFlags {
7
- VALUE_LENGTH = 49152,
8
- BRANCH_LENGTH = 16256,
9
- JUMP_TABLE = 127
10
- }
11
- export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIdx: number, char: number): number;
12
- /**
13
- * Decodes an HTML string, allowing for entities not terminated by a semi-colon.
14
- *
15
- * @param str The string to decode.
16
- * @returns The decoded string.
17
- */
18
- export declare function decodeHTML(str: string): string;
19
- /**
20
- * Decodes an HTML string, requiring all entities to be terminated by a semi-colon.
21
- *
22
- * @param str The string to decode.
23
- * @returns The decoded string.
24
- */
25
- export declare function decodeHTMLStrict(str: string): string;
26
- /**
27
- * Decodes an XML string, requiring all entities to be terminated by a semi-colon.
28
- *
29
- * @param str The string to decode.
30
- * @returns The decoded string.
31
- */
32
- export declare function decodeXML(str: string): string;
33
- //# sourceMappingURL=decode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/867ac709ba482a56a98b7c35f49ca833c74dc193/src/","sources":["decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAC7D,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAcxE,oBAAY,YAAY;IACpB,YAAY,QAAwB;IACpC,aAAa,QAAwB;IACrC,UAAU,MAAwB;CACrC;AA8GD,wBAAgB,eAAe,CAC3B,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACb,MAAM,CAsCR;AAKD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
package/lib/esm/decode.js DELETED
@@ -1,166 +0,0 @@
1
- import htmlDecodeTree from "./generated/decode-data-html.js";
2
- import xmlDecodeTree from "./generated/decode-data-xml.js";
3
- import decodeCodePoint from "./decode_codepoint.js";
4
- // Re-export for use by eg. htmlparser2
5
- export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };
6
- export { replaceCodePoint, fromCodePoint } from "./decode_codepoint.js";
7
- var CharCodes;
8
- (function (CharCodes) {
9
- CharCodes[CharCodes["NUM"] = 35] = "NUM";
10
- CharCodes[CharCodes["SEMI"] = 59] = "SEMI";
11
- CharCodes[CharCodes["ZERO"] = 48] = "ZERO";
12
- CharCodes[CharCodes["NINE"] = 57] = "NINE";
13
- CharCodes[CharCodes["LOWER_A"] = 97] = "LOWER_A";
14
- CharCodes[CharCodes["LOWER_F"] = 102] = "LOWER_F";
15
- CharCodes[CharCodes["LOWER_X"] = 120] = "LOWER_X";
16
- /** Bit that needs to be set to convert an upper case ASCII character to lower case */
17
- CharCodes[CharCodes["To_LOWER_BIT"] = 32] = "To_LOWER_BIT";
18
- })(CharCodes || (CharCodes = {}));
19
- export var BinTrieFlags;
20
- (function (BinTrieFlags) {
21
- BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
22
- BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH";
23
- BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
24
- })(BinTrieFlags || (BinTrieFlags = {}));
25
- function getDecoder(decodeTree) {
26
- return function decodeHTMLBinary(str, strict) {
27
- let ret = "";
28
- let lastIdx = 0;
29
- let strIdx = 0;
30
- while ((strIdx = str.indexOf("&", strIdx)) >= 0) {
31
- ret += str.slice(lastIdx, strIdx);
32
- lastIdx = strIdx;
33
- // Skip the "&"
34
- strIdx += 1;
35
- // If we have a numeric entity, handle this separately.
36
- if (str.charCodeAt(strIdx) === CharCodes.NUM) {
37
- // Skip the leading "&#". For hex entities, also skip the leading "x".
38
- let start = strIdx + 1;
39
- let base = 10;
40
- let cp = str.charCodeAt(start);
41
- if ((cp | CharCodes.To_LOWER_BIT) === CharCodes.LOWER_X) {
42
- base = 16;
43
- strIdx += 1;
44
- start += 1;
45
- }
46
- do
47
- cp = str.charCodeAt(++strIdx);
48
- while ((cp >= CharCodes.ZERO && cp <= CharCodes.NINE) ||
49
- (base === 16 &&
50
- (cp | CharCodes.To_LOWER_BIT) >= CharCodes.LOWER_A &&
51
- (cp | CharCodes.To_LOWER_BIT) <= CharCodes.LOWER_F));
52
- if (start !== strIdx) {
53
- const entity = str.substring(start, strIdx);
54
- const parsed = parseInt(entity, base);
55
- if (str.charCodeAt(strIdx) === CharCodes.SEMI) {
56
- strIdx += 1;
57
- }
58
- else if (strict) {
59
- continue;
60
- }
61
- ret += decodeCodePoint(parsed);
62
- lastIdx = strIdx;
63
- }
64
- continue;
65
- }
66
- let resultIdx = 0;
67
- let excess = 1;
68
- let treeIdx = 0;
69
- let current = decodeTree[treeIdx];
70
- for (; strIdx < str.length; strIdx++, excess++) {
71
- treeIdx = determineBranch(decodeTree, current, treeIdx + 1, str.charCodeAt(strIdx));
72
- if (treeIdx < 0)
73
- break;
74
- current = decodeTree[treeIdx];
75
- const masked = current & BinTrieFlags.VALUE_LENGTH;
76
- // If the branch is a value, store it and continue
77
- if (masked) {
78
- // If we have a legacy entity while parsing strictly, just skip the number of bytes
79
- if (!strict || str.charCodeAt(strIdx) === CharCodes.SEMI) {
80
- resultIdx = treeIdx;
81
- excess = 0;
82
- }
83
- // The mask is the number of bytes of the value, including the current byte.
84
- const valueLength = (masked >> 14) - 1;
85
- if (valueLength === 0)
86
- break;
87
- treeIdx += valueLength;
88
- }
89
- }
90
- if (resultIdx !== 0) {
91
- const valueLength = (decodeTree[resultIdx] & BinTrieFlags.VALUE_LENGTH) >> 14;
92
- ret +=
93
- valueLength === 1
94
- ? String.fromCharCode(decodeTree[resultIdx] & ~BinTrieFlags.VALUE_LENGTH)
95
- : valueLength === 2
96
- ? String.fromCharCode(decodeTree[resultIdx + 1])
97
- : String.fromCharCode(decodeTree[resultIdx + 1], decodeTree[resultIdx + 2]);
98
- lastIdx = strIdx - excess + 1;
99
- }
100
- }
101
- return ret + str.slice(lastIdx);
102
- };
103
- }
104
- export function determineBranch(decodeTree, current, nodeIdx, char) {
105
- const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
106
- const jumpOffset = current & BinTrieFlags.JUMP_TABLE;
107
- // Case 1: Single branch encoded in jump offset
108
- if (branchCount === 0) {
109
- return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1;
110
- }
111
- // Case 2: Multiple branches encoded in jump table
112
- if (jumpOffset) {
113
- const value = char - jumpOffset;
114
- return value < 0 || value >= branchCount
115
- ? -1
116
- : decodeTree[nodeIdx + value] - 1;
117
- }
118
- // Case 3: Multiple branches encoded in dictionary
119
- // Binary search for the character.
120
- let lo = nodeIdx;
121
- let hi = lo + branchCount - 1;
122
- while (lo <= hi) {
123
- const mid = (lo + hi) >>> 1;
124
- const midVal = decodeTree[mid];
125
- if (midVal < char) {
126
- lo = mid + 1;
127
- }
128
- else if (midVal > char) {
129
- hi = mid - 1;
130
- }
131
- else {
132
- return decodeTree[mid + branchCount];
133
- }
134
- }
135
- return -1;
136
- }
137
- const htmlDecoder = getDecoder(htmlDecodeTree);
138
- const xmlDecoder = getDecoder(xmlDecodeTree);
139
- /**
140
- * Decodes an HTML string, allowing for entities not terminated by a semi-colon.
141
- *
142
- * @param str The string to decode.
143
- * @returns The decoded string.
144
- */
145
- export function decodeHTML(str) {
146
- return htmlDecoder(str, false);
147
- }
148
- /**
149
- * Decodes an HTML string, requiring all entities to be terminated by a semi-colon.
150
- *
151
- * @param str The string to decode.
152
- * @returns The decoded string.
153
- */
154
- export function decodeHTMLStrict(str) {
155
- return htmlDecoder(str, true);
156
- }
157
- /**
158
- * Decodes an XML string, requiring all entities to be terminated by a semi-colon.
159
- *
160
- * @param str The string to decode.
161
- * @returns The decoded string.
162
- */
163
- export function decodeXML(str) {
164
- return xmlDecoder(str, true);
165
- }
166
- //# sourceMappingURL=decode.js.map