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.
- package/lib/decode.d.ts +14 -4
- package/lib/decode.d.ts.map +1 -1
- package/lib/decode.js +150 -42
- package/lib/decode.js.map +1 -0
- package/lib/decode_codepoint.d.ts +2 -0
- package/lib/decode_codepoint.d.ts.map +1 -1
- package/lib/decode_codepoint.js +54 -24
- package/lib/decode_codepoint.js.map +1 -0
- package/lib/encode.d.ts +2 -29
- package/lib/encode.d.ts.map +1 -1
- package/lib/encode.js +47 -108
- package/lib/encode.js.map +1 -0
- package/lib/escape.d.ts +43 -0
- package/lib/escape.d.ts.map +1 -0
- package/lib/escape.js +112 -0
- package/lib/escape.js.map +1 -0
- package/lib/esm/decode.d.ts +15 -0
- package/lib/esm/decode.d.ts.map +1 -0
- package/lib/esm/decode.js +148 -0
- package/lib/esm/decode.js.map +1 -0
- package/lib/esm/decode_codepoint.d.ts +4 -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.d.ts +20 -0
- package/lib/esm/encode.d.ts.map +1 -0
- package/lib/esm/encode.js +67 -0
- package/lib/esm/encode.js.map +1 -0
- package/lib/esm/escape.d.ts +43 -0
- package/lib/esm/escape.d.ts.map +1 -0
- package/lib/esm/escape.js +106 -0
- package/lib/esm/escape.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 +102 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +113 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/generated/decode-data-html.d.ts +3 -0
- package/lib/generated/decode-data-html.d.ts.map +1 -0
- package/lib/generated/decode-data-html.js +6 -0
- package/lib/generated/decode-data-html.js.map +1 -0
- package/lib/generated/decode-data-xml.d.ts +3 -0
- package/lib/generated/decode-data-xml.d.ts.map +1 -0
- package/lib/generated/decode-data-xml.js +6 -0
- 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 +86 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +112 -32
- package/lib/index.js.map +1 -0
- package/package.json +44 -17
- package/readme.md +78 -13
- package/lib/maps/decode.json +0 -1
- package/lib/maps/entities.json +0 -1
- package/lib/maps/legacy.json +0 -1
- package/lib/maps/xml.json +0 -1
package/lib/decode.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
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;
|
|
5
15
|
//# sourceMappingURL=decode.d.ts.map
|
package/lib/decode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["
|
|
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"}
|
package/lib/decode.js
CHANGED
|
@@ -3,51 +3,159 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
};
|
|
17
112
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
26
139
|
}
|
|
27
140
|
else {
|
|
28
|
-
|
|
141
|
+
return decodeTree[mid + branchCount];
|
|
29
142
|
}
|
|
30
143
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return decode_codepoint_1.default(parseInt(str.substr(3), 16));
|
|
47
|
-
}
|
|
48
|
-
return decode_codepoint_1.default(parseInt(str.substr(2), 10));
|
|
49
|
-
}
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
51
|
-
return map[str.slice(1, -1)] || str;
|
|
52
|
-
};
|
|
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
|
+
function decodeHTML(str) {
|
|
150
|
+
return htmlDecoder(str, false);
|
|
151
|
+
}
|
|
152
|
+
exports.decodeHTML = decodeHTML;
|
|
153
|
+
function decodeHTMLStrict(str) {
|
|
154
|
+
return htmlDecoder(str, true);
|
|
155
|
+
}
|
|
156
|
+
exports.decodeHTMLStrict = decodeHTMLStrict;
|
|
157
|
+
function decodeXML(str) {
|
|
158
|
+
return xmlDecoder(str, true);
|
|
53
159
|
}
|
|
160
|
+
exports.decodeXML = decodeXML;
|
|
161
|
+
//# 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"],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,CAAC,CAAC;SAChB;aAAM,IAAI,MAAM,GAAG,IAAI,EAAE;YACtB,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;SAChB;aAAM;YACH,OAAO,UAAU,CAAC,GAAG,GAAG,WAAW,CAAC,CAAC;SACxC;KACJ;IAED,OAAO,CAAC,CAAC,CAAC;AACd,CAAC;AA3CD,0CA2CC;AAED,IAAM,WAAW,GAAG,UAAU,CAAC,6BAAc,CAAC,CAAC;AAC/C,IAAM,UAAU,GAAG,UAAU,CAAC,4BAAa,CAAC,CAAC;AAE7C,SAAgB,UAAU,CAAC,GAAW;IAClC,OAAO,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAFD,gCAEC;AAED,SAAgB,gBAAgB,CAAC,GAAW;IACxC,OAAO,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAFD,4CAEC;AAED,SAAgB,SAAS,CAAC,GAAW;IACjC,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAFD,8BAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["
|
|
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"}
|
package/lib/decode_codepoint.js
CHANGED
|
@@ -1,30 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
|
|
3
|
+
var _a;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
exports.replaceCodePoint = exports.fromCodePoint = void 0;
|
|
6
|
+
var decodeMap = new Map([
|
|
7
|
+
[0, 65533],
|
|
8
|
+
[128, 8364],
|
|
9
|
+
[130, 8218],
|
|
10
|
+
[131, 402],
|
|
11
|
+
[132, 8222],
|
|
12
|
+
[133, 8230],
|
|
13
|
+
[134, 8224],
|
|
14
|
+
[135, 8225],
|
|
15
|
+
[136, 710],
|
|
16
|
+
[137, 8240],
|
|
17
|
+
[138, 352],
|
|
18
|
+
[139, 8249],
|
|
19
|
+
[140, 338],
|
|
20
|
+
[142, 381],
|
|
21
|
+
[145, 8216],
|
|
22
|
+
[146, 8217],
|
|
23
|
+
[147, 8220],
|
|
24
|
+
[148, 8221],
|
|
25
|
+
[149, 8226],
|
|
26
|
+
[150, 8211],
|
|
27
|
+
[151, 8212],
|
|
28
|
+
[152, 732],
|
|
29
|
+
[153, 8482],
|
|
30
|
+
[154, 353],
|
|
31
|
+
[155, 8250],
|
|
32
|
+
[156, 339],
|
|
33
|
+
[158, 382],
|
|
34
|
+
[159, 376],
|
|
35
|
+
]);
|
|
36
|
+
exports.fromCodePoint =
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
|
|
38
|
+
(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) {
|
|
39
|
+
var output = "";
|
|
40
|
+
if (codePoint > 0xffff) {
|
|
41
|
+
codePoint -= 0x10000;
|
|
42
|
+
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
|
|
43
|
+
codePoint = 0xdc00 | (codePoint & 0x3ff);
|
|
24
44
|
}
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
output += String.fromCharCode(codePoint);
|
|
46
|
+
return output;
|
|
47
|
+
};
|
|
48
|
+
function replaceCodePoint(codePoint) {
|
|
49
|
+
var _a;
|
|
50
|
+
if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
|
|
51
|
+
return 0xfffd;
|
|
27
52
|
}
|
|
28
|
-
return
|
|
53
|
+
return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
|
|
54
|
+
}
|
|
55
|
+
exports.replaceCodePoint = replaceCodePoint;
|
|
56
|
+
function decodeCodePoint(codePoint) {
|
|
57
|
+
return (0, exports.fromCodePoint)(replaceCodePoint(codePoint));
|
|
29
58
|
}
|
|
30
59
|
exports.default = decodeCodePoint;
|
|
60
|
+
//# 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,IAAM,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,CAA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AAI,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"}
|
package/lib/encode.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
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 const encodeXML: (data: string) => string;
|
|
9
1
|
/**
|
|
10
2
|
* Encodes all entities and non-ASCII characters in the input.
|
|
11
3
|
*
|
|
@@ -16,7 +8,7 @@ export declare const encodeXML: (data: string) => string;
|
|
|
16
8
|
* If a character has no equivalent entity, a
|
|
17
9
|
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
18
10
|
*/
|
|
19
|
-
export declare
|
|
11
|
+
export declare function encodeHTML(data: string): string;
|
|
20
12
|
/**
|
|
21
13
|
* Encodes all non-ASCII characters, as well as characters not valid in HTML
|
|
22
14
|
* documents using HTML entities.
|
|
@@ -24,24 +16,5 @@ export declare const encodeHTML: (data: string) => string;
|
|
|
24
16
|
* If a character has no equivalent entity, a
|
|
25
17
|
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
26
18
|
*/
|
|
27
|
-
export declare
|
|
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 function escape(data: string): string;
|
|
38
|
-
/**
|
|
39
|
-
* Encodes all characters not valid in XML documents using numeric hexadecimal
|
|
40
|
-
* reference (eg. `ü`).
|
|
41
|
-
*
|
|
42
|
-
* Note that the output will be character-set dependent.
|
|
43
|
-
*
|
|
44
|
-
* @param data String to escape.
|
|
45
|
-
*/
|
|
46
|
-
export declare function escapeUTF8(data: string): string;
|
|
19
|
+
export declare function encodeNonAsciiHTML(data: string): string;
|
|
47
20
|
//# sourceMappingURL=encode.d.ts.map
|
package/lib/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["
|
|
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"}
|
package/lib/encode.js
CHANGED
|
@@ -3,21 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
12
|
-
* documents using XML entities.
|
|
13
|
-
*
|
|
14
|
-
* If a character has no equivalent entity, a
|
|
15
|
-
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
16
|
-
*/
|
|
17
|
-
exports.encodeXML = getASCIIEncoder(inverseXML);
|
|
18
|
-
var entities_json_1 = __importDefault(require("./maps/entities.json"));
|
|
19
|
-
var inverseHTML = getInverseObj(entities_json_1.default);
|
|
20
|
-
var htmlReplacer = getInverseReplacer(inverseHTML);
|
|
6
|
+
exports.encodeNonAsciiHTML = exports.encodeHTML = void 0;
|
|
7
|
+
var encode_html_js_1 = __importDefault(require("./generated/encode-html.js"));
|
|
8
|
+
var escape_js_1 = require("./escape.js");
|
|
9
|
+
var htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;
|
|
21
10
|
/**
|
|
22
11
|
* Encodes all entities and non-ASCII characters in the input.
|
|
23
12
|
*
|
|
@@ -28,7 +17,10 @@ var htmlReplacer = getInverseReplacer(inverseHTML);
|
|
|
28
17
|
* If a character has no equivalent entity, a
|
|
29
18
|
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
30
19
|
*/
|
|
31
|
-
|
|
20
|
+
function encodeHTML(data) {
|
|
21
|
+
return encodeHTMLTrieRe(htmlReplacer, data);
|
|
22
|
+
}
|
|
23
|
+
exports.encodeHTML = encodeHTML;
|
|
32
24
|
/**
|
|
33
25
|
* Encodes all non-ASCII characters, as well as characters not valid in HTML
|
|
34
26
|
* documents using HTML entities.
|
|
@@ -36,101 +28,48 @@ exports.encodeHTML = getInverse(inverseHTML, htmlReplacer);
|
|
|
36
28
|
* If a character has no equivalent entity, a
|
|
37
29
|
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
38
30
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return Object.keys(obj)
|
|
42
|
-
.sort()
|
|
43
|
-
.reduce(function (inverse, name) {
|
|
44
|
-
inverse[obj[name]] = "&" + name + ";";
|
|
45
|
-
return inverse;
|
|
46
|
-
}, {});
|
|
31
|
+
function encodeNonAsciiHTML(data) {
|
|
32
|
+
return encodeHTMLTrieRe(escape_js_1.xmlReplacer, data);
|
|
47
33
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
34
|
+
exports.encodeNonAsciiHTML = encodeNonAsciiHTML;
|
|
35
|
+
function encodeHTMLTrieRe(regExp, str) {
|
|
36
|
+
var ret = "";
|
|
37
|
+
var lastIdx = 0;
|
|
38
|
+
var match;
|
|
39
|
+
while ((match = regExp.exec(str)) !== null) {
|
|
40
|
+
var i = match.index;
|
|
41
|
+
ret += str.substring(lastIdx, i);
|
|
42
|
+
var char = str.charCodeAt(i);
|
|
43
|
+
var next = encode_html_js_1.default.get(char);
|
|
44
|
+
if (typeof next === "object") {
|
|
45
|
+
// We are in a branch. Try to match the next char.
|
|
46
|
+
if (i + 1 < str.length) {
|
|
47
|
+
var nextChar = str.charCodeAt(i + 1);
|
|
48
|
+
var value = typeof next.n === "number"
|
|
49
|
+
? next.n === nextChar
|
|
50
|
+
? next.o
|
|
51
|
+
: undefined
|
|
52
|
+
: next.n.get(nextChar);
|
|
53
|
+
if (value !== undefined) {
|
|
54
|
+
ret += value;
|
|
55
|
+
lastIdx = regExp.lastIndex += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
next = next.v;
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
// We might have a tree node without a value; skip and use a numeric entitiy.
|
|
62
|
+
if (next !== undefined) {
|
|
63
|
+
ret += next;
|
|
64
|
+
lastIdx = i + 1;
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var end = start;
|
|
67
|
-
while (end < single.length - 1 &&
|
|
68
|
-
single[end].charCodeAt(1) + 1 === single[end + 1].charCodeAt(1)) {
|
|
69
|
-
end += 1;
|
|
66
|
+
else {
|
|
67
|
+
var cp = (0, escape_js_1.getCodePoint)(str, i);
|
|
68
|
+
ret += "&#x".concat(cp.toString(16), ";");
|
|
69
|
+
// Increase by 1 if we have a surrogate pair
|
|
70
|
+
lastIdx = regExp.lastIndex += Number(cp !== char);
|
|
70
71
|
}
|
|
71
|
-
var count = 1 + end - start;
|
|
72
|
-
// We want to replace at least three characters
|
|
73
|
-
if (count < 3)
|
|
74
|
-
continue;
|
|
75
|
-
single.splice(start, count, single[start] + "-" + single[end]);
|
|
76
72
|
}
|
|
77
|
-
|
|
78
|
-
return new RegExp(multiple.join("|"), "g");
|
|
79
|
-
}
|
|
80
|
-
// /[^\0-\x7F]/gu
|
|
81
|
-
var reNonASCII = /(?:[\x80-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/g;
|
|
82
|
-
var getCodePoint =
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
84
|
-
String.prototype.codePointAt != null
|
|
85
|
-
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
86
|
-
function (str) { return str.codePointAt(0); }
|
|
87
|
-
: // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
|
88
|
-
function (c) {
|
|
89
|
-
return (c.charCodeAt(0) - 0xd800) * 0x400 +
|
|
90
|
-
c.charCodeAt(1) -
|
|
91
|
-
0xdc00 +
|
|
92
|
-
0x10000;
|
|
93
|
-
};
|
|
94
|
-
function singleCharReplacer(c) {
|
|
95
|
-
return "&#x" + (c.length > 1 ? getCodePoint(c) : c.charCodeAt(0))
|
|
96
|
-
.toString(16)
|
|
97
|
-
.toUpperCase() + ";";
|
|
98
|
-
}
|
|
99
|
-
function getInverse(inverse, re) {
|
|
100
|
-
return function (data) {
|
|
101
|
-
return data
|
|
102
|
-
.replace(re, function (name) { return inverse[name]; })
|
|
103
|
-
.replace(reNonASCII, singleCharReplacer);
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
var reEscapeChars = new RegExp(xmlReplacer.source + "|" + reNonASCII.source, "g");
|
|
107
|
-
/**
|
|
108
|
-
* Encodes all non-ASCII characters, as well as characters not valid in XML
|
|
109
|
-
* documents using numeric hexadecimal reference (eg. `ü`).
|
|
110
|
-
*
|
|
111
|
-
* Have a look at `escapeUTF8` if you want a more concise output at the expense
|
|
112
|
-
* of reduced transportability.
|
|
113
|
-
*
|
|
114
|
-
* @param data String to escape.
|
|
115
|
-
*/
|
|
116
|
-
function escape(data) {
|
|
117
|
-
return data.replace(reEscapeChars, singleCharReplacer);
|
|
118
|
-
}
|
|
119
|
-
exports.escape = escape;
|
|
120
|
-
/**
|
|
121
|
-
* Encodes all characters not valid in XML documents using numeric hexadecimal
|
|
122
|
-
* reference (eg. `ü`).
|
|
123
|
-
*
|
|
124
|
-
* Note that the output will be character-set dependent.
|
|
125
|
-
*
|
|
126
|
-
* @param data String to escape.
|
|
127
|
-
*/
|
|
128
|
-
function escapeUTF8(data) {
|
|
129
|
-
return data.replace(xmlReplacer, singleCharReplacer);
|
|
130
|
-
}
|
|
131
|
-
exports.escapeUTF8 = escapeUTF8;
|
|
132
|
-
function getASCIIEncoder(obj) {
|
|
133
|
-
return function (data) {
|
|
134
|
-
return data.replace(reEscapeChars, function (c) { return obj[c] || singleCharReplacer(c); });
|
|
135
|
-
};
|
|
73
|
+
return ret + str.substr(lastIdx);
|
|
136
74
|
}
|
|
75
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/f85d378bc4dbe36a3a7b0f757114d3d71f950d31/src/","sources":["encode.ts"],"names":[],"mappings":";;;;;;AAAA,8EAAkD;AAClD,yCAAwD;AAExD,IAAM,YAAY,GAAG,qCAAqC,CAAC;AAE3D;;;;;;;;;GASG;AACH,SAAgB,UAAU,CAAC,IAAY;IACnC,OAAO,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC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BACZ;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"}
|
package/lib/escape.d.ts
ADDED
|
@@ -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. `ü`) 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. `ü`).
|
|
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"}
|