entities 3.0.0 → 3.0.1

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 CHANGED
@@ -1,18 +1,6 @@
1
1
  import htmlDecodeTree from "./generated/decode-data-html";
2
2
  import xmlDecodeTree from "./generated/decode-data-xml";
3
3
  export { htmlDecodeTree, xmlDecodeTree };
4
- export declare enum CharCodes {
5
- NUM,
6
- SEMI,
7
- ZERO,
8
- NINE,
9
- LOWER_A,
10
- UPPER_A,
11
- LOWER_F,
12
- UPPER_F,
13
- LOWER_X,
14
- UPPER_X
15
- }
16
4
  export declare enum BinTrieFlags {
17
5
  HAS_VALUE = 32768,
18
6
  BRANCH_LENGTH = 32512,
@@ -1 +1 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAC1D,OAAO,aAAa,MAAM,6BAA6B,CAAC;AAIxD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAEzC,oBAAY,SAAS;IACjB,GAAuB;IACvB,IAAwB;IACxB,IAAwB;IACxB,IAAwB;IACxB,OAA2B;IAC3B,OAA2B;IAC3B,OAA2B;IAC3B,OAA2B;IAC3B,OAA2B;IAC3B,OAA2B;CAC9B;AAED,oBAAY,YAAY;IACpB,SAAS,QAAwB;IACjC,aAAa,QAAwB;IACrC,UAAU,MAAwB;IAClC,UAAU,MAAwB;CACrC;AAED,eAAO,MAAM,gBAAgB,QAAqB,CAAC;AAoGnD,wBAAgB,eAAe,CAC3B,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACb,MAAM,CA0CR;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"}
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAC1D,OAAO,aAAa,MAAM,6BAA6B,CAAC;AAIxD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAczC,oBAAY,YAAY;IACpB,SAAS,QAAwB;IACjC,aAAa,QAAwB;IACrC,UAAU,MAAwB;IAClC,UAAU,MAAwB;CACrC;AAED,eAAO,MAAM,gBAAgB,QAAqB,CAAC;AAmGnD,wBAAgB,eAAe,CAC3B,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACb,MAAM,CA0CR;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,25 +3,12 @@ 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.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.JUMP_OFFSET_BASE = exports.BinTrieFlags = exports.CharCodes = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
6
+ exports.decodeXML = exports.decodeHTMLStrict = exports.decodeHTML = exports.determineBranch = exports.JUMP_OFFSET_BASE = exports.BinTrieFlags = exports.xmlDecodeTree = exports.htmlDecodeTree = void 0;
7
7
  var decode_data_html_1 = __importDefault(require("./generated/decode-data-html"));
8
8
  exports.htmlDecodeTree = decode_data_html_1.default;
9
9
  var decode_data_xml_1 = __importDefault(require("./generated/decode-data-xml"));
10
10
  exports.xmlDecodeTree = decode_data_xml_1.default;
11
11
  var decode_codepoint_1 = __importDefault(require("./decode_codepoint"));
12
- var CharCodes;
13
- (function (CharCodes) {
14
- CharCodes[CharCodes["NUM"] = "#".charCodeAt(0)] = "NUM";
15
- CharCodes[CharCodes["SEMI"] = ";".charCodeAt(0)] = "SEMI";
16
- CharCodes[CharCodes["ZERO"] = "0".charCodeAt(0)] = "ZERO";
17
- CharCodes[CharCodes["NINE"] = "9".charCodeAt(0)] = "NINE";
18
- CharCodes[CharCodes["LOWER_A"] = "a".charCodeAt(0)] = "LOWER_A";
19
- CharCodes[CharCodes["UPPER_A"] = "A".charCodeAt(0)] = "UPPER_A";
20
- CharCodes[CharCodes["LOWER_F"] = "f".charCodeAt(0)] = "LOWER_F";
21
- CharCodes[CharCodes["UPPER_F"] = "F".charCodeAt(0)] = "UPPER_F";
22
- CharCodes[CharCodes["LOWER_X"] = "x".charCodeAt(0)] = "LOWER_X";
23
- CharCodes[CharCodes["UPPER_X"] = "X".charCodeAt(0)] = "UPPER_X";
24
- })(CharCodes = exports.CharCodes || (exports.CharCodes = {}));
25
12
  var BinTrieFlags;
26
13
  (function (BinTrieFlags) {
27
14
  BinTrieFlags[BinTrieFlags["HAS_VALUE"] = 32768] = "HAS_VALUE";
@@ -29,7 +16,7 @@ var BinTrieFlags;
29
16
  BinTrieFlags[BinTrieFlags["MULTI_BYTE"] = 128] = "MULTI_BYTE";
30
17
  BinTrieFlags[BinTrieFlags["JUMP_TABLE"] = 127] = "JUMP_TABLE";
31
18
  })(BinTrieFlags = exports.BinTrieFlags || (exports.BinTrieFlags = {}));
32
- exports.JUMP_OFFSET_BASE = CharCodes.ZERO - 1;
19
+ exports.JUMP_OFFSET_BASE = 48 /* ZERO */ - 1;
33
20
  function getDecoder(decodeTree) {
34
21
  return function decodeHTMLBinary(str, strict) {
35
22
  var ret = "";
@@ -41,27 +28,26 @@ function getDecoder(decodeTree) {
41
28
  // Skip the "&"
42
29
  strIdx += 1;
43
30
  // If we have a numeric entity, handle this separately.
44
- if (str.charCodeAt(strIdx) === CharCodes.NUM) {
31
+ if (str.charCodeAt(strIdx) === 35 /* NUM */) {
45
32
  // Skip the leading "&#". For hex entities, also skip the leading "x".
46
33
  var start = strIdx + 1;
47
34
  var base = 10;
48
35
  var cp = str.charCodeAt(start);
49
- if (cp === CharCodes.LOWER_X || cp === CharCodes.UPPER_X) {
36
+ if ((cp | 32 /* To_LOWER_BIT */) === 120 /* LOWER_X */) {
50
37
  base = 16;
51
38
  strIdx += 1;
52
39
  start += 1;
53
40
  }
54
- while (((cp = str.charCodeAt(++strIdx)) >= CharCodes.ZERO &&
55
- cp <= CharCodes.NINE) ||
41
+ while (((cp = str.charCodeAt(++strIdx)) >= 48 /* ZERO */ &&
42
+ cp <= 57 /* NINE */) ||
56
43
  (base === 16 &&
57
- ((cp >= CharCodes.LOWER_A && cp <= CharCodes.LOWER_F) ||
58
- (cp >= CharCodes.UPPER_A &&
59
- cp <= CharCodes.UPPER_F))))
44
+ (cp | 32 /* To_LOWER_BIT */) >= 97 /* LOWER_A */ &&
45
+ (cp | 32 /* To_LOWER_BIT */) <= 102 /* LOWER_F */))
60
46
  ;
61
47
  if (start !== strIdx) {
62
48
  var entity = str.substring(start, strIdx);
63
49
  var parsed = parseInt(entity, base);
64
- if (str.charCodeAt(strIdx) === CharCodes.SEMI) {
50
+ if (str.charCodeAt(strIdx) === 59 /* SEMI */) {
65
51
  strIdx += 1;
66
52
  }
67
53
  else if (strict) {
@@ -84,7 +70,7 @@ function getDecoder(decodeTree) {
84
70
  // If the branch is a value, store it and continue
85
71
  if (current & BinTrieFlags.HAS_VALUE) {
86
72
  // If we have a legacy entity while parsing strictly, just skip the number of bytes
87
- if (strict && str.charCodeAt(strIdx) !== CharCodes.SEMI) {
73
+ if (strict && str.charCodeAt(strIdx) !== 59 /* SEMI */) {
88
74
  // No need to consider multi-byte values, as the legacy entity is always a single byte
89
75
  treeIdx += 1;
90
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"encode-trie.d.ts","sourceRoot":"","sources":["../src/encode-trie.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,QAGT,MAAM,SAAS,MAAM,KAAG,MAQD,CAAC;AAIxC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAkCpE;AAED,MAAM,WAAW,QAAQ;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAChC;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAmB1E"}
1
+ {"version":3,"file":"encode-trie.d.ts","sourceRoot":"","sources":["../src/encode-trie.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,QAGT,MAAM,SAAS,MAAM,KAAG,MAQD,CAAC;AAIxC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAkCpE;AAED,MAAM,WAAW,QAAQ;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAChC;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAmB1E"}
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getTrie = exports.encodeHTMLTrieRe = exports.getCodePoint = void 0;
7
7
  var entities_json_1 = __importDefault(require("./maps/entities.json"));
8
+ function isHighSurrugate(c) {
9
+ return (c & 64512 /* Mask */) === 55296 /* High */;
10
+ }
8
11
  // For compatibility with node < 4, we wrap `codePointAt`
9
12
  exports.getCodePoint =
10
13
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -12,8 +15,8 @@ String.prototype.codePointAt != null
12
15
  ? function (str, index) { return str.codePointAt(index); }
13
16
  : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
14
17
  function (c, index) {
15
- return (c.charCodeAt(index) & 0xd800) === 0xd800
16
- ? (c.charCodeAt(index) - 0xd800) * 0x400 +
18
+ return isHighSurrugate(c.charCodeAt(index))
19
+ ? (c.charCodeAt(index) - 55296 /* High */) * 0x400 +
17
20
  c.charCodeAt(index + 1) -
18
21
  0xdc00 +
19
22
  0x10000
@@ -45,7 +48,7 @@ function encodeHTMLTrieRe(regExp, str) {
45
48
  else {
46
49
  ret += str.substring(lastIdx, i) + "&#x" + exports.getCodePoint(str, i).toString(16) + ";";
47
50
  // Increase by 1 if we have a surrogate pair
48
- lastIdx = regExp.lastIndex += Number((char & 0xd800) === 0xd800);
51
+ lastIdx = regExp.lastIndex += Number(isHighSurrugate(char));
49
52
  }
50
53
  }
51
54
  return ret + str.substr(lastIdx);
package/lib/encode.js CHANGED
@@ -36,7 +36,7 @@ function encodeXML(str) {
36
36
  else {
37
37
  ret += str.substring(lastIdx, i) + "&#x" + encode_trie_1.getCodePoint(str, i).toString(16) + ";";
38
38
  // Increase by 1 if we have a surrogate pair
39
- lastIdx = xmlReplacer.lastIndex += Number((char & 0xd800) === 0xd800);
39
+ lastIdx = xmlReplacer.lastIndex += Number((char & 65408) === 0xd800);
40
40
  }
41
41
  }
42
42
  return ret + str.substr(lastIdx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "entities",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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",