speedy-entities 3.1.0 → 4.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.
package/escapeXML.d.ts CHANGED
@@ -1 +1,5 @@
1
+ /**
2
+ * Replaces `"&'<>` with XML entities and keeps other chars, so the output needs a Unicode encoding. Use
3
+ * {@linkcode encodeXML} for ASCII output.
4
+ */
1
5
  export declare function escapeXML(input: string): string;
package/escapeXML.js CHANGED
@@ -1,28 +1,37 @@
1
- const re = /["&'<>]/g;
1
+ const escapedCharRegExp = /["&'<>]/g;
2
+ /**
3
+ * Replaces `"&'<>` with XML entities and keeps other chars, so the output needs a Unicode encoding. Use
4
+ * {@linkcode encodeXML} for ASCII output.
5
+ */
2
6
  export function escapeXML(input) {
3
7
  let output = '';
4
8
  let textIndex = 0;
5
- while (re.test(input)) {
6
- const lastIndex = re.lastIndex;
9
+ // A call that threw midway doesn't reset lastIndex, and the search would skip the start of the input
10
+ escapedCharRegExp.lastIndex = 0;
11
+ while (escapedCharRegExp.test(input)) {
12
+ const lastIndex = escapedCharRegExp.lastIndex;
7
13
  const startIndex = lastIndex - 1;
8
14
  const charCode = input.charCodeAt(startIndex);
9
15
  let entity;
10
- if (charCode === 34) {
16
+ if (charCode === /* " */ 34) {
11
17
  entity = '&quot;';
12
18
  }
13
- else if (charCode === 38) {
19
+ else if (charCode === /* & */ 38) {
14
20
  entity = '&amp;';
15
21
  }
16
- else if (charCode === 39) {
22
+ else if (charCode === /* ' */ 39) {
17
23
  entity = '&apos;';
18
24
  }
19
- else if (charCode === 60) {
25
+ else if (charCode === /* < */ 60) {
20
26
  entity = '&lt;';
21
27
  }
22
28
  else {
23
29
  entity = '&gt;';
24
30
  }
25
- output += textIndex === startIndex ? entity : input.slice(textIndex, startIndex) + entity;
31
+ if (textIndex !== startIndex) {
32
+ output += input.slice(textIndex, startIndex);
33
+ }
34
+ output += entity;
26
35
  textIndex = lastIndex;
27
36
  }
28
37
  return textIndex === 0 ? input : textIndex === input.length ? output : output + input.slice(textIndex);
package/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- export { createEntityDecoder, type EntityDecoderOptions } from './createEntityDecoder.js';
2
- export { decodeHTML } from './decodeHTML.js';
3
- export { decodeXML } from './decodeXML.js';
4
- export { encodeXML } from './encodeXML.js';
5
- export { escapeXML } from './escapeXML.js';
1
+ export type { EntityTrie } from './createDoubleArrayEntityTrie.ts';
2
+ export { createEntityDecoder, type EntityDecoderOptions } from './createEntityDecoder.ts';
3
+ export { createEntityTrie } from './createEntityTrie.ts';
4
+ export { createEntityTrieDecoder, type EntityTrieDecoderOptions } from './createEntityTrieDecoder.ts';
5
+ export { decodeHTML, decodeHTMLAttribute } from './decodeHTML.ts';
6
+ export { decodeXML } from './decodeXML.ts';
7
+ export { encodeXML } from './encodeXML.ts';
8
+ export { escapeXML } from './escapeXML.ts';
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
- export { createEntityDecoder } from './createEntityDecoder.js';
2
- export { decodeHTML } from './decodeHTML.js';
3
- export { decodeXML } from './decodeXML.js';
4
- export { encodeXML } from './encodeXML.js';
5
- export { escapeXML } from './escapeXML.js';
1
+ export { createEntityDecoder } from "./createEntityDecoder.js";
2
+ export { createEntityTrie } from "./createEntityTrie.js";
3
+ export { createEntityTrieDecoder } from "./createEntityTrieDecoder.js";
4
+ export { decodeHTML, decodeHTMLAttribute } from "./decodeHTML.js";
5
+ export { decodeXML } from "./decodeXML.js";
6
+ export { encodeXML } from "./encodeXML.js";
7
+ export { escapeXML } from "./escapeXML.js";
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "speedy-entities",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "The fastest XML/HTML entities decoder.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
7
  "types": "./index.d.ts",
8
8
  "exports": {
9
9
  ".": "./index.js",
10
- "./html-entities": "./html-entities.js",
11
- "./xml-entities": "./xml-entities.js",
10
+ "./createEntityDecoder": "./createEntityDecoder.js",
11
+ "./createEntityTrie": "./createEntityTrie.js",
12
+ "./createEntityTrieDecoder": "./createEntityTrieDecoder.js",
13
+ "./decodeHTML": "./decodeHTML.js",
14
+ "./decodeHTMLAttribute": "./decodeHTML.js",
15
+ "./decodeXML": "./decodeXML.js",
16
+ "./encodeXML": "./encodeXML.js",
17
+ "./escapeXML": "./escapeXML.js",
18
+ "./entities": "./entities.js",
12
19
  "./package.json": "./package.json"
13
20
  },
14
21
  "sideEffects": false,