@rgrove/parse-xml 2.0.4 → 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.
Files changed (73) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +84 -337
  3. package/dist/browser.js +774 -0
  4. package/dist/browser.js.map +7 -0
  5. package/dist/global.min.js +10 -0
  6. package/dist/global.min.js.map +7 -0
  7. package/dist/index.d.ts +24 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +50 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/lib/Parser.d.ts +218 -0
  12. package/dist/lib/Parser.d.ts.map +1 -0
  13. package/dist/lib/Parser.js +638 -0
  14. package/dist/lib/Parser.js.map +1 -0
  15. package/dist/lib/StringScanner.d.ts +97 -0
  16. package/dist/lib/StringScanner.d.ts.map +1 -0
  17. package/dist/lib/StringScanner.js +210 -0
  18. package/dist/lib/StringScanner.js.map +1 -0
  19. package/dist/lib/XmlCdata.d.ts +8 -0
  20. package/dist/lib/XmlCdata.d.ts.map +1 -0
  21. package/dist/lib/XmlCdata.js +15 -0
  22. package/dist/lib/XmlCdata.js.map +1 -0
  23. package/dist/lib/XmlComment.d.ts +16 -0
  24. package/dist/lib/XmlComment.d.ts.map +1 -0
  25. package/dist/lib/XmlComment.js +23 -0
  26. package/dist/lib/XmlComment.js.map +1 -0
  27. package/dist/lib/XmlDocument.d.ts +29 -0
  28. package/dist/lib/XmlDocument.d.ts.map +1 -0
  29. package/dist/lib/XmlDocument.js +47 -0
  30. package/dist/lib/XmlDocument.js.map +1 -0
  31. package/dist/lib/XmlElement.d.ts +40 -0
  32. package/dist/lib/XmlElement.d.ts.map +1 -0
  33. package/dist/lib/XmlElement.js +51 -0
  34. package/dist/lib/XmlElement.js.map +1 -0
  35. package/dist/lib/XmlNode.d.ts +74 -0
  36. package/dist/lib/XmlNode.d.ts.map +1 -0
  37. package/dist/lib/XmlNode.js +96 -0
  38. package/dist/lib/XmlNode.js.map +1 -0
  39. package/dist/lib/XmlProcessingInstruction.d.ts +22 -0
  40. package/dist/lib/XmlProcessingInstruction.d.ts.map +1 -0
  41. package/dist/lib/XmlProcessingInstruction.js +25 -0
  42. package/dist/lib/XmlProcessingInstruction.js.map +1 -0
  43. package/dist/lib/XmlText.d.ts +16 -0
  44. package/dist/lib/XmlText.d.ts.map +1 -0
  45. package/dist/lib/XmlText.js +23 -0
  46. package/dist/lib/XmlText.js.map +1 -0
  47. package/dist/lib/syntax.d.ts +69 -0
  48. package/dist/lib/syntax.d.ts.map +1 -0
  49. package/dist/lib/syntax.js +133 -0
  50. package/dist/lib/syntax.js.map +1 -0
  51. package/dist/lib/types.d.ts +5 -0
  52. package/dist/lib/types.d.ts.map +1 -0
  53. package/dist/lib/types.js +3 -0
  54. package/dist/lib/types.js.map +1 -0
  55. package/package.json +36 -22
  56. package/src/index.ts +30 -0
  57. package/src/lib/Parser.ts +819 -0
  58. package/src/lib/StringScanner.ts +254 -0
  59. package/src/lib/XmlCdata.ts +11 -0
  60. package/src/lib/XmlComment.ts +26 -0
  61. package/src/lib/XmlDocument.ts +57 -0
  62. package/src/lib/XmlElement.ts +81 -0
  63. package/src/lib/XmlNode.ts +107 -0
  64. package/src/lib/XmlProcessingInstruction.ts +35 -0
  65. package/src/lib/XmlText.ts +26 -0
  66. package/src/lib/syntax.ts +136 -0
  67. package/src/lib/types.ts +2 -0
  68. package/CHANGELOG.md +0 -89
  69. package/dist/commonjs/index.js +0 -434
  70. package/dist/commonjs/lib/syntax.js +0 -262
  71. package/dist/umd/parse-xml.min.js +0 -1
  72. package/src/index.js +0 -451
  73. package/src/lib/syntax.js +0 -263
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlNode.d.ts","sourceRoot":"","sources":["../../src/lib/XmlNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,qBAAa,OAAO;IAClB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,WAAW;IAErC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,YAAY,aAAa;IAEzC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,cAAc;IAE3C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,YAAY,aAAa;IAEzC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,2BAA2B,QAAQ;IAEnD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,UAAU;IAEnC;;OAEG;IACH,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,CAAQ;IAE/C;;;OAGG;IACH,IAAI,QAAQ,IAAI,WAAW,GAAG,IAAI,CAEjC;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;;;;;;;;;OAUG;IACH,IAAI,kBAAkB,IAAI,OAAO,CAEhC;IAED;;;;;;;;;OASG;IACH,IAAI,IAAI,WAEP;IAED;;;OAGG;IACH,MAAM,IAAI,UAAU;CAerB"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XmlNode = void 0;
4
+ /**
5
+ * Base interface for a node in an XML document.
6
+ */
7
+ class XmlNode {
8
+ constructor() {
9
+ /**
10
+ * Parent node of this node, or `null` if this node has no parent.
11
+ */
12
+ this.parent = null;
13
+ }
14
+ /**
15
+ * Document that contains this node, or `null` if this node is not associated
16
+ * with a document.
17
+ */
18
+ get document() {
19
+ return this.parent?.document ?? null;
20
+ }
21
+ /**
22
+ * Whether this node is the root node of the document.
23
+ */
24
+ get isRootNode() {
25
+ return this.parent !== null && this.parent === this.document;
26
+ }
27
+ /**
28
+ * Whether whitespace should be preserved in the content of this element and
29
+ * its children.
30
+ *
31
+ * This is influenced by the value of the special `xml:space` attribute, and
32
+ * will be `true` for any node whose `xml:space` attribute is set to
33
+ * "preserve". If a node has no such attribute, it will inherit the value of
34
+ * the nearest ancestor that does (if any).
35
+ *
36
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space
37
+ */
38
+ get preserveWhitespace() {
39
+ return Boolean(this.parent?.preserveWhitespace);
40
+ }
41
+ /**
42
+ * Type of this node.
43
+ *
44
+ * The value of this property is a string that matches one of the static
45
+ * `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,
46
+ * `TYPE_TEXT`, etc.).
47
+ *
48
+ * The `XmlNode` class itself is a base class and doesn't have its own type
49
+ * name.
50
+ */
51
+ get type() {
52
+ return '';
53
+ }
54
+ /**
55
+ * Returns a JSON-serializable object representing this node, minus properties
56
+ * that could result in circular references.
57
+ */
58
+ toJSON() {
59
+ let json = {
60
+ type: this.type,
61
+ };
62
+ if (this.isRootNode) {
63
+ json.isRootNode = true;
64
+ }
65
+ if (this.preserveWhitespace) {
66
+ json.preserveWhitespace = true;
67
+ }
68
+ return json;
69
+ }
70
+ }
71
+ exports.XmlNode = XmlNode;
72
+ /**
73
+ * Type value for an `XmlCdata` node.
74
+ */
75
+ XmlNode.TYPE_CDATA = 'cdata';
76
+ /**
77
+ * Type value for an `XmlComment` node.
78
+ */
79
+ XmlNode.TYPE_COMMENT = 'comment';
80
+ /**
81
+ * Type value for an `XmlDocument` node.
82
+ */
83
+ XmlNode.TYPE_DOCUMENT = 'document';
84
+ /**
85
+ * Type value for an `XmlElement` node.
86
+ */
87
+ XmlNode.TYPE_ELEMENT = 'element';
88
+ /**
89
+ * Type value for an `XmlProcessingInstruction` node.
90
+ */
91
+ XmlNode.TYPE_PROCESSING_INSTRUCTION = 'pi';
92
+ /**
93
+ * Type value for an `XmlText` node.
94
+ */
95
+ XmlNode.TYPE_TEXT = 'text';
96
+ //# sourceMappingURL=XmlNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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2
+ /**
3
+ * A processing instruction within an XML document.
4
+ */
5
+ export declare class XmlProcessingInstruction extends XmlNode {
6
+ /**
7
+ * Content of this processing instruction.
8
+ */
9
+ content: string;
10
+ /**
11
+ * Name of this processing instruction. Also sometimes referred to as the
12
+ * processing instruction "target".
13
+ */
14
+ name: string;
15
+ constructor(name: string, content?: string);
16
+ get type(): string;
17
+ toJSON(): import("./types.js").JsonObject & {
18
+ name: string;
19
+ content: string;
20
+ };
21
+ }
22
+ //# sourceMappingURL=XmlProcessingInstruction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlProcessingInstruction.d.ts","sourceRoot":"","sources":["../../src/lib/XmlProcessingInstruction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,OAAO;IACnD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE,MAAM,EAAE,OAAO,SAAK;IAOtC,IAAa,IAAI,WAEhB;IAEQ,MAAM;;;;CAMhB"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XmlProcessingInstruction = void 0;
4
+ const XmlNode_js_1 = require("./XmlNode.js");
5
+ /**
6
+ * A processing instruction within an XML document.
7
+ */
8
+ class XmlProcessingInstruction extends XmlNode_js_1.XmlNode {
9
+ constructor(name, content = '') {
10
+ super();
11
+ this.name = name;
12
+ this.content = content;
13
+ }
14
+ get type() {
15
+ return XmlNode_js_1.XmlNode.TYPE_PROCESSING_INSTRUCTION;
16
+ }
17
+ toJSON() {
18
+ return Object.assign(XmlNode_js_1.XmlNode.prototype.toJSON.call(this), {
19
+ name: this.name,
20
+ content: this.content,
21
+ });
22
+ }
23
+ }
24
+ exports.XmlProcessingInstruction = XmlProcessingInstruction;
25
+ //# sourceMappingURL=XmlProcessingInstruction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlProcessingInstruction.js","sourceRoot":"","sources":["../../src/lib/XmlProcessingInstruction.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AAEvC;;GAEG;AACH,MAAa,wBAAyB,SAAQ,oBAAO;IAYnD,YAAY,IAAY,EAAE,OAAO,GAAG,EAAE;QACpC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAa,IAAI;QACf,OAAO,oBAAO,CAAC,2BAA2B,CAAC;IAC7C,CAAC;IAEQ,MAAM;QACb,OAAO,MAAM,CAAC,MAAM,CAAC,oBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACxD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;CACF;AA7BD,4DA6BC"}
@@ -0,0 +1,16 @@
1
+ import { XmlNode } from './XmlNode.js';
2
+ /**
3
+ * Text content within an XML document.
4
+ */
5
+ export declare class XmlText extends XmlNode {
6
+ /**
7
+ * Text content of this node.
8
+ */
9
+ text: string;
10
+ constructor(text?: string);
11
+ get type(): string;
12
+ toJSON(): import("./types.js").JsonObject & {
13
+ text: string;
14
+ };
15
+ }
16
+ //# sourceMappingURL=XmlText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlText.d.ts","sourceRoot":"","sources":["../../src/lib/XmlText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,qBAAa,OAAQ,SAAQ,OAAO;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,SAAK;IAKrB,IAAa,IAAI,WAEhB;IAEQ,MAAM;;;CAKhB"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XmlText = void 0;
4
+ const XmlNode_js_1 = require("./XmlNode.js");
5
+ /**
6
+ * Text content within an XML document.
7
+ */
8
+ class XmlText extends XmlNode_js_1.XmlNode {
9
+ constructor(text = '') {
10
+ super();
11
+ this.text = text;
12
+ }
13
+ get type() {
14
+ return XmlNode_js_1.XmlNode.TYPE_TEXT;
15
+ }
16
+ toJSON() {
17
+ return Object.assign(XmlNode_js_1.XmlNode.prototype.toJSON.call(this), {
18
+ text: this.text,
19
+ });
20
+ }
21
+ }
22
+ exports.XmlText = XmlText;
23
+ //# sourceMappingURL=XmlText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XmlText.js","sourceRoot":"","sources":["../../src/lib/XmlText.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AAEvC;;GAEG;AACH,MAAa,OAAQ,SAAQ,oBAAO;IAMlC,YAAY,IAAI,GAAG,EAAE;QACnB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAa,IAAI;QACf,OAAO,oBAAO,CAAC,SAAS,CAAC;IAC3B,CAAC;IAEQ,MAAM;QACb,OAAO,MAAM,CAAC,MAAM,CAAC,oBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACxD,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;CACF;AApBD,0BAoBC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Regular expression that matches one or more `AttValue` characters in a
3
+ * double-quoted attribute value.
4
+ *
5
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
6
+ */
7
+ export declare const attValueCharDoubleQuote: RegExp;
8
+ /**
9
+ * Regular expression that matches one or more `AttValue` characters in a
10
+ * single-quoted attribute value.
11
+ *
12
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
13
+ */
14
+ export declare const attValueCharSingleQuote: RegExp;
15
+ /**
16
+ * Regular expression that matches a whitespace character that should be
17
+ * normalized to a space character in an attribute value.
18
+ *
19
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize
20
+ */
21
+ export declare const attValueNormalizedWhitespace: RegExp;
22
+ /**
23
+ * Regular expression that matches one or more characters that signal the end of
24
+ * XML `CharData` content.
25
+ *
26
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata
27
+ */
28
+ export declare const endCharData: RegExp;
29
+ /**
30
+ * Mapping of predefined entity names to their replacement values.
31
+ *
32
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent
33
+ */
34
+ export declare const predefinedEntities: Readonly<{
35
+ [name: string]: string;
36
+ }>;
37
+ /**
38
+ * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.
39
+ *
40
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar
41
+ */
42
+ export declare function isNameChar(char: string): boolean;
43
+ /**
44
+ * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.
45
+ *
46
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar
47
+ */
48
+ export declare function isNameStartChar(char: string, cp?: number): boolean;
49
+ /**
50
+ * Returns `true` if _char_ is a valid reference character (which may appear
51
+ * between `&` and `;` in a reference), `false` otherwise.
52
+ *
53
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references
54
+ */
55
+ export declare function isReferenceChar(char: string): boolean;
56
+ /**
57
+ * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.
58
+ *
59
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
60
+ */
61
+ export declare function isWhitespace(char: string): boolean;
62
+ /**
63
+ * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`
64
+ * otherwise.
65
+ *
66
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char
67
+ */
68
+ export declare function isXmlCodePoint(cp: number): boolean;
69
+ //# sourceMappingURL=syntax.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../../src/lib/syntax.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAa,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAa,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAY,CAAC;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAY,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC;IAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAAC,CAMhE,CAAC;AAEJ;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAchD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAqB,GAAG,OAAO,CAiB9E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOlD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAOlD"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isXmlCodePoint = exports.isWhitespace = exports.isReferenceChar = exports.isNameStartChar = exports.isNameChar = exports.predefinedEntities = exports.endCharData = exports.attValueNormalizedWhitespace = exports.attValueCharSingleQuote = exports.attValueCharDoubleQuote = void 0;
4
+ /**
5
+ * Regular expression that matches one or more `AttValue` characters in a
6
+ * double-quoted attribute value.
7
+ *
8
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
9
+ */
10
+ exports.attValueCharDoubleQuote = /[^"&<]+/y;
11
+ /**
12
+ * Regular expression that matches one or more `AttValue` characters in a
13
+ * single-quoted attribute value.
14
+ *
15
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
16
+ */
17
+ exports.attValueCharSingleQuote = /[^'&<]+/y;
18
+ /**
19
+ * Regular expression that matches a whitespace character that should be
20
+ * normalized to a space character in an attribute value.
21
+ *
22
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize
23
+ */
24
+ exports.attValueNormalizedWhitespace = /[\t\n]/g;
25
+ /**
26
+ * Regular expression that matches one or more characters that signal the end of
27
+ * XML `CharData` content.
28
+ *
29
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata
30
+ */
31
+ exports.endCharData = /<|&|]]>/;
32
+ /**
33
+ * Mapping of predefined entity names to their replacement values.
34
+ *
35
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent
36
+ */
37
+ exports.predefinedEntities = Object.freeze(Object.assign(Object.create(null), {
38
+ amp: '&',
39
+ apos: "'",
40
+ gt: '>',
41
+ lt: '<',
42
+ quot: '"',
43
+ }));
44
+ /**
45
+ * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.
46
+ *
47
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar
48
+ */
49
+ function isNameChar(char) {
50
+ let cp = getCodePoint(char);
51
+ // Including the most common NameStartChars here improves performance
52
+ // slightly.
53
+ return (cp >= 0x61 && cp <= 0x7A) // a-z
54
+ || (cp >= 0x41 && cp <= 0x5A) // A-Z
55
+ || (cp >= 0x30 && cp <= 0x39) // 0-9
56
+ || cp === 0x2D // -
57
+ || cp === 0x2E // .
58
+ || cp === 0xB7
59
+ || (cp >= 0x300 && cp <= 0x36F)
60
+ || (cp >= 0x203F && cp <= 0x2040)
61
+ || isNameStartChar(char, cp);
62
+ }
63
+ exports.isNameChar = isNameChar;
64
+ /**
65
+ * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.
66
+ *
67
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar
68
+ */
69
+ function isNameStartChar(char, cp = getCodePoint(char)) {
70
+ return (cp >= 0x61 && cp <= 0x7A) // a-z
71
+ || (cp >= 0x41 && cp <= 0x5A) // A-Z
72
+ || cp === 0x3A // :
73
+ || cp === 0x5F // _
74
+ || (cp >= 0xC0 && cp <= 0xD6)
75
+ || (cp >= 0xD8 && cp <= 0xF6)
76
+ || (cp >= 0xF8 && cp <= 0x2FF)
77
+ || (cp >= 0x370 && cp <= 0x37D)
78
+ || (cp >= 0x37F && cp <= 0x1FFF)
79
+ || (cp >= 0x200C && cp <= 0x200D)
80
+ || (cp >= 0x2070 && cp <= 0x218F)
81
+ || (cp >= 0x2C00 && cp <= 0x2FEF)
82
+ || (cp >= 0x3001 && cp <= 0xD7FF)
83
+ || (cp >= 0xF900 && cp <= 0xFDCF)
84
+ || (cp >= 0xFDF0 && cp <= 0xFFFD)
85
+ || (cp >= 0x10000 && cp <= 0xEFFFF);
86
+ }
87
+ exports.isNameStartChar = isNameStartChar;
88
+ /**
89
+ * Returns `true` if _char_ is a valid reference character (which may appear
90
+ * between `&` and `;` in a reference), `false` otherwise.
91
+ *
92
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references
93
+ */
94
+ function isReferenceChar(char) {
95
+ return char === '#' || isNameChar(char);
96
+ }
97
+ exports.isReferenceChar = isReferenceChar;
98
+ /**
99
+ * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.
100
+ *
101
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
102
+ */
103
+ function isWhitespace(char) {
104
+ let cp = getCodePoint(char);
105
+ return cp === 0x20
106
+ || cp === 0x9
107
+ || cp === 0xA
108
+ || cp === 0xD;
109
+ }
110
+ exports.isWhitespace = isWhitespace;
111
+ /**
112
+ * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`
113
+ * otherwise.
114
+ *
115
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char
116
+ */
117
+ function isXmlCodePoint(cp) {
118
+ return cp === 0x9
119
+ || cp === 0xA
120
+ || cp === 0xD
121
+ || (cp >= 0x20 && cp <= 0xD7FF)
122
+ || (cp >= 0xE000 && cp <= 0xFFFD)
123
+ || (cp >= 0x10000 && cp <= 0x10FFFF);
124
+ }
125
+ exports.isXmlCodePoint = isXmlCodePoint;
126
+ /**
127
+ * Returns the Unicode code point value of the given character, or `-1` if
128
+ * _char_ is empty.
129
+ */
130
+ function getCodePoint(char) {
131
+ return char.codePointAt(0) || -1;
132
+ }
133
+ //# sourceMappingURL=syntax.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax.js","sourceRoot":"","sources":["../../src/lib/syntax.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACU,QAAA,uBAAuB,GAAG,UAAU,CAAC;AAElD;;;;;GAKG;AACU,QAAA,uBAAuB,GAAG,UAAU,CAAC;AAElD;;;;;GAKG;AACU,QAAA,4BAA4B,GAAG,SAAS,CAAC;AAEtD;;;;;GAKG;AACU,QAAA,WAAW,GAAG,SAAS,CAAC;AAErC;;;;GAIG;AACU,QAAA,kBAAkB,GAAwC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;IACtH,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,GAAG;IACT,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,GAAG;IACP,IAAI,EAAE,GAAG;CACV,CAAC,CAAC,CAAC;AAEJ;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,IAAI,EAAE,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAE5B,qEAAqE;IACrE,YAAY;IACZ,OAAO,CAAC,EAAE,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI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onObject | JsonValue[] | null;
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG;KAAE,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,SAAS;CAAC,CAAC;AACvD,oBAAY,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,EAAE,GAAG,IAAI,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@rgrove/parse-xml",
3
- "version": "2.0.4",
3
+ "version": "4.0.0",
4
4
  "description": "A fast, safe, compliant XML parser for Node.js and browsers.",
5
5
  "keywords": [
6
6
  "xml",
7
+ "xml parser",
8
+ "parse-xml",
9
+ "parse xml",
7
10
  "parse",
8
11
  "parser"
9
12
  ],
@@ -16,37 +19,48 @@
16
19
  "url": "https://github.com/rgrove/parse-xml.git"
17
20
  },
18
21
  "engines": {
19
- "node": ">=6.0.0"
22
+ "node": ">=14.0.0"
20
23
  },
21
24
  "files": [
22
25
  "dist",
26
+ "!dist/tsconfig.tsbuildinfo",
23
27
  "src",
24
28
  "LICENSE"
25
29
  ],
26
- "browser": "dist/commonjs/index.js",
27
- "main": "src/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "main": "./dist/index.js",
32
+ "browser": "./dist/browser.js",
28
33
  "scripts": {
29
- "build": "babel src -d dist/commonjs && webpack",
34
+ "build": "npm run build:js && npm run build:bundle && npm run build:docs",
35
+ "build:bundle": "./scripts/esbuild.js",
36
+ "build:docs": "typedoc src/index.ts",
37
+ "build:js": "tsc",
30
38
  "clean": "rm -rf .nyc_output coverage dist",
31
39
  "coverage": "nyc --reporter html --report-dir coverage npm test && open coverage/index.html",
32
- "lint": "eslint --cache {src,tests}",
40
+ "lint": "npm run lint:js && npm run lint:ts",
41
+ "lint:js": "eslint .",
42
+ "lint:ts": "tsc --noEmit",
33
43
  "prepublishOnly": "npm run clean && npm run build",
34
- "test": "nyc --check-coverage --lines 100 mocha tests/*.test.js --delay --reporter dot",
35
- "test:browser": "(sleep 5 && open 'http://localhost:8080/tests/browser/') & webpack-dev-server --config tests/webpack.config.js --watch"
44
+ "test": "npm run build:js && nyc --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 mocha",
45
+ "test:watch": "npm run build:js && concurrently --kill-others-on-fail --names build,mocha 'npm run build:js -- --watch' 'mocha --watch'",
46
+ "test:browser": "npm run build:js && npm run build:bundle && concurrently --kill-others-on-fail --names build:bundle,build:js,webpack 'npm run build:bundle -- --watch' 'npm run build:js -- --watch' 'webpack serve --config tests/webpack.config.js'"
36
47
  },
37
48
  "devDependencies": {
38
- "@babel/cli": "^7.8.4",
39
- "@babel/core": "^7.9.6",
40
- "@babel/preset-env": "^7.9.6",
41
- "@rgrove/eslint-config": "^1.5.0",
42
- "async": "^3.2.0",
43
- "babel-loader": "^8.1.0",
44
- "eslint": "^6.8.0",
45
- "mocha": "^7.1.2",
46
- "nyc": "^15.0.1",
47
- "webpack": "^4.43.0",
48
- "webpack-cli": "^3.3.11",
49
- "webpack-dev-server": "^3.10.3"
50
- },
51
- "dependencies": {}
49
+ "@rgrove/eslint-config": "^5.0.0",
50
+ "@types/node": "^18.7.21",
51
+ "assert": "^2.0.0",
52
+ "async": "^3.2.2",
53
+ "concurrently": "^7.4.0",
54
+ "esbuild": "^0.15.9",
55
+ "eslint": "^8.24.0",
56
+ "mocha": "^10.0.0",
57
+ "nyc": "^15.1.0",
58
+ "path-browserify": "^1.0.1",
59
+ "process": "^0.11.10",
60
+ "typedoc": "^0.23.15",
61
+ "typescript": "4.8.3",
62
+ "webpack": "^5.65.0",
63
+ "webpack-cli": "^4.9.1",
64
+ "webpack-dev-server": "^4.11.1"
65
+ }
52
66
  }
package/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { Parser } from './lib/Parser.js';
2
+
3
+ import type { ParserOptions } from './lib/Parser.js';
4
+
5
+ export * from './lib/types.js';
6
+ export { XmlCdata } from './lib/XmlCdata.js';
7
+ export { XmlComment } from './lib/XmlComment.js';
8
+ export { XmlDocument } from './lib/XmlDocument.js';
9
+ export { XmlElement } from './lib/XmlElement.js';
10
+ export { XmlNode } from './lib/XmlNode.js';
11
+ export { XmlProcessingInstruction } from './lib/XmlProcessingInstruction.js';
12
+ export { XmlText } from './lib/XmlText.js';
13
+
14
+ export type { ParserOptions } from './lib/Parser.js';
15
+
16
+ /**
17
+ * Parses the given XML string and returns an `XmlDocument` instance
18
+ * representing the document tree.
19
+ *
20
+ * @example
21
+ *
22
+ * import { parseXml } from '@rgrove/parse-xml';
23
+ * let doc = parseXml('<kittens fuzzy="yes">I like fuzzy kittens.</kittens>');
24
+ *
25
+ * @param xml XML string to parse.
26
+ * @param options Parser options.
27
+ */
28
+ export function parseXml(xml: string, options: ParserOptions) {
29
+ return (new Parser(xml, options)).document;
30
+ }