entities 2.1.0 → 2.2.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 +1 -3
- package/lib/decode.d.ts.map +1 -1
- package/lib/decode.js +4 -5
- package/lib/decode_codepoint.d.ts.map +1 -1
- package/lib/decode_codepoint.js +15 -9
- package/lib/encode.d.ts +43 -0
- package/lib/encode.d.ts.map +1 -1
- package/lib/encode.js +71 -8
- package/lib/index.d.ts +4 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -3
- package/package.json +4 -3
- package/readme.md +11 -4
package/lib/decode.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export declare const decodeXML: (str: string) => string;
|
|
2
2
|
export declare const decodeHTMLStrict: (str: string) => string;
|
|
3
|
-
export
|
|
4
|
-
[key: string]: string;
|
|
5
|
-
}
|
|
3
|
+
export declare type MapType = Record<string, string>;
|
|
6
4
|
export declare const decodeHTML: (str: string) => string;
|
|
7
5
|
//# sourceMappingURL=decode.d.ts.map
|
package/lib/decode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,SAAS,QAOL,MAAM,WAP0B,CAAC;AAClD,eAAO,MAAM,gBAAgB,QAMZ,MAAM,WANoC,CAAC;AAE5D,oBAAY,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAS7C,eAAO,MAAM,UAAU,QAyBN,MAAM,WACnB,CAAC"}
|
package/lib/decode.js
CHANGED
|
@@ -8,14 +8,12 @@ var entities_json_1 = __importDefault(require("./maps/entities.json"));
|
|
|
8
8
|
var legacy_json_1 = __importDefault(require("./maps/legacy.json"));
|
|
9
9
|
var xml_json_1 = __importDefault(require("./maps/xml.json"));
|
|
10
10
|
var decode_codepoint_1 = __importDefault(require("./decode_codepoint"));
|
|
11
|
+
var strictEntityRe = /&(?:[a-zA-Z0-9]+|#[xX][\da-fA-F]+|#\d+);/g;
|
|
11
12
|
exports.decodeXML = getStrictDecoder(xml_json_1.default);
|
|
12
13
|
exports.decodeHTMLStrict = getStrictDecoder(entities_json_1.default);
|
|
13
14
|
function getStrictDecoder(map) {
|
|
14
|
-
var keys = Object.keys(map).join("|");
|
|
15
15
|
var replace = getReplacer(map);
|
|
16
|
-
|
|
17
|
-
var re = new RegExp("&(?:" + keys + ");", "g");
|
|
18
|
-
return function (str) { return String(str).replace(re, replace); };
|
|
16
|
+
return function (str) { return String(str).replace(strictEntityRe, replace); };
|
|
19
17
|
}
|
|
20
18
|
var sorter = function (a, b) { return (a < b ? 1 : -1); };
|
|
21
19
|
exports.decodeHTML = (function () {
|
|
@@ -49,6 +47,7 @@ function getReplacer(map) {
|
|
|
49
47
|
}
|
|
50
48
|
return decode_codepoint_1.default(parseInt(str.substr(2), 10));
|
|
51
49
|
}
|
|
52
|
-
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
51
|
+
return map[str.slice(1, -1)] || str;
|
|
53
52
|
};
|
|
54
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["../src/decode_codepoint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decode_codepoint.d.ts","sourceRoot":"","sources":["../src/decode_codepoint.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAUjE"}
|
package/lib/decode_codepoint.js
CHANGED
|
@@ -4,7 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var decode_json_1 = __importDefault(require("./maps/decode.json"));
|
|
7
|
-
//
|
|
7
|
+
// Adapted from https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
|
|
8
|
+
var fromCodePoint =
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
10
|
+
String.fromCodePoint ||
|
|
11
|
+
function (codePoint) {
|
|
12
|
+
var output = "";
|
|
13
|
+
if (codePoint > 0xffff) {
|
|
14
|
+
codePoint -= 0x10000;
|
|
15
|
+
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
|
|
16
|
+
codePoint = 0xdc00 | (codePoint & 0x3ff);
|
|
17
|
+
}
|
|
18
|
+
output += String.fromCharCode(codePoint);
|
|
19
|
+
return output;
|
|
20
|
+
};
|
|
8
21
|
function decodeCodePoint(codePoint) {
|
|
9
22
|
if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
|
|
10
23
|
return "\uFFFD";
|
|
@@ -12,13 +25,6 @@ function decodeCodePoint(codePoint) {
|
|
|
12
25
|
if (codePoint in decode_json_1.default) {
|
|
13
26
|
codePoint = decode_json_1.default[codePoint];
|
|
14
27
|
}
|
|
15
|
-
|
|
16
|
-
if (codePoint > 0xffff) {
|
|
17
|
-
codePoint -= 0x10000;
|
|
18
|
-
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
|
|
19
|
-
codePoint = 0xdc00 | (codePoint & 0x3ff);
|
|
20
|
-
}
|
|
21
|
-
output += String.fromCharCode(codePoint);
|
|
22
|
-
return output;
|
|
28
|
+
return fromCodePoint(codePoint);
|
|
23
29
|
}
|
|
24
30
|
exports.default = decodeCodePoint;
|
package/lib/encode.d.ts
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
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
|
+
*/
|
|
1
8
|
export declare const encodeXML: (data: 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
|
+
*/
|
|
2
19
|
export declare const 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 const 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
|
+
*/
|
|
3
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;
|
|
4
47
|
//# sourceMappingURL=encode.d.ts.map
|
package/lib/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,SAwIJ,MAAM,WAxI4B,CAAC;AAOrD;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,SAkFL,MAAM,WAlFuC,CAAC;AAChE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,SA+Gb,MAAM,WA/GsC,CAAC;AAqF/D;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/lib/encode.js
CHANGED
|
@@ -3,15 +3,40 @@ 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.escape = exports.encodeHTML = exports.encodeXML = void 0;
|
|
6
|
+
exports.escapeUTF8 = exports.escape = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.encodeXML = void 0;
|
|
7
7
|
var xml_json_1 = __importDefault(require("./maps/xml.json"));
|
|
8
8
|
var inverseXML = getInverseObj(xml_json_1.default);
|
|
9
9
|
var xmlReplacer = getInverseReplacer(inverseXML);
|
|
10
|
-
|
|
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);
|
|
11
18
|
var entities_json_1 = __importDefault(require("./maps/entities.json"));
|
|
12
19
|
var inverseHTML = getInverseObj(entities_json_1.default);
|
|
13
20
|
var htmlReplacer = getInverseReplacer(inverseHTML);
|
|
21
|
+
/**
|
|
22
|
+
* Encodes all entities and non-ASCII characters in the input.
|
|
23
|
+
*
|
|
24
|
+
* This includes characters that are valid ASCII characters in HTML documents.
|
|
25
|
+
* For example `#` will be encoded as `#`. To get a more compact output,
|
|
26
|
+
* consider using the `encodeNonAsciiHTML` function.
|
|
27
|
+
*
|
|
28
|
+
* If a character has no equivalent entity, a
|
|
29
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
30
|
+
*/
|
|
14
31
|
exports.encodeHTML = getInverse(inverseHTML, htmlReplacer);
|
|
32
|
+
/**
|
|
33
|
+
* Encodes all non-ASCII characters, as well as characters not valid in HTML
|
|
34
|
+
* documents using HTML entities.
|
|
35
|
+
*
|
|
36
|
+
* If a character has no equivalent entity, a
|
|
37
|
+
* numeric hexadecimal reference (eg. `ü`) will be used.
|
|
38
|
+
*/
|
|
39
|
+
exports.encodeNonAsciiHTML = getASCIIEncoder(inverseHTML);
|
|
15
40
|
function getInverseObj(obj) {
|
|
16
41
|
return Object.keys(obj)
|
|
17
42
|
.sort()
|
|
@@ -52,10 +77,24 @@ function getInverseReplacer(inverse) {
|
|
|
52
77
|
multiple.unshift("[" + single.join("") + "]");
|
|
53
78
|
return new RegExp(multiple.join("|"), "g");
|
|
54
79
|
}
|
|
80
|
+
// /[^\0-\x7F]/gu
|
|
55
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
|
+
};
|
|
56
94
|
function singleCharReplacer(c) {
|
|
57
|
-
|
|
58
|
-
|
|
95
|
+
return "&#x" + (c.length > 1 ? getCodePoint(c) : c.charCodeAt(0))
|
|
96
|
+
.toString(16)
|
|
97
|
+
.toUpperCase() + ";";
|
|
59
98
|
}
|
|
60
99
|
function getInverse(inverse, re) {
|
|
61
100
|
return function (data) {
|
|
@@ -64,10 +103,34 @@ function getInverse(inverse, re) {
|
|
|
64
103
|
.replace(reNonASCII, singleCharReplacer);
|
|
65
104
|
};
|
|
66
105
|
}
|
|
67
|
-
var
|
|
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
|
+
*/
|
|
68
116
|
function escape(data) {
|
|
69
|
-
return data
|
|
70
|
-
.replace(reXmlChars, singleCharReplacer)
|
|
71
|
-
.replace(reNonASCII, singleCharReplacer);
|
|
117
|
+
return data.replace(reEscapeChars, singleCharReplacer);
|
|
72
118
|
}
|
|
73
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
|
+
};
|
|
136
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param data String to decode.
|
|
5
5
|
* @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.
|
|
6
|
+
* @deprecated Use `decodeXML` or `decodeHTML` directly.
|
|
6
7
|
*/
|
|
7
8
|
export declare function decode(data: string, level?: number): string;
|
|
8
9
|
/**
|
|
@@ -10,6 +11,7 @@ export declare function decode(data: string, level?: number): string;
|
|
|
10
11
|
*
|
|
11
12
|
* @param data String to decode.
|
|
12
13
|
* @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.
|
|
14
|
+
* @deprecated Use `decodeHTMLStrict` or `decodeXML` directly.
|
|
13
15
|
*/
|
|
14
16
|
export declare function decodeStrict(data: string, level?: number): string;
|
|
15
17
|
/**
|
|
@@ -17,8 +19,9 @@ export declare function decodeStrict(data: string, level?: number): string;
|
|
|
17
19
|
*
|
|
18
20
|
* @param data String to encode.
|
|
19
21
|
* @param level Optional level to encode at. 0 = XML, 1 = HTML. Default is 0.
|
|
22
|
+
* @deprecated Use `encodeHTML`, `encodeXML` or `encodeNonAsciiHTML` directly.
|
|
20
23
|
*/
|
|
21
24
|
export declare function encode(data: string, level?: number): string;
|
|
22
|
-
export { encodeXML, encodeHTML, escape, encodeHTML as encodeHTML4, encodeHTML as encodeHTML5, } from "./encode";
|
|
25
|
+
export { encodeXML, encodeHTML, encodeNonAsciiHTML, escape, escapeUTF8, encodeHTML as encodeHTML4, encodeHTML as encodeHTML5, } from "./encode";
|
|
23
26
|
export { decodeXML, decodeHTML, decodeHTMLStrict, decodeHTML as decodeHTML4, decodeHTML as decodeHTML5, decodeHTMLStrict as decodeHTML4Strict, decodeHTMLStrict as decodeHTML5Strict, decodeXML as decodeXMLStrict, } from "./decode";
|
|
24
27
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,OAAO,EACH,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,MAAM,EACN,UAAU,EAEV,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,GAC5B,MAAM,UAAU,CAAC;AAElB,OAAO,EACH,SAAS,EACT,UAAU,EACV,gBAAgB,EAEhB,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EACzB,gBAAgB,IAAI,iBAAiB,EACrC,gBAAgB,IAAI,iBAAiB,EACrC,SAAS,IAAI,eAAe,GAC/B,MAAM,UAAU,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.encodeHTML5 = exports.encodeHTML4 = exports.escape = exports.encodeHTML = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = void 0;
|
|
3
|
+
exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.encodeHTML5 = exports.encodeHTML4 = exports.escapeUTF8 = exports.escape = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = void 0;
|
|
4
4
|
var decode_1 = require("./decode");
|
|
5
5
|
var encode_1 = require("./encode");
|
|
6
6
|
/**
|
|
@@ -8,6 +8,7 @@ var encode_1 = require("./encode");
|
|
|
8
8
|
*
|
|
9
9
|
* @param data String to decode.
|
|
10
10
|
* @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.
|
|
11
|
+
* @deprecated Use `decodeXML` or `decodeHTML` directly.
|
|
11
12
|
*/
|
|
12
13
|
function decode(data, level) {
|
|
13
14
|
return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTML)(data);
|
|
@@ -18,6 +19,7 @@ exports.decode = decode;
|
|
|
18
19
|
*
|
|
19
20
|
* @param data String to decode.
|
|
20
21
|
* @param level Optional level to decode at. 0 = XML, 1 = HTML. Default is 0.
|
|
22
|
+
* @deprecated Use `decodeHTMLStrict` or `decodeXML` directly.
|
|
21
23
|
*/
|
|
22
24
|
function decodeStrict(data, level) {
|
|
23
25
|
return (!level || level <= 0 ? decode_1.decodeXML : decode_1.decodeHTMLStrict)(data);
|
|
@@ -28,6 +30,7 @@ exports.decodeStrict = decodeStrict;
|
|
|
28
30
|
*
|
|
29
31
|
* @param data String to encode.
|
|
30
32
|
* @param level Optional level to encode at. 0 = XML, 1 = HTML. Default is 0.
|
|
33
|
+
* @deprecated Use `encodeHTML`, `encodeXML` or `encodeNonAsciiHTML` directly.
|
|
31
34
|
*/
|
|
32
35
|
function encode(data, level) {
|
|
33
36
|
return (!level || level <= 0 ? encode_1.encodeXML : encode_1.encodeHTML)(data);
|
|
@@ -36,15 +39,17 @@ exports.encode = encode;
|
|
|
36
39
|
var encode_2 = require("./encode");
|
|
37
40
|
Object.defineProperty(exports, "encodeXML", { enumerable: true, get: function () { return encode_2.encodeXML; } });
|
|
38
41
|
Object.defineProperty(exports, "encodeHTML", { enumerable: true, get: function () { return encode_2.encodeHTML; } });
|
|
42
|
+
Object.defineProperty(exports, "encodeNonAsciiHTML", { enumerable: true, get: function () { return encode_2.encodeNonAsciiHTML; } });
|
|
39
43
|
Object.defineProperty(exports, "escape", { enumerable: true, get: function () { return encode_2.escape; } });
|
|
40
|
-
|
|
44
|
+
Object.defineProperty(exports, "escapeUTF8", { enumerable: true, get: function () { return encode_2.escapeUTF8; } });
|
|
45
|
+
// Legacy aliases (deprecated)
|
|
41
46
|
Object.defineProperty(exports, "encodeHTML4", { enumerable: true, get: function () { return encode_2.encodeHTML; } });
|
|
42
47
|
Object.defineProperty(exports, "encodeHTML5", { enumerable: true, get: function () { return encode_2.encodeHTML; } });
|
|
43
48
|
var decode_2 = require("./decode");
|
|
44
49
|
Object.defineProperty(exports, "decodeXML", { enumerable: true, get: function () { return decode_2.decodeXML; } });
|
|
45
50
|
Object.defineProperty(exports, "decodeHTML", { enumerable: true, get: function () { return decode_2.decodeHTML; } });
|
|
46
51
|
Object.defineProperty(exports, "decodeHTMLStrict", { enumerable: true, get: function () { return decode_2.decodeHTMLStrict; } });
|
|
47
|
-
// Legacy aliases
|
|
52
|
+
// Legacy aliases (deprecated)
|
|
48
53
|
Object.defineProperty(exports, "decodeHTML4", { enumerable: true, get: function () { return decode_2.decodeHTML; } });
|
|
49
54
|
Object.defineProperty(exports, "decodeHTML5", { enumerable: true, get: function () { return decode_2.decodeHTML; } });
|
|
50
55
|
Object.defineProperty(exports, "decodeHTML4Strict", { enumerable: true, get: function () { return decode_2.decodeHTMLStrict; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "entities",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Encode & decode XML and HTML entities with ease",
|
|
5
5
|
"author": "Felix Boehm <me@feedic.com>",
|
|
6
6
|
"funding": "https://github.com/fb55/entities?sponsor=1",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@typescript-eslint/parser": "^4.4.1",
|
|
29
29
|
"coveralls": "*",
|
|
30
30
|
"eslint": "^7.11.0",
|
|
31
|
-
"eslint-config-prettier": "^
|
|
31
|
+
"eslint-config-prettier": "^7.0.0",
|
|
32
32
|
"eslint-plugin-node": "^11.1.0",
|
|
33
33
|
"jest": "^26.5.3",
|
|
34
34
|
"prettier": "^2.0.5",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"testEnvironment": "node"
|
|
59
59
|
},
|
|
60
60
|
"prettier": {
|
|
61
|
-
"tabWidth": 4
|
|
61
|
+
"tabWidth": 4,
|
|
62
|
+
"proseWrap": "always"
|
|
62
63
|
}
|
|
63
64
|
}
|
package/readme.md
CHANGED
|
@@ -25,7 +25,8 @@ entities.decodeHTML("asdf & ÿ ü '"); // "asdf & ÿ ü '"
|
|
|
25
25
|
|
|
26
26
|
## Performance
|
|
27
27
|
|
|
28
|
-
This is how `entities` compares to other libraries on a very basic benchmark
|
|
28
|
+
This is how `entities` compares to other libraries on a very basic benchmark
|
|
29
|
+
(see `scripts/benchmark.ts`, for 10,000,000 iterations):
|
|
29
30
|
|
|
30
31
|
| Library | `decode` performance | `encode` performance | Bundle size |
|
|
31
32
|
| -------------- | -------------------- | -------------------- | -------------------------------------------------------------------------- |
|
|
@@ -40,11 +41,17 @@ License: BSD-2-Clause
|
|
|
40
41
|
|
|
41
42
|
## Security contact information
|
|
42
43
|
|
|
43
|
-
To report a security vulnerability, please use the
|
|
44
|
-
Tidelift
|
|
44
|
+
To report a security vulnerability, please use the
|
|
45
|
+
[Tidelift security contact](https://tidelift.com/security). Tidelift will
|
|
46
|
+
coordinate the fix and disclosure.
|
|
45
47
|
|
|
46
48
|
## `entities` for enterprise
|
|
47
49
|
|
|
48
50
|
Available as part of the Tidelift Subscription
|
|
49
51
|
|
|
50
|
-
The maintainers of `entities` and thousands of other packages are working with
|
|
52
|
+
The maintainers of `entities` and thousands of other packages are working with
|
|
53
|
+
Tidelift to deliver commercial support and maintenance for the open source
|
|
54
|
+
dependencies you use to build your applications. Save time, reduce risk, and
|
|
55
|
+
improve code health, while paying the maintainers of the exact dependencies you
|
|
56
|
+
use.
|
|
57
|
+
[Learn more.](https://tidelift.com/subscription/pkg/npm-entities?utm_source=npm-entities&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|