entities 4.4.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/commonjs/decode-codepoint.d.ts +19 -0
  2. package/dist/commonjs/decode-codepoint.d.ts.map +1 -0
  3. package/{lib/decode_codepoint.js → dist/commonjs/decode-codepoint.js} +30 -13
  4. package/dist/commonjs/decode-codepoint.js.map +1 -0
  5. package/dist/commonjs/decode.d.ts +209 -0
  6. package/dist/commonjs/decode.d.ts.map +1 -0
  7. package/dist/commonjs/decode.js +514 -0
  8. package/dist/commonjs/decode.js.map +1 -0
  9. package/{lib/esm → dist/commonjs}/encode.d.ts +2 -2
  10. package/dist/commonjs/encode.d.ts.map +1 -0
  11. package/{lib → dist/commonjs}/encode.js +32 -33
  12. package/dist/commonjs/encode.js.map +1 -0
  13. package/{lib/esm → dist/commonjs}/escape.d.ts +2 -2
  14. package/dist/commonjs/escape.d.ts.map +1 -0
  15. package/{lib → dist/commonjs}/escape.js +46 -38
  16. package/dist/commonjs/escape.js.map +1 -0
  17. package/dist/commonjs/generated/decode-data-html.d.ts.map +1 -0
  18. package/{lib → dist/commonjs}/generated/decode-data-html.js +1 -1
  19. package/dist/commonjs/generated/decode-data-html.js.map +1 -0
  20. package/dist/commonjs/generated/decode-data-xml.d.ts.map +1 -0
  21. package/{lib → dist/commonjs}/generated/decode-data-xml.js +1 -1
  22. package/dist/commonjs/generated/decode-data-xml.js.map +1 -0
  23. package/{lib/esm → dist/commonjs}/generated/encode-html.d.ts +1 -1
  24. package/dist/commonjs/generated/encode-html.d.ts.map +1 -0
  25. package/{lib → dist/commonjs}/generated/encode-html.js +4 -4
  26. package/dist/commonjs/generated/encode-html.js.map +1 -0
  27. package/{lib/esm → dist/commonjs}/index.d.ts +9 -15
  28. package/dist/commonjs/index.d.ts.map +1 -0
  29. package/{lib → dist/commonjs}/index.js +46 -55
  30. package/dist/commonjs/index.js.map +1 -0
  31. package/dist/commonjs/package.json +3 -0
  32. package/dist/esm/decode-codepoint.d.ts +19 -0
  33. package/dist/esm/decode-codepoint.d.ts.map +1 -0
  34. package/{lib/esm/decode_codepoint.js → dist/esm/decode-codepoint.js} +25 -8
  35. package/dist/esm/decode-codepoint.js.map +1 -0
  36. package/dist/esm/decode.d.ts +209 -0
  37. package/dist/esm/decode.d.ts.map +1 -0
  38. package/dist/esm/decode.js +497 -0
  39. package/dist/esm/decode.js.map +1 -0
  40. package/{lib → dist/esm}/encode.d.ts +2 -2
  41. package/dist/esm/encode.d.ts.map +1 -0
  42. package/{lib → dist}/esm/encode.js +25 -25
  43. package/dist/esm/encode.js.map +1 -0
  44. package/{lib → dist/esm}/escape.d.ts +2 -2
  45. package/dist/esm/escape.d.ts.map +1 -0
  46. package/{lib → dist}/esm/escape.js +39 -29
  47. package/dist/esm/escape.js.map +1 -0
  48. package/dist/esm/generated/decode-data-html.d.ts.map +1 -0
  49. package/dist/esm/generated/decode-data-html.js.map +1 -0
  50. package/dist/esm/generated/decode-data-xml.d.ts.map +1 -0
  51. package/dist/esm/generated/decode-data-xml.js.map +1 -0
  52. package/{lib → dist/esm}/generated/encode-html.d.ts +1 -1
  53. package/dist/esm/generated/encode-html.d.ts.map +1 -0
  54. package/{lib → dist}/esm/generated/encode-html.js +4 -4
  55. package/dist/esm/generated/encode-html.js.map +1 -0
  56. package/{lib → dist/esm}/index.d.ts +9 -15
  57. package/dist/esm/index.d.ts.map +1 -0
  58. package/{lib → dist}/esm/index.js +36 -45
  59. package/dist/esm/index.js.map +1 -0
  60. package/dist/esm/package.json +3 -0
  61. package/package.json +96 -66
  62. package/readme.md +5 -5
  63. package/src/decode-codepoint.ts +81 -0
  64. package/src/decode.spec.ts +320 -0
  65. package/src/decode.ts +620 -0
  66. package/src/encode.spec.ts +78 -0
  67. package/src/encode.ts +77 -0
  68. package/src/escape.spec.ts +14 -0
  69. package/src/escape.ts +144 -0
  70. package/src/generated/.eslintrc.json +10 -0
  71. package/src/generated/decode-data-html.ts +8 -0
  72. package/src/generated/decode-data-xml.ts +8 -0
  73. package/src/generated/encode-html.ts +17 -0
  74. package/src/index.spec.ts +125 -0
  75. package/src/index.ts +185 -0
  76. package/lib/decode.d.ts +0 -33
  77. package/lib/decode.d.ts.map +0 -1
  78. package/lib/decode.js +0 -179
  79. package/lib/decode.js.map +0 -1
  80. package/lib/decode_codepoint.d.ts +0 -4
  81. package/lib/decode_codepoint.d.ts.map +0 -1
  82. package/lib/decode_codepoint.js.map +0 -1
  83. package/lib/encode.d.ts.map +0 -1
  84. package/lib/encode.js.map +0 -1
  85. package/lib/escape.d.ts.map +0 -1
  86. package/lib/escape.js.map +0 -1
  87. package/lib/esm/decode.d.ts +0 -33
  88. package/lib/esm/decode.d.ts.map +0 -1
  89. package/lib/esm/decode.js +0 -166
  90. package/lib/esm/decode.js.map +0 -1
  91. package/lib/esm/decode_codepoint.d.ts +0 -4
  92. package/lib/esm/decode_codepoint.d.ts.map +0 -1
  93. package/lib/esm/decode_codepoint.js.map +0 -1
  94. package/lib/esm/encode.d.ts.map +0 -1
  95. package/lib/esm/encode.js.map +0 -1
  96. package/lib/esm/escape.d.ts.map +0 -1
  97. package/lib/esm/escape.js.map +0 -1
  98. package/lib/esm/generated/decode-data-html.d.ts.map +0 -1
  99. package/lib/esm/generated/decode-data-html.js.map +0 -1
  100. package/lib/esm/generated/decode-data-xml.d.ts.map +0 -1
  101. package/lib/esm/generated/decode-data-xml.js.map +0 -1
  102. package/lib/esm/generated/encode-html.d.ts.map +0 -1
  103. package/lib/esm/generated/encode-html.js.map +0 -1
  104. package/lib/esm/index.d.ts.map +0 -1
  105. package/lib/esm/index.js.map +0 -1
  106. package/lib/esm/package.json +0 -1
  107. package/lib/generated/decode-data-html.d.ts.map +0 -1
  108. package/lib/generated/decode-data-html.js.map +0 -1
  109. package/lib/generated/decode-data-xml.d.ts.map +0 -1
  110. package/lib/generated/decode-data-xml.js.map +0 -1
  111. package/lib/generated/encode-html.d.ts.map +0 -1
  112. package/lib/generated/encode-html.js.map +0 -1
  113. package/lib/index.d.ts.map +0 -1
  114. package/lib/index.js.map +0 -1
  115. /package/{lib/esm → dist/commonjs}/generated/decode-data-html.d.ts +0 -0
  116. /package/{lib/esm → dist/commonjs}/generated/decode-data-xml.d.ts +0 -0
  117. /package/{lib → dist/esm}/generated/decode-data-html.d.ts +0 -0
  118. /package/{lib → dist}/esm/generated/decode-data-html.js +0 -0
  119. /package/{lib → dist/esm}/generated/decode-data-xml.d.ts +0 -0
  120. /package/{lib → dist}/esm/generated/decode-data-xml.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,YAAY,EAAE,MAAM,aAAa,CAAC;AASlE,wCAAwC;AACxC,oBAAY,WAAW;IACnB,iCAAiC;IACjC,GAAG,IAAI;IACP,mEAAmE;IACnE,IAAI,IAAI;CACX;AAED,oBAAY,YAAY;IACpB;;;OAGG;IACH,IAAI,IAAA;IACJ;;;;OAIG;IACH,KAAK,IAAA;IACL;;;OAGG;IACH,SAAS,IAAA;IACT;;;OAGG;IACH,SAAS,IAAA;IACT;;;OAGG;IACH,IAAI,IAAA;CACP;AAED,MAAM,WAAW,eAAe;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;;;;;;OAUG;IACH,IAAI,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAe,GAAG,WAA6B,GACzD,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAe,GAAG,WAA6B,GACzD,MAAM,CAMR;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;OAGG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAe,GAAG,WAA6B,GACzD,MAAM,CAwBR;AAED,OAAO,EACH,SAAS,EACT,MAAM,EACN,UAAU,EACV,eAAe,EACf,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,UAAU,EACV,kBAAkB,EAElB,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,GAC5B,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,aAAa,EACb,YAAY,EACZ,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EAEnB,UAAU,IAAI,WAAW,EACzB,UAAU,IAAI,WAAW,EACzB,gBAAgB,IAAI,iBAAiB,EACrC,gBAAgB,IAAI,iBAAiB,EACrC,SAAS,IAAI,eAAe,GAC/B,MAAM,aAAa,CAAC"}
@@ -1,9 +1,12 @@
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.encodeNonAsciiHTML = exports.encodeHTML = exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.escape = exports.encodeXML = exports.encode = exports.decodeStrict = exports.decode = exports.EncodingMode = exports.DecodingMode = exports.EntityLevel = void 0;
4
- var decode_js_1 = require("./decode.js");
5
- var encode_js_1 = require("./encode.js");
6
- var escape_js_1 = require("./escape.js");
3
+ exports.decodeXMLStrict = exports.decodeHTML5Strict = exports.decodeHTML4Strict = exports.decodeHTML5 = exports.decodeHTML4 = exports.decodeHTMLAttribute = exports.decodeHTMLStrict = exports.decodeHTML = exports.decodeXML = exports.DecodingMode = exports.EntityDecoder = exports.encodeHTML5 = exports.encodeHTML4 = exports.encodeNonAsciiHTML = exports.encodeHTML = exports.escapeText = exports.escapeAttribute = exports.escapeUTF8 = exports.encodeXML = exports.EncodingMode = exports.EntityLevel = void 0;
4
+ exports.decode = decode;
5
+ exports.decodeStrict = decodeStrict;
6
+ exports.encode = encode;
7
+ const decode_js_1 = require("./decode.js");
8
+ const encode_js_1 = require("./encode.js");
9
+ const escape_js_1 = require("./escape.js");
7
10
  /** The level of entities to support. */
8
11
  var EntityLevel;
9
12
  (function (EntityLevel) {
@@ -11,15 +14,7 @@ var EntityLevel;
11
14
  EntityLevel[EntityLevel["XML"] = 0] = "XML";
12
15
  /** Support HTML entities, which are a superset of XML entities. */
13
16
  EntityLevel[EntityLevel["HTML"] = 1] = "HTML";
14
- })(EntityLevel = exports.EntityLevel || (exports.EntityLevel = {}));
15
- /** Determines whether some entities are allowed to be written without a trailing `;`. */
16
- var DecodingMode;
17
- (function (DecodingMode) {
18
- /** Support legacy HTML entities. */
19
- DecodingMode[DecodingMode["Legacy"] = 0] = "Legacy";
20
- /** Do not support legacy HTML entities. */
21
- DecodingMode[DecodingMode["Strict"] = 1] = "Strict";
22
- })(DecodingMode = exports.DecodingMode || (exports.DecodingMode = {}));
17
+ })(EntityLevel || (exports.EntityLevel = EntityLevel = {}));
23
18
  var EncodingMode;
24
19
  (function (EncodingMode) {
25
20
  /**
@@ -48,70 +43,63 @@ var EncodingMode;
48
43
  * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
49
44
  */
50
45
  EncodingMode[EncodingMode["Text"] = 4] = "Text";
51
- })(EncodingMode = exports.EncodingMode || (exports.EncodingMode = {}));
46
+ })(EncodingMode || (exports.EncodingMode = EncodingMode = {}));
52
47
  /**
53
48
  * Decodes a string with entities.
54
49
  *
55
- * @param data String to decode.
50
+ * @param input String to decode.
56
51
  * @param options Decoding options.
57
52
  */
58
- function decode(data, options) {
59
- if (options === void 0) { options = EntityLevel.XML; }
60
- var opts = typeof options === "number" ? { level: options } : options;
61
- if (opts.level === EntityLevel.HTML) {
62
- if (opts.mode === DecodingMode.Strict) {
63
- return (0, decode_js_1.decodeHTMLStrict)(data);
64
- }
65
- return (0, decode_js_1.decodeHTML)(data);
53
+ function decode(input, options = EntityLevel.XML) {
54
+ const level = typeof options === "number" ? options : options.level;
55
+ if (level === EntityLevel.HTML) {
56
+ const mode = typeof options === "object" ? options.mode : undefined;
57
+ return (0, decode_js_1.decodeHTML)(input, mode);
66
58
  }
67
- return (0, decode_js_1.decodeXML)(data);
59
+ return (0, decode_js_1.decodeXML)(input);
68
60
  }
69
- exports.decode = decode;
70
61
  /**
71
62
  * Decodes a string with entities. Does not allow missing trailing semicolons for entities.
72
63
  *
73
- * @param data String to decode.
64
+ * @param input String to decode.
74
65
  * @param options Decoding options.
75
66
  * @deprecated Use `decode` with the `mode` set to `Strict`.
76
67
  */
77
- function decodeStrict(data, options) {
78
- if (options === void 0) { options = EntityLevel.XML; }
79
- var opts = typeof options === "number" ? { level: options } : options;
80
- if (opts.level === EntityLevel.HTML) {
81
- if (opts.mode === DecodingMode.Legacy) {
82
- return (0, decode_js_1.decodeHTML)(data);
83
- }
84
- return (0, decode_js_1.decodeHTMLStrict)(data);
85
- }
86
- return (0, decode_js_1.decodeXML)(data);
68
+ function decodeStrict(input, options = EntityLevel.XML) {
69
+ var _a;
70
+ const normalizedOptions = typeof options === "number" ? { level: options } : options;
71
+ (_a = normalizedOptions.mode) !== null && _a !== void 0 ? _a : (normalizedOptions.mode = decode_js_1.DecodingMode.Strict);
72
+ return decode(input, normalizedOptions);
87
73
  }
88
- exports.decodeStrict = decodeStrict;
89
74
  /**
90
75
  * Encodes a string with entities.
91
76
  *
92
- * @param data String to encode.
77
+ * @param input String to encode.
93
78
  * @param options Encoding options.
94
79
  */
95
- function encode(data, options) {
96
- if (options === void 0) { options = EntityLevel.XML; }
97
- var opts = typeof options === "number" ? { level: options } : options;
98
- // Mode `UTF8` just escapes XML entities
99
- if (opts.mode === EncodingMode.UTF8)
100
- return (0, escape_js_1.escapeUTF8)(data);
101
- if (opts.mode === EncodingMode.Attribute)
102
- return (0, escape_js_1.escapeAttribute)(data);
103
- if (opts.mode === EncodingMode.Text)
104
- return (0, escape_js_1.escapeText)(data);
105
- if (opts.level === EntityLevel.HTML) {
106
- if (opts.mode === EncodingMode.ASCII) {
107
- return (0, encode_js_1.encodeNonAsciiHTML)(data);
80
+ function encode(input, options = EntityLevel.XML) {
81
+ const { mode = EncodingMode.Extensive, level = EntityLevel.XML } = typeof options === "number" ? { level: options } : options;
82
+ switch (mode) {
83
+ case EncodingMode.UTF8: {
84
+ return (0, escape_js_1.escapeUTF8)(input);
85
+ }
86
+ case EncodingMode.Attribute: {
87
+ return (0, escape_js_1.escapeAttribute)(input);
88
+ }
89
+ case EncodingMode.Text: {
90
+ return (0, escape_js_1.escapeText)(input);
91
+ }
92
+ default: {
93
+ if (level === EntityLevel.HTML) {
94
+ if (mode === EncodingMode.ASCII) {
95
+ return (0, encode_js_1.encodeNonAsciiHTML)(input);
96
+ }
97
+ return (0, encode_js_1.encodeHTML)(input);
98
+ }
99
+ return (0, escape_js_1.encodeXML)(input);
108
100
  }
109
- return (0, encode_js_1.encodeHTML)(data);
110
101
  }
111
- // ASCII and Extensive are equivalent
112
- return (0, escape_js_1.encodeXML)(data);
113
102
  }
114
- exports.encode = encode;
115
103
  var escape_js_2 = require("./escape.js");
116
104
  Object.defineProperty(exports, "encodeXML", { enumerable: true, get: function () { return escape_js_2.encodeXML; } });
117
105
  Object.defineProperty(exports, "escape", { enumerable: true, get: function () { return escape_js_2.escape; } });
@@ -125,9 +113,12 @@ Object.defineProperty(exports, "encodeNonAsciiHTML", { enumerable: true, get: fu
125
113
  Object.defineProperty(exports, "encodeHTML4", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } });
126
114
  Object.defineProperty(exports, "encodeHTML5", { enumerable: true, get: function () { return encode_js_2.encodeHTML; } });
127
115
  var decode_js_2 = require("./decode.js");
116
+ Object.defineProperty(exports, "EntityDecoder", { enumerable: true, get: function () { return decode_js_2.EntityDecoder; } });
117
+ Object.defineProperty(exports, "DecodingMode", { enumerable: true, get: function () { return decode_js_2.DecodingMode; } });
128
118
  Object.defineProperty(exports, "decodeXML", { enumerable: true, get: function () { return decode_js_2.decodeXML; } });
129
119
  Object.defineProperty(exports, "decodeHTML", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } });
130
120
  Object.defineProperty(exports, "decodeHTMLStrict", { enumerable: true, get: function () { return decode_js_2.decodeHTMLStrict; } });
121
+ Object.defineProperty(exports, "decodeHTMLAttribute", { enumerable: true, get: function () { return decode_js_2.decodeHTMLAttribute; } });
131
122
  // Legacy aliases (deprecated)
132
123
  Object.defineProperty(exports, "decodeHTML4", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } });
133
124
  Object.defineProperty(exports, "decodeHTML5", { enumerable: true, get: function () { return decode_js_2.decodeHTML; } });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAwEA,wBAYC;AASD,oCASC;AAwBD,wBA2BC;AAzJD,2CAAkE;AAClE,2CAA6D;AAC7D,2CAKqB;AAErB,wCAAwC;AACxC,IAAY,WAKX;AALD,WAAY,WAAW;IACnB,iCAAiC;IACjC,2CAAO,CAAA;IACP,mEAAmE;IACnE,6CAAQ,CAAA;AACZ,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAED,IAAY,YA2BX;AA3BD,WAAY,YAAY;IACpB;;;OAGG;IACH,+CAAI,CAAA;IACJ;;;;OAIG;IACH,iDAAK,CAAA;IACL;;;OAGG;IACH,yDAAS,CAAA;IACT;;;OAGG;IACH,yDAAS,CAAA;IACT;;;OAGG;IACH,+CAAI,CAAA;AACR,CAAC,EA3BW,YAAY,4BAAZ,YAAY,QA2BvB;AAsBD;;;;;GAKG;AACH,SAAgB,MAAM,CAClB,KAAa,EACb,UAAyC,WAAW,CAAC,GAAG;IAExD,MAAM,KA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`. It is used to create a string from a Unicode code point.
3
+ */
4
+ export declare const fromCodePoint: (...codePoints: number[]) => string;
5
+ /**
6
+ * Replace the given code point with a replacement character if it is a
7
+ * surrogate or is outside the valid range. Otherwise return the code
8
+ * point unchanged.
9
+ */
10
+ export declare function replaceCodePoint(codePoint: number): number;
11
+ /**
12
+ * Replace the code point if relevant, then convert it to a string.
13
+ *
14
+ * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.
15
+ * @param codePoint The code point to decode.
16
+ * @returns The decoded code point.
17
+ */
18
+ export default function decodeCodePoint(codePoint: number): string;
19
+ //# sourceMappingURL=decode-codepoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-codepoint.d.ts","sourceRoot":"","sources":["../../src/decode-codepoint.ts"],"names":[],"mappings":"AAkCA;;GAEG;AACH,eAAO,MAAM,aAAa,qCAgBrB,CAAC;AAEN;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,UASjD;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjE"}
@@ -2,6 +2,7 @@
2
2
  var _a;
3
3
  const decodeMap = new Map([
4
4
  [0, 65533],
5
+ // C1 Unicode control character reference replacements
5
6
  [128, 8364],
6
7
  [130, 8218],
7
8
  [131, 402],
@@ -30,26 +31,42 @@ const decodeMap = new Map([
30
31
  [158, 382],
31
32
  [159, 376],
32
33
  ]);
34
+ /**
35
+ * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
36
+ */
33
37
  export const fromCodePoint =
34
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
38
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, n/no-unsupported-features/es-builtins
35
39
  (_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) {
36
40
  let output = "";
37
- if (codePoint > 0xffff) {
38
- codePoint -= 0x10000;
39
- output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
40
- codePoint = 0xdc00 | (codePoint & 0x3ff);
41
+ if (codePoint > 65535) {
42
+ codePoint -= 65536;
43
+ output += String.fromCharCode(((codePoint >>> 10) & 1023) | 55296);
44
+ codePoint = 56320 | (codePoint & 1023);
41
45
  }
42
46
  output += String.fromCharCode(codePoint);
43
47
  return output;
44
48
  };
49
+ /**
50
+ * Replace the given code point with a replacement character if it is a
51
+ * surrogate or is outside the valid range. Otherwise return the code
52
+ * point unchanged.
53
+ */
45
54
  export function replaceCodePoint(codePoint) {
46
55
  var _a;
47
- if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
48
- return 0xfffd;
56
+ if ((codePoint >= 55296 && codePoint <= 57343) ||
57
+ codePoint > 1114111) {
58
+ return 65533;
49
59
  }
50
60
  return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
51
61
  }
62
+ /**
63
+ * Replace the code point if relevant, then convert it to a string.
64
+ *
65
+ * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead.
66
+ * @param codePoint The code point to decode.
67
+ * @returns The decoded code point.
68
+ */
52
69
  export default function decodeCodePoint(codePoint) {
53
70
  return fromCodePoint(replaceCodePoint(codePoint));
54
71
  }
55
- //# sourceMappingURL=decode_codepoint.js.map
72
+ //# 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,KAAM,CAAC;IACX,sDAAsD;IACtD,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,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IAED,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEN;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB;;IAC9C,IACI,CAAC,SAAS,IAAI,KAAO,IAAI,SAAS,IAAI,KAAO,CAAC;QAC9C,SAAS,GAAG,OAAU,EACxB,CAAC;QACC,OAAO,KAAO,CAAC;IACnB,CAAC;IAED,OAAO,MAAA,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,mCAAI,SAAS,CAAC;AACjD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,SAAiB;IACrD,OAAO,aAAa,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,209 @@
1
+ export declare enum BinTrieFlags {
2
+ VALUE_LENGTH = 49152,
3
+ BRANCH_LENGTH = 16256,
4
+ JUMP_TABLE = 127
5
+ }
6
+ export declare enum DecodingMode {
7
+ /** Entities in text nodes that can end with any character. */
8
+ Legacy = 0,
9
+ /** Only allow entities terminated with a semicolon. */
10
+ Strict = 1,
11
+ /** Entities in attributes have limitations on ending characters. */
12
+ Attribute = 2
13
+ }
14
+ /**
15
+ * Producers for character reference errors as defined in the HTML spec.
16
+ */
17
+ export interface EntityErrorProducer {
18
+ missingSemicolonAfterCharacterReference(): void;
19
+ absenceOfDigitsInNumericCharacterReference(consumedCharacters: number): void;
20
+ validateNumericCharacterReference(code: number): void;
21
+ }
22
+ /**
23
+ * Token decoder with support of writing partial entities.
24
+ */
25
+ export declare class EntityDecoder {
26
+ /** The tree used to decode entities. */
27
+ private readonly decodeTree;
28
+ /**
29
+ * The function that is called when a codepoint is decoded.
30
+ *
31
+ * For multi-byte named entities, this will be called multiple times,
32
+ * with the second codepoint, and the same `consumed` value.
33
+ *
34
+ * @param codepoint The decoded codepoint.
35
+ * @param consumed The number of bytes consumed by the decoder.
36
+ */
37
+ private readonly emitCodePoint;
38
+ /** An object that is used to produce errors. */
39
+ private readonly errors?;
40
+ constructor(
41
+ /** The tree used to decode entities. */
42
+ decodeTree: Uint16Array,
43
+ /**
44
+ * The function that is called when a codepoint is decoded.
45
+ *
46
+ * For multi-byte named entities, this will be called multiple times,
47
+ * with the second codepoint, and the same `consumed` value.
48
+ *
49
+ * @param codepoint The decoded codepoint.
50
+ * @param consumed The number of bytes consumed by the decoder.
51
+ */
52
+ emitCodePoint: (cp: number, consumed: number) => void,
53
+ /** An object that is used to produce errors. */
54
+ errors?: EntityErrorProducer | undefined);
55
+ /** The current state of the decoder. */
56
+ private state;
57
+ /** Characters that were consumed while parsing an entity. */
58
+ private consumed;
59
+ /**
60
+ * The result of the entity.
61
+ *
62
+ * Either the result index of a numeric entity, or the codepoint of a
63
+ * numeric entity.
64
+ */
65
+ private result;
66
+ /** The current index in the decode tree. */
67
+ private treeIndex;
68
+ /** The number of characters that were consumed in excess. */
69
+ private excess;
70
+ /** The mode in which the decoder is operating. */
71
+ private decodeMode;
72
+ /** Resets the instance to make it reusable. */
73
+ startEntity(decodeMode: DecodingMode): void;
74
+ /**
75
+ * Write an entity to the decoder. This can be called multiple times with partial entities.
76
+ * If the entity is incomplete, the decoder will return -1.
77
+ *
78
+ * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
79
+ * entity is incomplete, and resume when the next string is written.
80
+ *
81
+ * @param input The string containing the entity (or a continuation of the entity).
82
+ * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
83
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
84
+ */
85
+ write(input: string, offset: number): number;
86
+ /**
87
+ * Switches between the numeric decimal and hexadecimal states.
88
+ *
89
+ * Equivalent to the `Numeric character reference state` in the HTML spec.
90
+ *
91
+ * @param input The string containing the entity (or a continuation of the entity).
92
+ * @param offset The current offset.
93
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
94
+ */
95
+ private stateNumericStart;
96
+ private addToNumericResult;
97
+ /**
98
+ * Parses a hexadecimal numeric entity.
99
+ *
100
+ * Equivalent to the `Hexademical character reference state` in the HTML spec.
101
+ *
102
+ * @param input The string containing the entity (or a continuation of the entity).
103
+ * @param offset The current offset.
104
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
105
+ */
106
+ private stateNumericHex;
107
+ /**
108
+ * Parses a decimal numeric entity.
109
+ *
110
+ * Equivalent to the `Decimal character reference state` in the HTML spec.
111
+ *
112
+ * @param input The string containing the entity (or a continuation of the entity).
113
+ * @param offset The current offset.
114
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
115
+ */
116
+ private stateNumericDecimal;
117
+ /**
118
+ * Validate and emit a numeric entity.
119
+ *
120
+ * Implements the logic from the `Hexademical character reference start
121
+ * state` and `Numeric character reference end state` in the HTML spec.
122
+ *
123
+ * @param lastCp The last code point of the entity. Used to see if the
124
+ * entity was terminated with a semicolon.
125
+ * @param expectedLength The minimum number of characters that should be
126
+ * consumed. Used to validate that at least one digit
127
+ * was consumed.
128
+ * @returns The number of characters that were consumed.
129
+ */
130
+ private emitNumericEntity;
131
+ /**
132
+ * Parses a named entity.
133
+ *
134
+ * Equivalent to the `Named character reference state` in the HTML spec.
135
+ *
136
+ * @param input The string containing the entity (or a continuation of the entity).
137
+ * @param offset The current offset.
138
+ * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
139
+ */
140
+ private stateNamedEntity;
141
+ /**
142
+ * Emit a named entity that was not terminated with a semicolon.
143
+ *
144
+ * @returns The number of characters consumed.
145
+ */
146
+ private emitNotTerminatedNamedEntity;
147
+ /**
148
+ * Emit a named entity.
149
+ *
150
+ * @param result The index of the entity in the decode tree.
151
+ * @param valueLength The number of bytes in the entity.
152
+ * @param consumed The number of characters consumed.
153
+ *
154
+ * @returns The number of characters consumed.
155
+ */
156
+ private emitNamedEntityData;
157
+ /**
158
+ * Signal to the parser that the end of the input was reached.
159
+ *
160
+ * Remaining data will be emitted and relevant errors will be produced.
161
+ *
162
+ * @returns The number of characters consumed.
163
+ */
164
+ end(): number;
165
+ }
166
+ /**
167
+ * Determines the branch of the current node that is taken given the current
168
+ * character. This function is used to traverse the trie.
169
+ *
170
+ * @param decodeTree The trie.
171
+ * @param current The current node.
172
+ * @param nodeIdx The index right after the current node and its value.
173
+ * @param char The current character.
174
+ * @returns The index of the next node, or -1 if no branch is taken.
175
+ */
176
+ export declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIndex: number, char: number): number;
177
+ /**
178
+ * Decodes an HTML string.
179
+ *
180
+ * @param htmlString The string to decode.
181
+ * @param mode The decoding mode.
182
+ * @returns The decoded string.
183
+ */
184
+ export declare function decodeHTML(htmlString: string, mode?: DecodingMode): string;
185
+ /**
186
+ * Decodes an HTML string in an attribute.
187
+ *
188
+ * @param htmlAttribute The string to decode.
189
+ * @returns The decoded string.
190
+ */
191
+ export declare function decodeHTMLAttribute(htmlAttribute: string): string;
192
+ /**
193
+ * Decodes an HTML string, requiring all entities to be terminated by a semicolon.
194
+ *
195
+ * @param htmlString The string to decode.
196
+ * @returns The decoded string.
197
+ */
198
+ export declare function decodeHTMLStrict(htmlString: string): string;
199
+ /**
200
+ * Decodes an XML string, requiring all entities to be terminated by a semicolon.
201
+ *
202
+ * @param xmlString The string to decode.
203
+ * @returns The decoded string.
204
+ */
205
+ export declare function decodeXML(xmlString: string): string;
206
+ export { default as htmlDecodeTree } from "./generated/decode-data-html.js";
207
+ export { default as xmlDecodeTree } from "./generated/decode-data-xml.js";
208
+ export { default as decodeCodePoint, replaceCodePoint, fromCodePoint, } from "./decode-codepoint.js";
209
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AAsBA,oBAAY,YAAY;IACpB,YAAY,QAAwB;IACpC,aAAa,QAAwB;IACrC,UAAU,MAAwB;CACrC;AAuCD,oBAAY,YAAY;IACpB,8DAA8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