entities 3.0.0 → 4.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.
- package/lib/decode.d.ts +6 -19
- package/lib/decode.d.ts.map +1 -1
- package/lib/decode.js +46 -59
- package/lib/decode.js.map +1 -0
- package/lib/decode_codepoint.d.ts +1 -0
- package/lib/decode_codepoint.d.ts.map +1 -1
- package/lib/decode_codepoint.js +9 -3
- package/lib/decode_codepoint.js.map +1 -0
- package/lib/encode-trie.d.ts +0 -5
- package/lib/encode-trie.d.ts.map +1 -1
- package/lib/encode-trie.js +28 -38
- package/lib/encode-trie.js.map +1 -0
- package/lib/encode.d.ts +15 -1
- package/lib/encode.d.ts.map +1 -1
- package/lib/encode.js +57 -58
- package/lib/encode.js.map +1 -0
- package/lib/esm/decode.d.ts +14 -0
- package/lib/esm/decode.d.ts.map +1 -0
- package/lib/esm/decode.js +135 -0
- package/lib/esm/decode.js.map +1 -0
- package/lib/esm/decode_codepoint.d.ts +3 -0
- package/lib/esm/decode_codepoint.d.ts.map +1 -0
- package/lib/esm/decode_codepoint.js +55 -0
- package/lib/esm/decode_codepoint.js.map +1 -0
- package/lib/esm/encode-trie.d.ts +3 -0
- package/lib/esm/encode-trie.d.ts.map +1 -0
- package/lib/esm/encode-trie.js +55 -0
- package/lib/esm/encode-trie.js.map +1 -0
- package/lib/esm/encode.d.ts +60 -0
- package/lib/esm/encode.d.ts.map +1 -0
- package/lib/esm/encode.js +119 -0
- package/lib/esm/encode.js.map +1 -0
- package/lib/esm/generated/decode-data-html.d.ts +3 -0
- package/lib/esm/generated/decode-data-html.d.ts.map +1 -0
- package/lib/esm/generated/decode-data-html.js +4 -0
- package/lib/esm/generated/decode-data-html.js.map +1 -0
- package/lib/esm/generated/decode-data-xml.d.ts +3 -0
- package/lib/esm/generated/decode-data-xml.d.ts.map +1 -0
- package/lib/esm/generated/decode-data-xml.js +4 -0
- package/lib/esm/generated/decode-data-xml.js.map +1 -0
- package/lib/esm/generated/encode-html.d.ts +8 -0
- package/lib/esm/generated/encode-html.d.ts.map +1 -0
- package/lib/esm/generated/encode-html.js +4 -0
- package/lib/esm/generated/encode-html.js.map +1 -0
- package/lib/esm/index.d.ts +101 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +111 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/generated/decode-data-html.d.ts.map +1 -1
- package/lib/generated/decode-data-html.js +2 -1
- package/lib/generated/decode-data-html.js.map +1 -0
- package/lib/generated/decode-data-xml.d.ts.map +1 -1
- package/lib/generated/decode-data-xml.js +2 -1
- package/lib/generated/decode-data-xml.js.map +1 -0
- package/lib/generated/encode-html.d.ts +8 -0
- package/lib/generated/encode-html.d.ts.map +1 -0
- package/lib/generated/encode-html.js +6 -0
- package/lib/generated/encode-html.js.map +1 -0
- package/lib/index.d.ts +18 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +47 -30
- package/lib/index.js.map +1 -0
- package/package.json +34 -14
- package/readme.md +61 -13
- package/lib/maps/entities.json +0 -1
- package/lib/maps/legacy.json +0 -1
- package/lib/maps/xml.json +0 -1
|
@@ -0,0 +1,135 @@
|
|
|
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 var BinTrieFlags;
|
|
7
|
+
(function (BinTrieFlags) {
|
|
8
|
+
BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
|
|
9
|
+
BinTrieFlags[BinTrieFlags["BRANCH_LENGTH"] = 16256] = "BRANCH_LENGTH";
|
|
10
|
+
BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
|
|
11
|
+
})(BinTrieFlags || (BinTrieFlags = {}));
|
|
12
|
+
function getDecoder(decodeTree) {
|
|
13
|
+
return function decodeHTMLBinary(str, strict) {
|
|
14
|
+
let ret = "";
|
|
15
|
+
let lastIdx = 0;
|
|
16
|
+
let strIdx = 0;
|
|
17
|
+
while ((strIdx = str.indexOf("&", strIdx)) >= 0) {
|
|
18
|
+
ret += str.slice(lastIdx, strIdx);
|
|
19
|
+
lastIdx = strIdx;
|
|
20
|
+
// Skip the "&"
|
|
21
|
+
strIdx += 1;
|
|
22
|
+
// If we have a numeric entity, handle this separately.
|
|
23
|
+
if (str.charCodeAt(strIdx) === 35 /* NUM */) {
|
|
24
|
+
// Skip the leading "&#". For hex entities, also skip the leading "x".
|
|
25
|
+
let start = strIdx + 1;
|
|
26
|
+
let base = 10;
|
|
27
|
+
let cp = str.charCodeAt(start);
|
|
28
|
+
if ((cp | 32 /* To_LOWER_BIT */) === 120 /* LOWER_X */) {
|
|
29
|
+
base = 16;
|
|
30
|
+
strIdx += 1;
|
|
31
|
+
start += 1;
|
|
32
|
+
}
|
|
33
|
+
do
|
|
34
|
+
cp = str.charCodeAt(++strIdx);
|
|
35
|
+
while ((cp >= 48 /* ZERO */ && cp <= 57 /* NINE */) ||
|
|
36
|
+
(base === 16 &&
|
|
37
|
+
(cp | 32 /* To_LOWER_BIT */) >= 97 /* LOWER_A */ &&
|
|
38
|
+
(cp | 32 /* To_LOWER_BIT */) <= 102 /* LOWER_F */));
|
|
39
|
+
if (start !== strIdx) {
|
|
40
|
+
const entity = str.substring(start, strIdx);
|
|
41
|
+
const parsed = parseInt(entity, base);
|
|
42
|
+
if (str.charCodeAt(strIdx) === 59 /* SEMI */) {
|
|
43
|
+
strIdx += 1;
|
|
44
|
+
}
|
|
45
|
+
else if (strict) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
ret += decodeCodePoint(parsed);
|
|
49
|
+
lastIdx = strIdx;
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
let resultIdx = 0;
|
|
54
|
+
let excess = 1;
|
|
55
|
+
let treeIdx = 0;
|
|
56
|
+
let current = decodeTree[treeIdx];
|
|
57
|
+
for (; strIdx < str.length; strIdx++, excess++) {
|
|
58
|
+
treeIdx = determineBranch(decodeTree, current, treeIdx + 1, str.charCodeAt(strIdx));
|
|
59
|
+
if (treeIdx < 0)
|
|
60
|
+
break;
|
|
61
|
+
current = decodeTree[treeIdx];
|
|
62
|
+
const masked = current & BinTrieFlags.VALUE_LENGTH;
|
|
63
|
+
// If the branch is a value, store it and continue
|
|
64
|
+
if (masked) {
|
|
65
|
+
// If we have a legacy entity while parsing strictly, just skip the number of bytes
|
|
66
|
+
if (!strict || str.charCodeAt(strIdx) === 59 /* SEMI */) {
|
|
67
|
+
resultIdx = treeIdx;
|
|
68
|
+
excess = 0;
|
|
69
|
+
}
|
|
70
|
+
// The mask is the number of bytes of the value, including the current byte.
|
|
71
|
+
const valueLength = (masked >> 14) - 1;
|
|
72
|
+
if (valueLength === 0)
|
|
73
|
+
break;
|
|
74
|
+
treeIdx += valueLength;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (resultIdx !== 0) {
|
|
78
|
+
const valueLength = (decodeTree[resultIdx] & BinTrieFlags.VALUE_LENGTH) >> 14;
|
|
79
|
+
ret +=
|
|
80
|
+
valueLength === 1
|
|
81
|
+
? String.fromCharCode(decodeTree[resultIdx] & ~BinTrieFlags.VALUE_LENGTH)
|
|
82
|
+
: valueLength === 2
|
|
83
|
+
? String.fromCharCode(decodeTree[resultIdx + 1])
|
|
84
|
+
: String.fromCharCode(decodeTree[resultIdx + 1], decodeTree[resultIdx + 2]);
|
|
85
|
+
lastIdx = strIdx - excess + 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return ret + str.slice(lastIdx);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function determineBranch(decodeTree, current, nodeIdx, char) {
|
|
92
|
+
const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
|
|
93
|
+
const jumpOffset = current & BinTrieFlags.JUMP_TABLE;
|
|
94
|
+
// Case 1: Single branch encoded in jump offset
|
|
95
|
+
if (branchCount === 0) {
|
|
96
|
+
return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1;
|
|
97
|
+
}
|
|
98
|
+
// Case 2: Multiple branches encoded in jump table
|
|
99
|
+
if (jumpOffset) {
|
|
100
|
+
const value = char - jumpOffset;
|
|
101
|
+
return value < 0 || value > branchCount
|
|
102
|
+
? -1
|
|
103
|
+
: decodeTree[nodeIdx + value] - 1;
|
|
104
|
+
}
|
|
105
|
+
// Case 3: Multiple branches encoded in dictionary
|
|
106
|
+
// Binary search for the character.
|
|
107
|
+
let lo = nodeIdx;
|
|
108
|
+
let hi = lo + branchCount - 1;
|
|
109
|
+
while (lo <= hi) {
|
|
110
|
+
const mid = (lo + hi) >>> 1;
|
|
111
|
+
const midVal = decodeTree[mid];
|
|
112
|
+
if (midVal < char) {
|
|
113
|
+
lo = mid + 1;
|
|
114
|
+
}
|
|
115
|
+
else if (midVal > char) {
|
|
116
|
+
hi = mid - 1;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return decodeTree[mid + branchCount];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return -1;
|
|
123
|
+
}
|
|
124
|
+
const htmlDecoder = getDecoder(htmlDecodeTree);
|
|
125
|
+
const xmlDecoder = getDecoder(xmlDecodeTree);
|
|
126
|
+
export function decodeHTML(str) {
|
|
127
|
+
return htmlDecoder(str, false);
|
|
128
|
+
}
|
|
129
|
+
export function decodeHTMLStrict(str) {
|
|
130
|
+
return htmlDecoder(str, true);
|
|
131
|
+
}
|
|
132
|
+
export function decodeXML(str) {
|
|
133
|
+
return xmlDecoder(str, true);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IACxC,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 @@
|
|
|
1
|
+
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["../../src/decode_codepoint.ts"],"names":[],"mappings":"AAmDA,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
|
+
const decodeMap = new Map([
|
|
3
|
+
[0, 65533],
|
|
4
|
+
[128, 8364],
|
|
5
|
+
[130, 8218],
|
|
6
|
+
[131, 402],
|
|
7
|
+
[132, 8222],
|
|
8
|
+
[133, 8230],
|
|
9
|
+
[134, 8224],
|
|
10
|
+
[135, 8225],
|
|
11
|
+
[136, 710],
|
|
12
|
+
[137, 8240],
|
|
13
|
+
[138, 352],
|
|
14
|
+
[139, 8249],
|
|
15
|
+
[140, 338],
|
|
16
|
+
[142, 381],
|
|
17
|
+
[145, 8216],
|
|
18
|
+
[146, 8217],
|
|
19
|
+
[147, 8220],
|
|
20
|
+
[148, 8221],
|
|
21
|
+
[149, 8226],
|
|
22
|
+
[150, 8211],
|
|
23
|
+
[151, 8212],
|
|
24
|
+
[152, 732],
|
|
25
|
+
[153, 8482],
|
|
26
|
+
[154, 353],
|
|
27
|
+
[155, 8250],
|
|
28
|
+
[156, 339],
|
|
29
|
+
[158, 382],
|
|
30
|
+
[159, 376],
|
|
31
|
+
]);
|
|
32
|
+
const fromCodePoint =
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
|
|
34
|
+
String.fromCodePoint ||
|
|
35
|
+
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":"","sources":["../../src/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,GA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,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;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAiB;IACrD,OAAO,aAAa,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-trie.d.ts","sourceRoot":"","sources":["../../src/encode-trie.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,QAGT,MAAM,SAAS,MAAM,KAAG,MAQD,CAAC;AAExC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA6CpE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import htmlTrie from "./generated/encode-html";
|
|
2
|
+
function isHighSurrugate(c) {
|
|
3
|
+
return (c & 64512 /* Mask */) === 55296 /* High */;
|
|
4
|
+
}
|
|
5
|
+
// For compatibility with node < 4, we wrap `codePointAt`
|
|
6
|
+
export const getCodePoint =
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
8
|
+
String.prototype.codePointAt != null
|
|
9
|
+
? (str, index) => str.codePointAt(index)
|
|
10
|
+
: // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
|
11
|
+
(c, index) => isHighSurrugate(c.charCodeAt(index))
|
|
12
|
+
? (c.charCodeAt(index) - 55296 /* High */) * 0x400 +
|
|
13
|
+
c.charCodeAt(index + 1) -
|
|
14
|
+
0xdc00 +
|
|
15
|
+
0x10000
|
|
16
|
+
: c.charCodeAt(index);
|
|
17
|
+
export function encodeHTMLTrieRe(regExp, str) {
|
|
18
|
+
var _a;
|
|
19
|
+
let ret = "";
|
|
20
|
+
let lastIdx = 0;
|
|
21
|
+
let match;
|
|
22
|
+
while ((match = regExp.exec(str)) !== null) {
|
|
23
|
+
const i = match.index;
|
|
24
|
+
const char = str.charCodeAt(i);
|
|
25
|
+
let next = htmlTrie.get(char);
|
|
26
|
+
if (next != null) {
|
|
27
|
+
if (typeof next !== "string") {
|
|
28
|
+
// We are in a branch. Try to match the next char.
|
|
29
|
+
if (i + 1 < str.length) {
|
|
30
|
+
const value = typeof next.n === "number"
|
|
31
|
+
? next.n === str.charCodeAt(i + 1)
|
|
32
|
+
? next.o
|
|
33
|
+
: null
|
|
34
|
+
: next.n.get(str.charCodeAt(i + 1));
|
|
35
|
+
if (value) {
|
|
36
|
+
ret += str.substring(lastIdx, i) + value;
|
|
37
|
+
lastIdx = regExp.lastIndex += 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// If we have a character without a value, use a numeric entitiy.
|
|
42
|
+
next = (_a = next.v) !== null && _a !== void 0 ? _a : `&#x${char.toString(16)};`;
|
|
43
|
+
}
|
|
44
|
+
ret += str.substring(lastIdx, i) + next;
|
|
45
|
+
lastIdx = i + 1;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`;
|
|
49
|
+
// Increase by 1 if we have a surrogate pair
|
|
50
|
+
lastIdx = regExp.lastIndex += Number(isHighSurrugate(char));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return ret + str.substr(lastIdx);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=encode-trie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-trie.js","sourceRoot":"","sources":["../../src/encode-trie.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAO/C,SAAS,eAAe,CAAC,CAAS;IAC9B,OAAO,CAAC,CAAC,mBAAiB,CAAC,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AAC,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC;4BAC9B,CAAC,CAAC,IAAI,CAAC,CAAC;4BACR,CAAC,CAAC,IAAI;wBACV,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBAE5C,IAAI,KAAK,EAAE;wBACP,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;wBACzC,OAAO,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;wBAChC,SAAS;qBACZ;iBACJ;gBAED,iEAAiE;gBACjE,IAAI,GAAG,MAAA,IAAI,CAAC,CAAC,mCAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;aAC/C;YAED,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;YACxC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;SACnB;aAAM;YACH,GAAG,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,YAAY,CACjD,GAAG,EACH,CAAC,CACJ,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;YAClB,4CAA4C;YAC5C,OAAO,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;SAC/D;KACJ;IAED,OAAO,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
3
|
+
* documents using XML entities.
|
|
4
|
+
*
|
|
5
|
+
* If a character has no equivalent entity, a
|
|
6
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
7
|
+
*/
|
|
8
|
+
export declare function encodeXML(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Encodes all entities and non-ASCII characters in the input.
|
|
11
|
+
*
|
|
12
|
+
* This includes characters that are valid ASCII characters in HTML documents.
|
|
13
|
+
* For example `#` will be encoded as `#`. To get a more compact output,
|
|
14
|
+
* consider using the `encodeNonAsciiHTML` function.
|
|
15
|
+
*
|
|
16
|
+
* If a character has no equivalent entity, a
|
|
17
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
18
|
+
*/
|
|
19
|
+
export declare function encodeHTML(data: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Encodes all non-ASCII characters, as well as characters not valid in HTML
|
|
22
|
+
* documents using HTML entities.
|
|
23
|
+
*
|
|
24
|
+
* If a character has no equivalent entity, a
|
|
25
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
26
|
+
*/
|
|
27
|
+
export declare function encodeNonAsciiHTML(data: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
30
|
+
* documents using numeric hexadecimal reference (eg. `ü`).
|
|
31
|
+
*
|
|
32
|
+
* Have a look at `escapeUTF8` if you want a more concise output at the expense
|
|
33
|
+
* of reduced transportability.
|
|
34
|
+
*
|
|
35
|
+
* @param data String to escape.
|
|
36
|
+
*/
|
|
37
|
+
export declare const escape: typeof encodeXML;
|
|
38
|
+
/**
|
|
39
|
+
* Encodes all characters not valid in XML documents using XML entities.
|
|
40
|
+
*
|
|
41
|
+
* Note that the output will be character-set dependent.
|
|
42
|
+
*
|
|
43
|
+
* @param data String to escape.
|
|
44
|
+
*/
|
|
45
|
+
export declare const escapeUTF8: (data: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Encodes all characters that have to be escaped in HTML attributes,
|
|
48
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
49
|
+
*
|
|
50
|
+
* @param data String to escape.
|
|
51
|
+
*/
|
|
52
|
+
export declare const escapeAttribute: (data: string) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Encodes all characters that have to be escaped in HTML text,
|
|
55
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
56
|
+
*
|
|
57
|
+
* @param data String to escape.
|
|
58
|
+
*/
|
|
59
|
+
export declare const escapeText: (data: string) => string;
|
|
60
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA0B7C;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AACD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;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,119 @@
|
|
|
1
|
+
import { encodeHTMLTrieRe, getCodePoint } from "./encode-trie.js";
|
|
2
|
+
const htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;
|
|
3
|
+
const xmlReplacer = /["&'<>$\x80-\uFFFF]/g;
|
|
4
|
+
const xmlCodeMap = new Map([
|
|
5
|
+
[34, """],
|
|
6
|
+
[38, "&"],
|
|
7
|
+
[39, "'"],
|
|
8
|
+
[60, "<"],
|
|
9
|
+
[62, ">"],
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
13
|
+
* documents using XML entities.
|
|
14
|
+
*
|
|
15
|
+
* If a character has no equivalent entity, a
|
|
16
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
17
|
+
*/
|
|
18
|
+
export function encodeXML(str) {
|
|
19
|
+
let ret = "";
|
|
20
|
+
let lastIdx = 0;
|
|
21
|
+
let match;
|
|
22
|
+
while ((match = xmlReplacer.exec(str)) !== null) {
|
|
23
|
+
const i = match.index;
|
|
24
|
+
const char = str.charCodeAt(i);
|
|
25
|
+
const next = xmlCodeMap.get(char);
|
|
26
|
+
if (next) {
|
|
27
|
+
ret += str.substring(lastIdx, i) + next;
|
|
28
|
+
lastIdx = i + 1;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`;
|
|
32
|
+
// Increase by 1 if we have a surrogate pair
|
|
33
|
+
lastIdx = xmlReplacer.lastIndex += Number((char & 65408) === 0xd800);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return ret + str.substr(lastIdx);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Encodes all entities and non-ASCII characters in the input.
|
|
40
|
+
*
|
|
41
|
+
* This includes characters that are valid ASCII characters in HTML documents.
|
|
42
|
+
* For example `#` will be encoded as `#`. To get a more compact output,
|
|
43
|
+
* consider using the `encodeNonAsciiHTML` function.
|
|
44
|
+
*
|
|
45
|
+
* If a character has no equivalent entity, a
|
|
46
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
47
|
+
*/
|
|
48
|
+
export function encodeHTML(data) {
|
|
49
|
+
return encodeHTMLTrieRe(htmlReplacer, data);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Encodes all non-ASCII characters, as well as characters not valid in HTML
|
|
53
|
+
* documents using HTML entities.
|
|
54
|
+
*
|
|
55
|
+
* If a character has no equivalent entity, a
|
|
56
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
57
|
+
*/
|
|
58
|
+
export function encodeNonAsciiHTML(data) {
|
|
59
|
+
return encodeHTMLTrieRe(xmlReplacer, data);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
63
|
+
* documents using numeric hexadecimal reference (eg. `ü`).
|
|
64
|
+
*
|
|
65
|
+
* Have a look at `escapeUTF8` if you want a more concise output at the expense
|
|
66
|
+
* of reduced transportability.
|
|
67
|
+
*
|
|
68
|
+
* @param data String to escape.
|
|
69
|
+
*/
|
|
70
|
+
export const escape = encodeXML;
|
|
71
|
+
function getEscaper(regex, map) {
|
|
72
|
+
return function escape(data) {
|
|
73
|
+
let match;
|
|
74
|
+
let lastIdx = 0;
|
|
75
|
+
let result = "";
|
|
76
|
+
while ((match = regex.exec(data))) {
|
|
77
|
+
if (lastIdx !== match.index) {
|
|
78
|
+
result += data.substring(lastIdx, match.index);
|
|
79
|
+
}
|
|
80
|
+
// We know that this chararcter will be in the map.
|
|
81
|
+
result += map.get(match[0].charCodeAt(0));
|
|
82
|
+
// Every match will be of length 1
|
|
83
|
+
lastIdx = match.index + 1;
|
|
84
|
+
}
|
|
85
|
+
return result + data.substring(lastIdx);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Encodes all characters not valid in XML documents using XML entities.
|
|
90
|
+
*
|
|
91
|
+
* Note that the output will be character-set dependent.
|
|
92
|
+
*
|
|
93
|
+
* @param data String to escape.
|
|
94
|
+
*/
|
|
95
|
+
export const escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap);
|
|
96
|
+
/**
|
|
97
|
+
* Encodes all characters that have to be escaped in HTML attributes,
|
|
98
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
99
|
+
*
|
|
100
|
+
* @param data String to escape.
|
|
101
|
+
*/
|
|
102
|
+
export const escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([
|
|
103
|
+
[34, """],
|
|
104
|
+
[38, "&"],
|
|
105
|
+
[160, " "],
|
|
106
|
+
]));
|
|
107
|
+
/**
|
|
108
|
+
* Encodes all characters that have to be escaped in HTML text,
|
|
109
|
+
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
110
|
+
*
|
|
111
|
+
* @param data String to escape.
|
|
112
|
+
*/
|
|
113
|
+
export const escapeText = getEscaper(/[&<>\u00A0]/g, new Map([
|
|
114
|
+
[38, "&"],
|
|
115
|
+
[60, "<"],
|
|
116
|
+
[62, ">"],
|
|
117
|
+
[160, " "],
|
|
118
|
+
]));
|
|
119
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAC3D,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAE3C,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,MAAM,CAAC;IACZ,CAAC,EAAE,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACjC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,KAAK,CAAC;IAEV,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC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