entities 4.1.1 → 4.3.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.
Files changed (61) hide show
  1. package/lib/decode.d.ts +19 -0
  2. package/lib/decode.d.ts.map +1 -1
  3. package/lib/decode.js +42 -9
  4. package/lib/decode.js.map +1 -1
  5. package/lib/decode_codepoint.d.ts +1 -0
  6. package/lib/decode_codepoint.d.ts.map +1 -1
  7. package/lib/decode_codepoint.js +14 -14
  8. package/lib/decode_codepoint.js.map +1 -1
  9. package/lib/encode.d.ts +11 -49
  10. package/lib/encode.d.ts.map +1 -1
  11. package/lib/encode.js +56 -104
  12. package/lib/encode.js.map +1 -1
  13. package/lib/escape.d.ts +43 -0
  14. package/lib/escape.d.ts.map +1 -0
  15. package/lib/escape.js +112 -0
  16. package/lib/escape.js.map +1 -0
  17. package/lib/esm/decode.d.ts +19 -0
  18. package/lib/esm/decode.d.ts.map +1 -1
  19. package/lib/esm/decode.js +39 -8
  20. package/lib/esm/decode.js.map +1 -1
  21. package/lib/esm/decode_codepoint.d.ts +1 -0
  22. package/lib/esm/decode_codepoint.d.ts.map +1 -1
  23. package/lib/esm/decode_codepoint.js +12 -12
  24. package/lib/esm/decode_codepoint.js.map +1 -1
  25. package/lib/esm/encode.d.ts +11 -49
  26. package/lib/esm/encode.d.ts.map +1 -1
  27. package/lib/esm/encode.js +50 -100
  28. package/lib/esm/encode.js.map +1 -1
  29. package/lib/esm/escape.d.ts +43 -0
  30. package/lib/esm/escape.d.ts.map +1 -0
  31. package/lib/esm/escape.js +106 -0
  32. package/lib/esm/escape.js.map +1 -0
  33. package/lib/esm/generated/decode-data-html.d.ts.map +1 -1
  34. package/lib/esm/generated/decode-data-html.js.map +1 -1
  35. package/lib/esm/generated/decode-data-xml.d.ts.map +1 -1
  36. package/lib/esm/generated/decode-data-xml.js.map +1 -1
  37. package/lib/esm/generated/encode-html.d.ts.map +1 -1
  38. package/lib/esm/generated/encode-html.js.map +1 -1
  39. package/lib/esm/index.d.ts +3 -2
  40. package/lib/esm/index.d.ts.map +1 -1
  41. package/lib/esm/index.js +5 -3
  42. package/lib/esm/index.js.map +1 -1
  43. package/lib/generated/decode-data-html.d.ts.map +1 -1
  44. package/lib/generated/decode-data-html.js.map +1 -1
  45. package/lib/generated/decode-data-xml.d.ts.map +1 -1
  46. package/lib/generated/decode-data-xml.js.map +1 -1
  47. package/lib/generated/encode-html.d.ts.map +1 -1
  48. package/lib/generated/encode-html.js.map +1 -1
  49. package/lib/index.d.ts +3 -2
  50. package/lib/index.d.ts.map +1 -1
  51. package/lib/index.js +13 -11
  52. package/lib/index.js.map +1 -1
  53. package/package.json +17 -14
  54. package/lib/encode-trie.d.ts +0 -3
  55. package/lib/encode-trie.d.ts.map +0 -1
  56. package/lib/encode-trie.js +0 -64
  57. package/lib/encode-trie.js.map +0 -1
  58. package/lib/esm/encode-trie.d.ts +0 -3
  59. package/lib/esm/encode-trie.d.ts.map +0 -1
  60. package/lib/esm/encode-trie.js +0 -55
  61. package/lib/esm/encode-trie.js.map +0 -1
@@ -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/b535ea9a1a9aec373141f168b5a7d55b66d6fac0/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"}
@@ -0,0 +1,106 @@
1
+ export const xmlReplacer = /["&'<>$\x80-\uFFFF]/g;
2
+ const xmlCodeMap = new Map([
3
+ [34, "&quot;"],
4
+ [38, "&amp;"],
5
+ [39, "&apos;"],
6
+ [60, "&lt;"],
7
+ [62, "&gt;"],
8
+ ]);
9
+ // For compatibility with node < 4, we wrap `codePointAt`
10
+ export const getCodePoint =
11
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
+ String.prototype.codePointAt != null
13
+ ? (str, index) => str.codePointAt(index)
14
+ : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
15
+ (c, index) => (c.charCodeAt(index) & 0xfc00) === 0xd800
16
+ ? (c.charCodeAt(index) - 0xd800) * 0x400 +
17
+ c.charCodeAt(index + 1) -
18
+ 0xdc00 +
19
+ 0x10000
20
+ : c.charCodeAt(index);
21
+ /**
22
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
23
+ * documents using XML entities.
24
+ *
25
+ * If a character has no equivalent entity, a
26
+ * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
27
+ */
28
+ export function encodeXML(str) {
29
+ let ret = "";
30
+ let lastIdx = 0;
31
+ let match;
32
+ while ((match = xmlReplacer.exec(str)) !== null) {
33
+ const i = match.index;
34
+ const char = str.charCodeAt(i);
35
+ const next = xmlCodeMap.get(char);
36
+ if (next !== undefined) {
37
+ ret += str.substring(lastIdx, i) + next;
38
+ lastIdx = i + 1;
39
+ }
40
+ else {
41
+ ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`;
42
+ // Increase by 1 if we have a surrogate pair
43
+ lastIdx = xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800);
44
+ }
45
+ }
46
+ return ret + str.substr(lastIdx);
47
+ }
48
+ /**
49
+ * Encodes all non-ASCII characters, as well as characters not valid in XML
50
+ * documents using numeric hexadecimal reference (eg. `&#xfc;`).
51
+ *
52
+ * Have a look at `escapeUTF8` if you want a more concise output at the expense
53
+ * of reduced transportability.
54
+ *
55
+ * @param data String to escape.
56
+ */
57
+ export const escape = encodeXML;
58
+ function getEscaper(regex, map) {
59
+ return function escape(data) {
60
+ let match;
61
+ let lastIdx = 0;
62
+ let result = "";
63
+ while ((match = regex.exec(data))) {
64
+ if (lastIdx !== match.index) {
65
+ result += data.substring(lastIdx, match.index);
66
+ }
67
+ // We know that this chararcter will be in the map.
68
+ result += map.get(match[0].charCodeAt(0));
69
+ // Every match will be of length 1
70
+ lastIdx = match.index + 1;
71
+ }
72
+ return result + data.substring(lastIdx);
73
+ };
74
+ }
75
+ /**
76
+ * Encodes all characters not valid in XML documents using XML entities.
77
+ *
78
+ * Note that the output will be character-set dependent.
79
+ *
80
+ * @param data String to escape.
81
+ */
82
+ export const escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap);
83
+ /**
84
+ * Encodes all characters that have to be escaped in HTML attributes,
85
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
86
+ *
87
+ * @param data String to escape.
88
+ */
89
+ export const escapeAttribute = getEscaper(/["&\u00A0]/g, new Map([
90
+ [34, "&quot;"],
91
+ [38, "&amp;"],
92
+ [160, "&nbsp;"],
93
+ ]));
94
+ /**
95
+ * Encodes all characters that have to be escaped in HTML text,
96
+ * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
97
+ *
98
+ * @param data String to escape.
99
+ */
100
+ export const escapeText = getEscaper(/[&<>\u00A0]/g, new Map([
101
+ [38, "&amp;"],
102
+ [60, "&lt;"],
103
+ [62, "&gt;"],
104
+ [160, "&nbsp;"],
105
+ ]));
106
+ //# sourceMappingURL=escape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.js","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/b535ea9a1a9aec373141f168b5a7d55b66d6fac0/src/","sources":["escape.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAElD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACvB,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,QAAQ,CAAC;IACd,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAEH,yDAAyD;AACzD,MAAM,CAAC,MAAM,YAAY;AACrB,uEAAuE;AACvE,MAAM,CAA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,EAAE,OAAO,CAAC;IACb,CAAC,GAAG,EAAE,QAAQ,CAAC;CAClB,CAAC,CACL,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAChC,cAAc,EACd,IAAI,GAAG,CAAC;IACJ,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,QAAQ,CAAC;CAClB,CAAC,CACL,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"decode-data-html.d.ts","sourceRoot":"","sources":["../../../src/generated/decode-data-html.ts"],"names":[],"mappings":";AAEA,wBAAivgE"}
1
+ {"version":3,"file":"decode-data-html.d.ts","sourceRoot":"https://raw.githubusercontent.com/fb55/entities/b535ea9a1a9aec373141f168b5a7d55b66d6fac0/src/","sources":["generated/decode-data-html.ts"],"names":[],"mappings":";AAEA,wBAAivgE"}