entities 2.2.0 → 4.3.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 (71) hide show
  1. package/lib/decode.d.ts +14 -4
  2. package/lib/decode.d.ts.map +1 -1
  3. package/lib/decode.js +150 -42
  4. package/lib/decode.js.map +1 -0
  5. package/lib/decode_codepoint.d.ts +2 -0
  6. package/lib/decode_codepoint.d.ts.map +1 -1
  7. package/lib/decode_codepoint.js +54 -24
  8. package/lib/decode_codepoint.js.map +1 -0
  9. package/lib/encode.d.ts +2 -29
  10. package/lib/encode.d.ts.map +1 -1
  11. package/lib/encode.js +47 -108
  12. package/lib/encode.js.map +1 -0
  13. package/lib/escape.d.ts +43 -0
  14. package/lib/escape.d.ts.map +1 -0
  15. package/lib/escape.js +112 -0
  16. package/lib/escape.js.map +1 -0
  17. package/lib/esm/decode.d.ts +15 -0
  18. package/lib/esm/decode.d.ts.map +1 -0
  19. package/lib/esm/decode.js +148 -0
  20. package/lib/esm/decode.js.map +1 -0
  21. package/lib/esm/decode_codepoint.d.ts +4 -0
  22. package/lib/esm/decode_codepoint.d.ts.map +1 -0
  23. package/lib/esm/decode_codepoint.js +55 -0
  24. package/lib/esm/decode_codepoint.js.map +1 -0
  25. package/lib/esm/encode.d.ts +20 -0
  26. package/lib/esm/encode.d.ts.map +1 -0
  27. package/lib/esm/encode.js +67 -0
  28. package/lib/esm/encode.js.map +1 -0
  29. package/lib/esm/escape.d.ts +43 -0
  30. package/lib/esm/escape.d.ts.map +1 -0
  31. package/lib/esm/escape.js +106 -0
  32. package/lib/esm/escape.js.map +1 -0
  33. package/lib/esm/generated/decode-data-html.d.ts +3 -0
  34. package/lib/esm/generated/decode-data-html.d.ts.map +1 -0
  35. package/lib/esm/generated/decode-data-html.js +4 -0
  36. package/lib/esm/generated/decode-data-html.js.map +1 -0
  37. package/lib/esm/generated/decode-data-xml.d.ts +3 -0
  38. package/lib/esm/generated/decode-data-xml.d.ts.map +1 -0
  39. package/lib/esm/generated/decode-data-xml.js +4 -0
  40. package/lib/esm/generated/decode-data-xml.js.map +1 -0
  41. package/lib/esm/generated/encode-html.d.ts +8 -0
  42. package/lib/esm/generated/encode-html.d.ts.map +1 -0
  43. package/lib/esm/generated/encode-html.js +4 -0
  44. package/lib/esm/generated/encode-html.js.map +1 -0
  45. package/lib/esm/index.d.ts +102 -0
  46. package/lib/esm/index.d.ts.map +1 -0
  47. package/lib/esm/index.js +113 -0
  48. package/lib/esm/index.js.map +1 -0
  49. package/lib/esm/package.json +1 -0
  50. package/lib/generated/decode-data-html.d.ts +3 -0
  51. package/lib/generated/decode-data-html.d.ts.map +1 -0
  52. package/lib/generated/decode-data-html.js +6 -0
  53. package/lib/generated/decode-data-html.js.map +1 -0
  54. package/lib/generated/decode-data-xml.d.ts +3 -0
  55. package/lib/generated/decode-data-xml.d.ts.map +1 -0
  56. package/lib/generated/decode-data-xml.js +6 -0
  57. package/lib/generated/decode-data-xml.js.map +1 -0
  58. package/lib/generated/encode-html.d.ts +8 -0
  59. package/lib/generated/encode-html.d.ts.map +1 -0
  60. package/lib/generated/encode-html.js +6 -0
  61. package/lib/generated/encode-html.js.map +1 -0
  62. package/lib/index.d.ts +86 -11
  63. package/lib/index.d.ts.map +1 -1
  64. package/lib/index.js +112 -32
  65. package/lib/index.js.map +1 -0
  66. package/package.json +44 -17
  67. package/readme.md +78 -13
  68. package/lib/maps/decode.json +0 -1
  69. package/lib/maps/entities.json +0 -1
  70. package/lib/maps/legacy.json +0 -1
  71. package/lib/maps/xml.json +0 -1
package/lib/escape.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.getCodePoint = exports.xmlReplacer = void 0;
4
+ exports.xmlReplacer = /["&'<>$\x80-\uFFFF]/g;
5
+ var xmlCodeMap = new Map([
6
+ [34, "&quot;"],
7
+ [38, "&amp;"],
8
+ [39, "&apos;"],
9
+ [60, "&lt;"],
10
+ [62, "&gt;"],
11
+ ]);
12
+ // For compatibility with node < 4, we wrap `codePointAt`
13
+ exports.getCodePoint =
14
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15
+ String.prototype.codePointAt != null
16
+ ? function (str, index) { return str.codePointAt(index); }
17
+ : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
18
+ function (c, index) {
19
+ return (c.charCodeAt(index) & 0xfc00) === 0xd800
20
+ ? (c.charCodeAt(index) - 0xd800) * 0x400 +
21
+ c.charCodeAt(index + 1) -
22
+ 0xdc00 +
23
+ 0x10000
24
+ : c.charCodeAt(index);
25
+ };
26
+ /**
27
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
28
+ * documents using XML entities.
29
+ *
30
+ * If a character has no equivalent entity, a
31
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
32
+ */
33
+ function encodeXML(str) {
34
+ var ret = "";
35
+ var lastIdx = 0;
36
+ var match;
37
+ while ((match = exports.xmlReplacer.exec(str)) !== null) {
38
+ var i = match.index;
39
+ var char = str.charCodeAt(i);
40
+ var next = xmlCodeMap.get(char);
41
+ if (next !== undefined) {
42
+ ret += str.substring(lastIdx, i) + next;
43
+ lastIdx = i + 1;
44
+ }
45
+ else {
46
+ ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, exports.getCodePoint)(str, i).toString(16), ";");
47
+ // Increase by 1 if we have a surrogate pair
48
+ lastIdx = exports.xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800);
49
+ }
50
+ }
51
+ return ret + str.substr(lastIdx);
52
+ }
53
+ exports.encodeXML = encodeXML;
54
+ /**
55
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
56
+ * documents using numeric hexadecimal reference (eg. `&#xfc;`).
57
+ *
58
+ * Have a look at `escapeUTF8` if you want a more concise output at the expense
59
+ * of reduced transportability.
60
+ *
61
+ * @param data String to escape.
62
+ */
63
+ exports.escape = encodeXML;
64
+ function getEscaper(regex, map) {
65
+ return function escape(data) {
66
+ var match;
67
+ var lastIdx = 0;
68
+ var result = "";
69
+ while ((match = regex.exec(data))) {
70
+ if (lastIdx !== match.index) {
71
+ result += data.substring(lastIdx, match.index);
72
+ }
73
+ // We know that this chararcter will be in the map.
74
+ result += map.get(match[0].charCodeAt(0));
75
+ // Every match will be of length 1
76
+ lastIdx = match.index + 1;
77
+ }
78
+ return result + data.substring(lastIdx);
79
+ };
80
+ }
81
+ /**
82
+ * Encodes all characters not valid in XML documents using XML entities.
83
+ *
84
+ * Note that the output will be character-set dependent.
85
+ *
86
+ * @param data String to escape.
87
+ */
88
+ exports.escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap);
89
+ /**
90
+ * Encodes all characters that have to be escaped in HTML attributes,
91
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
92
+ *
93
+ * @param data String to escape.
94
+ */
95
+ exports.escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([
96
+ [34, "&quot;"],
97
+ [38, "&amp;"],
98
+ [160, "&nbsp;"],
99
+ ]));
100
+ /**
101
+ * Encodes all characters that have to be escaped in HTML text,
102
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
103
+ *
104
+ * @param data String to escape.
105
+ */
106
+ exports.escapeText = getEscaper(/[&<>\u00A0]/g, new Map([
107
+ [38, "&amp;"],
108
+ [60, "&lt;"],
109
+ [62, "&gt;"],
110
+ [160, "&nbsp;"],
111
+ ]));
112
+ //# sourceMappingURL=escape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/src/","sources":["escape.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,sBAAsB,CAAC;AAElD,IAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACvB,CAAC,EAAE,EAAE,QAAQ,C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AC;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"}
@@ -0,0 +1,15 @@
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
+ export declare function decodeHTML(str: string): string;
13
+ export declare function decodeHTMLStrict(str: string): string;
14
+ export declare function decodeXML(str: string): string;
15
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/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,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
@@ -0,0 +1,148 @@
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
+ export function decodeHTML(str) {
140
+ return htmlDecoder(str, false);
141
+ }
142
+ export function decodeHTMLStrict(str) {
143
+ return htmlDecoder(str, true);
144
+ }
145
+ export function decodeXML(str) {
146
+ return xmlDecoder(str, true);
147
+ }
148
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/src/","sources":["decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAC7D,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAExE,IAAW,SAUV;AAVD,WAAW,SAAS;IAChB,wCAAQ,CAAA;IACR,0CAAS,CAAA;IACT,0CAAS,CAAA;IACT,0CAAS,CAAA;IACT,gDAAY,CAAA;IACZ,iDAAa,CAAA;IACb,iDAAa,CAAA;IACb,sFAAsF;IACtF,0DAAuB,CAAA;AAC3B,CAAC,EAVU,SAAS,KAAT,SAAS,QAUnB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OAAO,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW;IACjC,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,4 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/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"}
@@ -0,0 +1,55 @@
1
+ // Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
2
+ var _a;
3
+ const decodeMap = new Map([
4
+ [0, 65533],
5
+ [128, 8364],
6
+ [130, 8218],
7
+ [131, 402],
8
+ [132, 8222],
9
+ [133, 8230],
10
+ [134, 8224],
11
+ [135, 8225],
12
+ [136, 710],
13
+ [137, 8240],
14
+ [138, 352],
15
+ [139, 8249],
16
+ [140, 338],
17
+ [142, 381],
18
+ [145, 8216],
19
+ [146, 8217],
20
+ [147, 8220],
21
+ [148, 8221],
22
+ [149, 8226],
23
+ [150, 8211],
24
+ [151, 8212],
25
+ [152, 732],
26
+ [153, 8482],
27
+ [154, 353],
28
+ [155, 8250],
29
+ [156, 339],
30
+ [158, 382],
31
+ [159, 376],
32
+ ]);
33
+ export const fromCodePoint =
34
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
35
+ (_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) {
36
+ let output = "";
37
+ if (codePoint > 0xffff) {
38
+ codePoint -= 0x10000;
39
+ output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
40
+ codePoint = 0xdc00 | (codePoint & 0x3ff);
41
+ }
42
+ output += String.fromCharCode(codePoint);
43
+ return output;
44
+ };
45
+ export function replaceCodePoint(codePoint) {
46
+ var _a;
47
+ if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
48
+ return 0xfffd;
49
+ }
50
+ return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
51
+ }
52
+ export default function decodeCodePoint(codePoint) {
53
+ return fromCodePoint(replaceCodePoint(codePoint));
54
+ }
55
+ //# sourceMappingURL=decode_codepoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode_codepoint.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/src/","sources":["decode_codepoint.ts"],"names":[],"mappings":"AAAA,qHAAqH;;AAErH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACtB,CAAC,CAAC,EAAE,KAAK,CAAC;IACV,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,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CAAC,SAAS,CAAC,mCAAI,SAAS,CAAC;AACjD,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAiB;IACrD,OAAO,aAAa,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Encodes all entities and non-ASCII characters in the input.
3
+ *
4
+ * This includes characters that are valid ASCII characters in HTML documents.
5
+ * For example `#` will be encoded as `&num;`. To get a more compact output,
6
+ * consider using the `encodeNonAsciiHTML` function.
7
+ *
8
+ * If a character has no equivalent entity, a
9
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
10
+ */
11
+ export declare function encodeHTML(data: string): string;
12
+ /**
13
+ * Encodes all non-ASCII characters, as well as characters not valid in HTML
14
+ * documents using HTML entities.
15
+ *
16
+ * If a character has no equivalent entity, a
17
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
18
+ */
19
+ export declare function encodeNonAsciiHTML(data: string): string;
20
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/src/","sources":["encode.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AACD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD"}
@@ -0,0 +1,67 @@
1
+ import htmlTrie from "./generated/encode-html.js";
2
+ import { xmlReplacer, getCodePoint } from "./escape.js";
3
+ const htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;
4
+ /**
5
+ * Encodes all entities and non-ASCII characters in the input.
6
+ *
7
+ * This includes characters that are valid ASCII characters in HTML documents.
8
+ * For example `#` will be encoded as `&num;`. To get a more compact output,
9
+ * consider using the `encodeNonAsciiHTML` function.
10
+ *
11
+ * If a character has no equivalent entity, a
12
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
13
+ */
14
+ export function encodeHTML(data) {
15
+ return encodeHTMLTrieRe(htmlReplacer, data);
16
+ }
17
+ /**
18
+ * Encodes all non-ASCII characters, as well as characters not valid in HTML
19
+ * documents using HTML entities.
20
+ *
21
+ * If a character has no equivalent entity, a
22
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
23
+ */
24
+ export function encodeNonAsciiHTML(data) {
25
+ return encodeHTMLTrieRe(xmlReplacer, data);
26
+ }
27
+ function encodeHTMLTrieRe(regExp, str) {
28
+ let ret = "";
29
+ let lastIdx = 0;
30
+ let match;
31
+ while ((match = regExp.exec(str)) !== null) {
32
+ const i = match.index;
33
+ ret += str.substring(lastIdx, i);
34
+ const char = str.charCodeAt(i);
35
+ let next = htmlTrie.get(char);
36
+ if (typeof next === "object") {
37
+ // We are in a branch. Try to match the next char.
38
+ if (i + 1 < str.length) {
39
+ const nextChar = str.charCodeAt(i + 1);
40
+ const value = typeof next.n === "number"
41
+ ? next.n === nextChar
42
+ ? next.o
43
+ : undefined
44
+ : next.n.get(nextChar);
45
+ if (value !== undefined) {
46
+ ret += value;
47
+ lastIdx = regExp.lastIndex += 1;
48
+ continue;
49
+ }
50
+ }
51
+ next = next.v;
52
+ }
53
+ // We might have a tree node without a value; skip and use a numeric entitiy.
54
+ if (next !== undefined) {
55
+ ret += next;
56
+ lastIdx = i + 1;
57
+ }
58
+ else {
59
+ const cp = getCodePoint(str, i);
60
+ ret += `&#x${cp.toString(16)};`;
61
+ // Increase by 1 if we have a surrogate pair
62
+ lastIdx = regExp.lastIndex += Number(cp !== char);
63
+ }
64
+ }
65
+ return ret + str.substr(lastIdx);
66
+ }
67
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3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;wBACjB,CAAC,CAAC,IAAI,CAAC,CAAC;wBACR,CAAC,CAAC,SAAS;oBACf,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAE/B,IAAI,KAAK,KAAK,SAAS,EAAE;oBACrB,GAAG,IAAI,KAAK,CAAC;oBACb,OAAO,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;oBAChC,SAAS;iBACZ;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,MAAM,EAAE,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAChC,GAAG,IAAI,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,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"}
@@ -0,0 +1,43 @@
1
+ export declare const xmlReplacer: RegExp;
2
+ export declare const getCodePoint: (str: string, index: number) => number;
3
+ /**
4
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
5
+ * documents using XML entities.
6
+ *
7
+ * If a character has no equivalent entity, a
8
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
9
+ */
10
+ export declare function encodeXML(str: string): string;
11
+ /**
12
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
13
+ * documents using numeric hexadecimal reference (eg. `&#xfc;`).
14
+ *
15
+ * Have a look at `escapeUTF8` if you want a more concise output at the expense
16
+ * of reduced transportability.
17
+ *
18
+ * @param data String to escape.
19
+ */
20
+ export declare const escape: typeof encodeXML;
21
+ /**
22
+ * Encodes all characters not valid in XML documents using XML entities.
23
+ *
24
+ * Note that the output will be character-set dependent.
25
+ *
26
+ * @param data String to escape.
27
+ */
28
+ export declare const escapeUTF8: (data: string) => string;
29
+ /**
30
+ * Encodes all characters that have to be escaped in HTML attributes,
31
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
32
+ *
33
+ * @param data String to escape.
34
+ */
35
+ export declare const escapeAttribute: (data: string) => string;
36
+ /**
37
+ * Encodes all characters that have to be escaped in HTML text,
38
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
39
+ *
40
+ * @param data String to escape.
41
+ */
42
+ export declare const escapeText: (data: string) => string;
43
+ //# sourceMappingURL=escape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/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"}
@@ -0,0 +1,106 @@
1
+ export const xmlReplacer = /["&'<>$\x80-\uFFFF]/g;
2
+ const xmlCodeMap = new Map([
3
+ [34, "&quot;"],
4
+ [38, "&amp;"],
5
+ [39, "&apos;"],
6
+ [60, "&lt;"],
7
+ [62, "&gt;"],
8
+ ]);
9
+ // For compatibility with node < 4, we wrap `codePointAt`
10
+ export const getCodePoint =
11
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
+ String.prototype.codePointAt != null
13
+ ? (str, index) => str.codePointAt(index)
14
+ : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
15
+ (c, index) => (c.charCodeAt(index) & 0xfc00) === 0xd800
16
+ ? (c.charCodeAt(index) - 0xd800) * 0x400 +
17
+ c.charCodeAt(index + 1) -
18
+ 0xdc00 +
19
+ 0x10000
20
+ : c.charCodeAt(index);
21
+ /**
22
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
23
+ * documents using XML entities.
24
+ *
25
+ * If a character has no equivalent entity, a
26
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
27
+ */
28
+ export function encodeXML(str) {
29
+ let ret = "";
30
+ let lastIdx = 0;
31
+ let match;
32
+ while ((match = xmlReplacer.exec(str)) !== null) {
33
+ const i = match.index;
34
+ const char = str.charCodeAt(i);
35
+ const next = xmlCodeMap.get(char);
36
+ if (next !== undefined) {
37
+ ret += str.substring(lastIdx, i) + next;
38
+ lastIdx = i + 1;
39
+ }
40
+ else {
41
+ ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`;
42
+ // Increase by 1 if we have a surrogate pair
43
+ lastIdx = xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800);
44
+ }
45
+ }
46
+ return ret + str.substr(lastIdx);
47
+ }
48
+ /**
49
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
50
+ * documents using numeric hexadecimal reference (eg. `&#xfc;`).
51
+ *
52
+ * Have a look at `escapeUTF8` if you want a more concise output at the expense
53
+ * of reduced transportability.
54
+ *
55
+ * @param data String to escape.
56
+ */
57
+ export const escape = encodeXML;
58
+ function getEscaper(regex, map) {
59
+ return function escape(data) {
60
+ let match;
61
+ let lastIdx = 0;
62
+ let result = "";
63
+ while ((match = regex.exec(data))) {
64
+ if (lastIdx !== match.index) {
65
+ result += data.substring(lastIdx, match.index);
66
+ }
67
+ // We know that this chararcter will be in the map.
68
+ result += map.get(match[0].charCodeAt(0));
69
+ // Every match will be of length 1
70
+ lastIdx = match.index + 1;
71
+ }
72
+ return result + data.substring(lastIdx);
73
+ };
74
+ }
75
+ /**
76
+ * Encodes all characters not valid in XML documents using XML entities.
77
+ *
78
+ * Note that the output will be character-set dependent.
79
+ *
80
+ * @param data String to escape.
81
+ */
82
+ export const escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap);
83
+ /**
84
+ * Encodes all characters that have to be escaped in HTML attributes,
85
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
86
+ *
87
+ * @param data String to escape.
88
+ */
89
+ export const escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([
90
+ [34, "&quot;"],
91
+ [38, "&amp;"],
92
+ [160, "&nbsp;"],
93
+ ]));
94
+ /**
95
+ * Encodes all characters that have to be escaped in HTML text,
96
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
97
+ *
98
+ * @param data String to escape.
99
+ */
100
+ export const escapeText = getEscaper(/[&<>\u00A0]/g, new Map([
101
+ [38, "&amp;"],
102
+ [60, "&lt;"],
103
+ [62, "&gt;"],
104
+ [160, "&nbsp;"],
105
+ ]));
106
+ //# sourceMappingURL=escape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/src/","sources":["escape.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAElD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACvB,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE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;;;;;GAKG;AACH,MAAM,CAAC,MAAM,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;AACH,MAAM,CAAC,MAAM,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"}
@@ -0,0 +1,3 @@
1
+ declare const _default: Uint16Array;
2
+ export default _default;
3
+ //# sourceMappingURL=decode-data-html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-data-html.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/src/","sources":["generated/decode-data-html.ts"],"names":[],"mappings":";AAEA,wBAAivgE"}