entities 4.2.0 → 4.4.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 +21 -2
- package/lib/decode.d.ts.map +1 -1
- package/lib/decode.js +44 -35
- package/lib/decode.js.map +1 -1
- package/lib/decode_codepoint.d.ts +1 -0
- package/lib/decode_codepoint.d.ts.map +1 -1
- package/lib/decode_codepoint.js +3 -3
- package/lib/decode_codepoint.js.map +1 -1
- package/lib/encode.d.ts +11 -49
- package/lib/encode.d.ts.map +1 -1
- package/lib/encode.js +56 -104
- package/lib/encode.js.map +1 -1
- 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 +21 -2
- package/lib/esm/decode.d.ts.map +1 -1
- package/lib/esm/decode.js +41 -10
- package/lib/esm/decode.js.map +1 -1
- package/lib/esm/decode_codepoint.d.ts +1 -0
- package/lib/esm/decode_codepoint.d.ts.map +1 -1
- package/lib/esm/decode_codepoint.js +1 -1
- package/lib/esm/decode_codepoint.js.map +1 -1
- package/lib/esm/encode.d.ts +11 -49
- package/lib/esm/encode.d.ts.map +1 -1
- package/lib/esm/encode.js +50 -100
- package/lib/esm/encode.js.map +1 -1
- 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.map +1 -1
- package/lib/esm/generated/decode-data-html.js +4 -1
- package/lib/esm/generated/decode-data-html.js.map +1 -1
- package/lib/esm/generated/decode-data-xml.d.ts.map +1 -1
- package/lib/esm/generated/decode-data-xml.js +4 -1
- package/lib/esm/generated/decode-data-xml.js.map +1 -1
- package/lib/esm/generated/encode-html.d.ts.map +1 -1
- package/lib/esm/generated/encode-html.js +7 -1
- package/lib/esm/generated/encode-html.js.map +1 -1
- package/lib/esm/index.d.ts +3 -2
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +5 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/generated/decode-data-html.d.ts.map +1 -1
- package/lib/generated/decode-data-html.js +5 -2
- package/lib/generated/decode-data-html.js.map +1 -1
- package/lib/generated/decode-data-xml.d.ts.map +1 -1
- package/lib/generated/decode-data-xml.js +5 -2
- package/lib/generated/decode-data-xml.js.map +1 -1
- package/lib/generated/encode-html.d.ts.map +1 -1
- package/lib/generated/encode-html.js +7 -1
- package/lib/generated/encode-html.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -11
- package/lib/index.js.map +1 -1
- package/package.json +17 -14
- package/lib/encode-trie.d.ts +0 -3
- package/lib/encode-trie.d.ts.map +0 -1
- package/lib/encode-trie.js +0 -66
- package/lib/encode-trie.js.map +0 -1
- package/lib/esm/encode-trie.d.ts +0 -3
- package/lib/esm/encode-trie.d.ts.map +0 -1
- package/lib/esm/encode-trie.js +0 -57
- package/lib/esm/encode-trie.js.map +0 -1
package/lib/decode.d.ts
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
import htmlDecodeTree from "./generated/decode-data-html.js";
|
|
2
2
|
import xmlDecodeTree from "./generated/decode-data-xml.js";
|
|
3
|
-
import
|
|
4
|
-
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint
|
|
3
|
+
import decodeCodePoint from "./decode_codepoint.js";
|
|
4
|
+
export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint };
|
|
5
|
+
export { replaceCodePoint, fromCodePoint } from "./decode_codepoint.js";
|
|
5
6
|
export declare enum BinTrieFlags {
|
|
6
7
|
VALUE_LENGTH = 49152,
|
|
7
8
|
BRANCH_LENGTH = 16256,
|
|
8
9
|
JUMP_TABLE = 127
|
|
9
10
|
}
|
|
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
|
+
*/
|
|
11
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
|
+
*/
|
|
12
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
|
+
*/
|
|
13
32
|
export declare function decodeXML(str: string): string;
|
|
14
33
|
//# 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/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
CHANGED
|
@@ -1,39 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.BinTrieFlags = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
|
|
6
|
+
exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.BinTrieFlags = exports.fromCodePoint = exports.replaceCodePoint = exports.decodeCodePoint = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
|
|
30
7
|
var decode_data_html_js_1 = __importDefault(require("./generated/decode-data-html.js"));
|
|
31
8
|
exports.htmlDecodeTree = decode_data_html_js_1.default;
|
|
32
9
|
var decode_data_xml_js_1 = __importDefault(require("./generated/decode-data-xml.js"));
|
|
33
10
|
exports.xmlDecodeTree = decode_data_xml_js_1.default;
|
|
34
|
-
var decode_codepoint_js_1 =
|
|
35
|
-
|
|
36
|
-
|
|
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 = {}));
|
|
37
28
|
var BinTrieFlags;
|
|
38
29
|
(function (BinTrieFlags) {
|
|
39
30
|
BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
|
|
@@ -51,26 +42,26 @@ function getDecoder(decodeTree) {
|
|
|
51
42
|
// Skip the "&"
|
|
52
43
|
strIdx += 1;
|
|
53
44
|
// If we have a numeric entity, handle this separately.
|
|
54
|
-
if (str.charCodeAt(strIdx) ===
|
|
45
|
+
if (str.charCodeAt(strIdx) === CharCodes.NUM) {
|
|
55
46
|
// Skip the leading "&#". For hex entities, also skip the leading "x".
|
|
56
47
|
var start = strIdx + 1;
|
|
57
48
|
var base = 10;
|
|
58
49
|
var cp = str.charCodeAt(start);
|
|
59
|
-
if ((cp |
|
|
50
|
+
if ((cp | CharCodes.To_LOWER_BIT) === CharCodes.LOWER_X) {
|
|
60
51
|
base = 16;
|
|
61
52
|
strIdx += 1;
|
|
62
53
|
start += 1;
|
|
63
54
|
}
|
|
64
55
|
do
|
|
65
56
|
cp = str.charCodeAt(++strIdx);
|
|
66
|
-
while ((cp >=
|
|
57
|
+
while ((cp >= CharCodes.ZERO && cp <= CharCodes.NINE) ||
|
|
67
58
|
(base === 16 &&
|
|
68
|
-
(cp |
|
|
69
|
-
(cp |
|
|
59
|
+
(cp | CharCodes.To_LOWER_BIT) >= CharCodes.LOWER_A &&
|
|
60
|
+
(cp | CharCodes.To_LOWER_BIT) <= CharCodes.LOWER_F));
|
|
70
61
|
if (start !== strIdx) {
|
|
71
62
|
var entity = str.substring(start, strIdx);
|
|
72
63
|
var parsed = parseInt(entity, base);
|
|
73
|
-
if (str.charCodeAt(strIdx) ===
|
|
64
|
+
if (str.charCodeAt(strIdx) === CharCodes.SEMI) {
|
|
74
65
|
strIdx += 1;
|
|
75
66
|
}
|
|
76
67
|
else if (strict) {
|
|
@@ -94,7 +85,7 @@ function getDecoder(decodeTree) {
|
|
|
94
85
|
// If the branch is a value, store it and continue
|
|
95
86
|
if (masked) {
|
|
96
87
|
// If we have a legacy entity while parsing strictly, just skip the number of bytes
|
|
97
|
-
if (!strict || str.charCodeAt(strIdx) ===
|
|
88
|
+
if (!strict || str.charCodeAt(strIdx) === CharCodes.SEMI) {
|
|
98
89
|
resultIdx = treeIdx;
|
|
99
90
|
excess = 0;
|
|
100
91
|
}
|
|
@@ -129,7 +120,7 @@ function determineBranch(decodeTree, current, nodeIdx, char) {
|
|
|
129
120
|
// Case 2: Multiple branches encoded in jump table
|
|
130
121
|
if (jumpOffset) {
|
|
131
122
|
var value = char - jumpOffset;
|
|
132
|
-
return value < 0 || value
|
|
123
|
+
return value < 0 || value >= branchCount
|
|
133
124
|
? -1
|
|
134
125
|
: decodeTree[nodeIdx + value] - 1;
|
|
135
126
|
}
|
|
@@ -155,14 +146,32 @@ function determineBranch(decodeTree, current, nodeIdx, char) {
|
|
|
155
146
|
exports.determineBranch = determineBranch;
|
|
156
147
|
var htmlDecoder = getDecoder(decode_data_html_js_1.default);
|
|
157
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
|
+
*/
|
|
158
155
|
function decodeHTML(str) {
|
|
159
156
|
return htmlDecoder(str, false);
|
|
160
157
|
}
|
|
161
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
|
+
*/
|
|
162
165
|
function decodeHTMLStrict(str) {
|
|
163
166
|
return htmlDecoder(str, true);
|
|
164
167
|
}
|
|
165
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
|
+
*/
|
|
166
175
|
function decodeXML(str) {
|
|
167
176
|
return xmlDecoder(str, true);
|
|
168
177
|
}
|
package/lib/decode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.js","sourceRoot":"","sources":["
|
|
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,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;AAED,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,mEAAoC,CAAA;IACpC,qEAAqC,CAAA;IACrC,6DAAkC,CAAA;AACtC,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,SAAS,UAAU,CAAC,UAAuB;IACvC,OAAO,S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,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/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"}
|
package/lib/decode_codepoint.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
|
|
3
3
|
var _a;
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.replaceCodePoint = void 0;
|
|
5
|
+
exports.replaceCodePoint = exports.fromCodePoint = void 0;
|
|
6
6
|
var decodeMap = new Map([
|
|
7
7
|
[0, 65533],
|
|
8
8
|
[128, 8364],
|
|
@@ -33,7 +33,7 @@ var decodeMap = new Map([
|
|
|
33
33
|
[158, 382],
|
|
34
34
|
[159, 376],
|
|
35
35
|
]);
|
|
36
|
-
|
|
36
|
+
exports.fromCodePoint =
|
|
37
37
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
|
|
38
38
|
(_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) {
|
|
39
39
|
var output = "";
|
|
@@ -54,7 +54,7 @@ function replaceCodePoint(codePoint) {
|
|
|
54
54
|
}
|
|
55
55
|
exports.replaceCodePoint = replaceCodePoint;
|
|
56
56
|
function decodeCodePoint(codePoint) {
|
|
57
|
-
return fromCodePoint(replaceCodePoint(codePoint));
|
|
57
|
+
return (0, exports.fromCodePoint)(replaceCodePoint(codePoint));
|
|
58
58
|
}
|
|
59
59
|
exports.default = decodeCodePoint;
|
|
60
60
|
//# sourceMappingURL=decode_codepoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode_codepoint.js","sourceRoot":"","sources":["
|
|
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,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,GAAG,CAAC;CACb,CAAC,CAAC;AAEU,QAAA,aAAa;AACtB,iHAAiH;AACjH,MAAA,MAAM,CAAC,aAAa,mCACpB,UAAU,SAAiB;IACvB,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,SAAS,GAAG,MAAM,EAAE;QACpB,SAAS,IAAI,OAAO,CAAC;QACrB,MAAM,IAAI,MAAM,CAAC,YAAY,CACzB,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,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"}
|
package/lib/encode.d.ts
CHANGED
|
@@ -1,60 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Encodes all
|
|
3
|
-
* documents
|
|
2
|
+
* Encodes all characters in the input using HTML entities. This includes
|
|
3
|
+
* characters that are valid ASCII characters in HTML documents, such as `#`.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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.
|
|
5
|
+
* To get a more compact output, consider using the `encodeNonAsciiHTML`
|
|
6
|
+
* function, which will only encode characters that are not valid in HTML
|
|
7
|
+
* documents, as well as non-ASCII characters.
|
|
15
8
|
*
|
|
16
|
-
* If a character has no equivalent entity, a
|
|
17
|
-
*
|
|
9
|
+
* If a character has no equivalent entity, a numeric hexadecimal reference
|
|
10
|
+
* (eg. `ü`) will be used.
|
|
18
11
|
*/
|
|
19
12
|
export declare function encodeHTML(data: string): string;
|
|
20
13
|
/**
|
|
21
14
|
* Encodes all non-ASCII characters, as well as characters not valid in HTML
|
|
22
|
-
* documents using HTML entities.
|
|
15
|
+
* documents using HTML entities. This function will not encode characters that
|
|
16
|
+
* are valid in HTML documents, such as `#`.
|
|
23
17
|
*
|
|
24
|
-
* If a character has no equivalent entity, a
|
|
25
|
-
*
|
|
18
|
+
* If a character has no equivalent entity, a numeric hexadecimal reference
|
|
19
|
+
* (eg. `ü`) will be used.
|
|
26
20
|
*/
|
|
27
21
|
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
22
|
//# 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/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
CHANGED
|
@@ -1,125 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
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");
|
|
5
9
|
var htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;
|
|
6
|
-
var xmlReplacer = /["&'<>$\x80-\uFFFF]/g;
|
|
7
|
-
var xmlCodeMap = new Map([
|
|
8
|
-
[34, """],
|
|
9
|
-
[38, "&"],
|
|
10
|
-
[39, "'"],
|
|
11
|
-
[60, "<"],
|
|
12
|
-
[62, ">"],
|
|
13
|
-
]);
|
|
14
10
|
/**
|
|
15
|
-
* Encodes all
|
|
16
|
-
* documents
|
|
11
|
+
* Encodes all characters in the input using HTML entities. This includes
|
|
12
|
+
* characters that are valid ASCII characters in HTML documents, such as `#`.
|
|
17
13
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
function encodeXML(str) {
|
|
22
|
-
var ret = "";
|
|
23
|
-
var lastIdx = 0;
|
|
24
|
-
var match;
|
|
25
|
-
while ((match = xmlReplacer.exec(str)) !== null) {
|
|
26
|
-
var i = match.index;
|
|
27
|
-
var char = str.charCodeAt(i);
|
|
28
|
-
var next = xmlCodeMap.get(char);
|
|
29
|
-
if (next !== undefined) {
|
|
30
|
-
ret += str.substring(lastIdx, i) + next;
|
|
31
|
-
lastIdx = i + 1;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
ret += "".concat(str.substring(lastIdx, i), "&#x").concat((0, encode_trie_js_1.getCodePoint)(str, i).toString(16), ";");
|
|
35
|
-
// Increase by 1 if we have a surrogate pair
|
|
36
|
-
lastIdx = xmlReplacer.lastIndex += Number((char & 65408) === 0xd800);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return ret + str.substr(lastIdx);
|
|
40
|
-
}
|
|
41
|
-
exports.encodeXML = encodeXML;
|
|
42
|
-
/**
|
|
43
|
-
* Encodes all entities and non-ASCII characters in the input.
|
|
44
|
-
*
|
|
45
|
-
* This includes characters that are valid ASCII characters in HTML documents.
|
|
46
|
-
* For example `#` will be encoded as `#`. To get a more compact output,
|
|
47
|
-
* consider using the `encodeNonAsciiHTML` function.
|
|
14
|
+
* To get a more compact output, consider using the `encodeNonAsciiHTML`
|
|
15
|
+
* function, which will only encode characters that are not valid in HTML
|
|
16
|
+
* documents, as well as non-ASCII characters.
|
|
48
17
|
*
|
|
49
|
-
* If a character has no equivalent entity, a
|
|
50
|
-
*
|
|
18
|
+
* If a character has no equivalent entity, a numeric hexadecimal reference
|
|
19
|
+
* (eg. `ü`) will be used.
|
|
51
20
|
*/
|
|
52
21
|
function encodeHTML(data) {
|
|
53
|
-
return
|
|
22
|
+
return encodeHTMLTrieRe(htmlReplacer, data);
|
|
54
23
|
}
|
|
55
24
|
exports.encodeHTML = encodeHTML;
|
|
56
25
|
/**
|
|
57
26
|
* Encodes all non-ASCII characters, as well as characters not valid in HTML
|
|
58
|
-
* documents using HTML entities.
|
|
27
|
+
* documents using HTML entities. This function will not encode characters that
|
|
28
|
+
* are valid in HTML documents, such as `#`.
|
|
59
29
|
*
|
|
60
|
-
* If a character has no equivalent entity, a
|
|
61
|
-
*
|
|
30
|
+
* If a character has no equivalent entity, a numeric hexadecimal reference
|
|
31
|
+
* (eg. `ü`) will be used.
|
|
62
32
|
*/
|
|
63
33
|
function encodeNonAsciiHTML(data) {
|
|
64
|
-
return (
|
|
34
|
+
return encodeHTMLTrieRe(escape_js_1.xmlReplacer, data);
|
|
65
35
|
}
|
|
66
36
|
exports.encodeNonAsciiHTML = encodeNonAsciiHTML;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
37
|
+
function encodeHTMLTrieRe(regExp, str) {
|
|
38
|
+
var ret = "";
|
|
39
|
+
var lastIdx = 0;
|
|
40
|
+
var match;
|
|
41
|
+
while ((match = regExp.exec(str)) !== null) {
|
|
42
|
+
var i = match.index;
|
|
43
|
+
ret += str.substring(lastIdx, i);
|
|
44
|
+
var char = str.charCodeAt(i);
|
|
45
|
+
var next = encode_html_js_1.default.get(char);
|
|
46
|
+
if (typeof next === "object") {
|
|
47
|
+
// We are in a branch. Try to match the next char.
|
|
48
|
+
if (i + 1 < str.length) {
|
|
49
|
+
var nextChar = str.charCodeAt(i + 1);
|
|
50
|
+
var value = typeof next.n === "number"
|
|
51
|
+
? next.n === nextChar
|
|
52
|
+
? next.o
|
|
53
|
+
: undefined
|
|
54
|
+
: next.n.get(nextChar);
|
|
55
|
+
if (value !== undefined) {
|
|
56
|
+
ret += value;
|
|
57
|
+
lastIdx = regExp.lastIndex += 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
85
60
|
}
|
|
86
|
-
|
|
87
|
-
result += map.get(match[0].charCodeAt(0));
|
|
88
|
-
// Every match will be of length 1
|
|
89
|
-
lastIdx = match.index + 1;
|
|
61
|
+
next = next.v;
|
|
90
62
|
}
|
|
91
|
-
|
|
92
|
-
|
|
63
|
+
// We might have a tree node without a value; skip and use a numeric entitiy.
|
|
64
|
+
if (next !== undefined) {
|
|
65
|
+
ret += next;
|
|
66
|
+
lastIdx = i + 1;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
var cp = (0, escape_js_1.getCodePoint)(str, i);
|
|
70
|
+
ret += "&#x".concat(cp.toString(16), ";");
|
|
71
|
+
// Increase by 1 if we have a surrogate pair
|
|
72
|
+
lastIdx = regExp.lastIndex += Number(cp !== char);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return ret + str.substr(lastIdx);
|
|
93
76
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Encodes all characters not valid in XML documents using XML entities.
|
|
96
|
-
*
|
|
97
|
-
* Note that the output will be character-set dependent.
|
|
98
|
-
*
|
|
99
|
-
* @param data String to escape.
|
|
100
|
-
*/
|
|
101
|
-
exports.escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap);
|
|
102
|
-
/**
|
|
103
|
-
* Encodes all characters that have to be escaped in HTML attributes,
|
|
104
|
-
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
105
|
-
*
|
|
106
|
-
* @param data String to escape.
|
|
107
|
-
*/
|
|
108
|
-
exports.escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([
|
|
109
|
-
[34, """],
|
|
110
|
-
[38, "&"],
|
|
111
|
-
[160, " "],
|
|
112
|
-
]));
|
|
113
|
-
/**
|
|
114
|
-
* Encodes all characters that have to be escaped in HTML text,
|
|
115
|
-
* following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
|
|
116
|
-
*
|
|
117
|
-
* @param data String to escape.
|
|
118
|
-
*/
|
|
119
|
-
exports.escapeText = getEscaper(/[&<>\u00A0]/g, new Map([
|
|
120
|
-
[38, "&"],
|
|
121
|
-
[60, "<"],
|
|
122
|
-
[62, ">"],
|
|
123
|
-
[160, " "],
|
|
124
|
-
]));
|
|
125
77
|
//# sourceMappingURL=encode.js.map
|
package/lib/encode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"","sources":["
|
|
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;AACh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;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/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"}
|