@rgrove/parse-xml 3.0.0 → 4.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.
Files changed (103) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +72 -97
  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 +33 -26
  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 -162
  69. package/dist/types/index.d.ts +0 -68
  70. package/dist/types/index.d.ts.map +0 -1
  71. package/dist/types/lib/Parser.d.ts +0 -234
  72. package/dist/types/lib/Parser.d.ts.map +0 -1
  73. package/dist/types/lib/StringScanner.d.ts +0 -139
  74. package/dist/types/lib/StringScanner.d.ts.map +0 -1
  75. package/dist/types/lib/XmlCdata.d.ts +0 -11
  76. package/dist/types/lib/XmlCdata.d.ts.map +0 -1
  77. package/dist/types/lib/XmlComment.d.ts +0 -21
  78. package/dist/types/lib/XmlComment.d.ts.map +0 -1
  79. package/dist/types/lib/XmlDocument.d.ts +0 -42
  80. package/dist/types/lib/XmlDocument.d.ts.map +0 -1
  81. package/dist/types/lib/XmlElement.d.ts +0 -62
  82. package/dist/types/lib/XmlElement.d.ts.map +0 -1
  83. package/dist/types/lib/XmlNode.d.ts +0 -78
  84. package/dist/types/lib/XmlNode.d.ts.map +0 -1
  85. package/dist/types/lib/XmlProcessingInstruction.d.ts +0 -30
  86. package/dist/types/lib/XmlProcessingInstruction.d.ts.map +0 -1
  87. package/dist/types/lib/XmlText.d.ts +0 -21
  88. package/dist/types/lib/XmlText.d.ts.map +0 -1
  89. package/dist/types/lib/syntax.d.ts +0 -59
  90. package/dist/types/lib/syntax.d.ts.map +0 -1
  91. package/dist/umd/parse-xml.min.js +0 -2
  92. package/dist/umd/parse-xml.min.js.map +0 -1
  93. package/src/index.js +0 -67
  94. package/src/lib/Parser.js +0 -812
  95. package/src/lib/StringScanner.js +0 -312
  96. package/src/lib/XmlCdata.js +0 -17
  97. package/src/lib/XmlComment.js +0 -37
  98. package/src/lib/XmlDocument.js +0 -69
  99. package/src/lib/XmlElement.js +0 -101
  100. package/src/lib/XmlNode.js +0 -152
  101. package/src/lib/XmlProcessingInstruction.js +0 -48
  102. package/src/lib/XmlText.js +0 -37
  103. package/src/lib/syntax.js +0 -153
@@ -1,139 +0,0 @@
1
- export = StringScanner;
2
- /**
3
- @private
4
- */
5
- declare class StringScanner {
6
- /**
7
- @param {string} string
8
- */
9
- constructor(string: string);
10
- /** @type {string[]} */
11
- chars: string[];
12
- /** @type {number} */
13
- charCount: number;
14
- /** @type {number} */
15
- charIndex: number;
16
- /** @type {number[]} */
17
- charsToBytes: number[];
18
- /** @type {boolean} */
19
- multiByteMode: boolean;
20
- /** @type {string} */
21
- string: string;
22
- /**
23
- Whether the current character index is at the end of the input string.
24
-
25
- @type {boolean}
26
- */
27
- get isEnd(): boolean;
28
- /**
29
- Returns the number of characters in the given _string_, which may differ from
30
- the byte length if the string contains multibyte characters.
31
-
32
- @param {string} string
33
- @returns {number}
34
- */
35
- _charLength(string: string): number;
36
- /**
37
- Advances the scanner by the given number of characters, stopping if the end of
38
- the string is reached.
39
-
40
- @param {number} [count]
41
- */
42
- advance(count?: number | undefined): void;
43
- /**
44
- Consumes and returns the given number of characters if possible, advancing the
45
- scanner and stopping if the end of the string is reached.
46
-
47
- If no characters could be consumed, an empty string will be returned.
48
-
49
- @param {number} [count]
50
- @returns {string}
51
- */
52
- consume(count?: number | undefined): string;
53
- /**
54
- Consumes a match for the given sticky regex, advances the scanner, updates the
55
- `lastIndex` property of the regex, and returns the matching string.
56
-
57
- The regex must have a sticky flag ("y") so that its `lastIndex` prop can be
58
- used to anchor the match at the current scanner position.
59
-
60
- Returns the consumed string, or an empty string if nothing was consumed.
61
-
62
- @param {RegExp} regex
63
- @returns {string}
64
- */
65
- consumeMatch(regex: RegExp): string;
66
- /**
67
- Consumes and returns all characters for which the given function returns a
68
- truthy value, stopping on the first falsy return value or if the end of the
69
- input is reached.
70
-
71
- @param {(char: string) => boolean} fn
72
- @returns {string}
73
- */
74
- consumeMatchFn(fn: (char: string) => boolean): string;
75
- /**
76
- Consumes the given string if it exists at the current character index, and
77
- advances the scanner.
78
-
79
- If the given string doesn't exist at the current character index, an empty
80
- string will be returned and the scanner will not be advanced.
81
-
82
- @param {string} stringToConsume
83
- @returns {string}
84
- */
85
- consumeString(stringToConsume: string): string;
86
- /**
87
- * Does the same thing as `consumeString()`, but doesn't support consuming
88
- * multibyte characters. This can be much faster if you only need to match
89
- * single byte characters.
90
- *
91
- * @param {string} stringToConsume
92
- * @returns {string}
93
- */
94
- consumeStringFast(stringToConsume: string): string;
95
- /**
96
- Consumes characters until the given global regex is matched, advancing the
97
- scanner up to (but not beyond) the beginning of the match and updating the
98
- `lastIndex` property of the regex.
99
-
100
- The regex must have a global flag ("g") so that its `lastIndex` prop can be
101
- used to begin the search at the current scanner position.
102
-
103
- Returns the consumed string, or an empty string if nothing was consumed.
104
-
105
- @param {RegExp} regex
106
- @returns {string}
107
- */
108
- consumeUntilMatch(regex: RegExp): string;
109
- /**
110
- Consumes characters until the given string is found, advancing the scanner up
111
- to (but not beyond) that point.
112
-
113
- Returns the consumed string, or an empty string if nothing was consumed.
114
-
115
- @param {string} searchString
116
- @returns {string}
117
- */
118
- consumeUntilString(searchString: string): string;
119
- /**
120
- Returns the given number of characters starting at the current character
121
- index, without advancing the scanner and without exceeding the end of the
122
- input string.
123
-
124
- @param {number} [count]
125
- @returns {string}
126
- */
127
- peek(count?: number | undefined): string;
128
- /**
129
- Resets the scanner position to the given character _index_, or to the start of
130
- the input string if no index is given.
131
-
132
- If _index_ is negative, the scanner position will be moved backward by that
133
- many characters, stopping if the beginning of the string is reached.
134
-
135
- @param {number} [index]
136
- */
137
- reset(index?: number | undefined): void;
138
- }
139
- //# sourceMappingURL=StringScanner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StringScanner.d.ts","sourceRoot":"","sources":["../../../src/lib/StringScanner.js"],"names":[],"mappings":";AAIA;;EAEE;AACF;IACE;;MAEE;IACF,oBAFQ,MAAM,EAwCb;IArCC,uBAAuB;IACvB,OADW,MAAM,EAAE,CACO;IAE1B,qBAAqB;IACrB,WADW,MAAM,CACiB;IAElC,qBAAqB;IACrB,WADW,MAAM,CACC;IAElB,uBAAuB;IACvB,cADW,MAAM,EAAE,CAC0B;IAE7C,sBAAsB;IACtB,eADW,OAAO,CACQ;IAE1B,qBAAqB;IACrB,QADW,MAAM,CACG;IAuBtB;;;;MAIE;IACF,qBAEC;IAID;;;;;;MAME;IACF,oBAHQ,MAAM,GACJ,MAAM,CAaf;IAID;;;;;MAKE;IACF,0CAEC;IAED;;;;;;;;MAQE;IACF,qCAFU,MAAM,CAMf;IAED;;;;;;;;;;;MAWE;IACF,oBAHQ,MAAM,GACJ,MAAM,CAkBf;IAED;;;;;;;MAOE;IACF,0BAHe,MAAM,KAAK,OAAO,GACvB,MAAM,CAYf;IAED;;;;;;;;;MASE;IACF,+BAHQ,MAAM,GACJ,MAAM,CAsBf;IAED;;;;;;;OAOG;IACH,mCAHW,MAAM,GACJ,MAAM,CAkBlB;IAED;;;;;;;;;;;;MAYE;IACF,yBAHQ,MAAM,GACJ,MAAM,CAmBf;IAED;;;;;;;;MAQE;IACF,iCAHQ,MAAM,GACJ,MAAM,CAcf;IAED;;;;;;;MAOE;IACF,kCAFU,MAAM,CAef;IAED;;;;;;;;MAQE;IACF,wCAIC;CACF"}
@@ -1,11 +0,0 @@
1
- export = XmlCdata;
2
- /**
3
- A CDATA section within an XML document.
4
-
5
- @public
6
- */
7
- declare class XmlCdata extends XmlText {
8
- constructor(text?: string | undefined);
9
- }
10
- import XmlText = require("./XmlText");
11
- //# sourceMappingURL=XmlCdata.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XmlCdata.d.ts","sourceRoot":"","sources":["../../../src/lib/XmlCdata.js"],"names":[],"mappings":";AAKA;;;;EAIE;AACF;IAFC,uCASyD;CAHzD"}
@@ -1,21 +0,0 @@
1
- export = XmlComment;
2
- /**
3
- A comment within an XML document.
4
-
5
- @public
6
- */
7
- declare class XmlComment extends XmlNode {
8
- /**
9
- @param {string} [content]
10
- */
11
- constructor(content?: string | undefined);
12
- /**
13
- Content of this comment.
14
-
15
- @type {string}
16
- @public
17
- */
18
- public content: string;
19
- }
20
- import XmlNode = require("./XmlNode");
21
- //# sourceMappingURL=XmlComment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XmlComment.d.ts","sourceRoot":"","sources":["../../../src/lib/XmlComment.js"],"names":[],"mappings":";AAIA;;;;EAIE;AACF;IACE;;MAEE;IACF,0CAUC;IAPC;;;;;MAKE;IACF,gBAHO,MAAM,CAGS;CAYzB"}
@@ -1,42 +0,0 @@
1
- export = XmlDocument;
2
- /**
3
- Represents an XML document. All elements within the document are descendants of
4
- this node.
5
-
6
- @public
7
- */
8
- declare class XmlDocument extends XmlNode {
9
- /**
10
- @param {Array<XmlComment|XmlElement|XmlProcessingInstruction>} [children]
11
- */
12
- constructor(children?: (import("./XmlComment") | import("./XmlProcessingInstruction") | XmlElement)[] | undefined);
13
- /**
14
- Child nodes of this document.
15
-
16
- @type {Array<XmlComment|XmlElement|XmlProcessingInstruction>}
17
- @public
18
- */
19
- public children: Array<XmlComment | XmlElement | XmlProcessingInstruction>;
20
- /**
21
- Root element of this document, or `null` if this document is empty.
22
-
23
- @type {XmlElement?}
24
- @public
25
- */
26
- public get root(): XmlElement | null;
27
- /**
28
- Text content of this document and all its descendants.
29
-
30
- @type {string}
31
- @public
32
- */
33
- public get text(): string;
34
- }
35
- declare namespace XmlDocument {
36
- export { XmlComment, XmlProcessingInstruction };
37
- }
38
- import XmlNode = require("./XmlNode");
39
- type XmlComment = import("./XmlComment");
40
- import XmlElement = require("./XmlElement");
41
- type XmlProcessingInstruction = import("./XmlProcessingInstruction");
42
- //# sourceMappingURL=XmlDocument.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XmlDocument.d.ts","sourceRoot":"","sources":["../../../src/lib/XmlDocument.js"],"names":[],"mappings":";AAKA;;;;;EAKE;AACF;IACE;;MAEE;IACF,mHAUC;IAPC;;;;;MAKE;IACF,iBAHO,MAAM,UAAU,GAAC,UAAU,GAAC,wBAAwB,CAAC,CAGpC;IAO1B;;;;;MAKE;IACF,qCAGC;IAED;;;;;MAKE;IACF,0BAIC;CAWF"}
@@ -1,62 +0,0 @@
1
- export = XmlElement;
2
- /**
3
- Element in an XML document.
4
-
5
- @public
6
- */
7
- declare class XmlElement extends XmlNode {
8
- /**
9
- @param {string} name
10
- @param {{[attrName: string]: string}} [attributes]
11
- @param {Array<XmlCdata|XmlComment|XmlElement|XmlProcessingInstruction|XmlText>} [children]
12
- */
13
- constructor(name: string, attributes?: {
14
- [attrName: string]: string;
15
- } | undefined, children?: (import("./XmlComment") | import("./XmlProcessingInstruction") | import("./XmlText") | import("./XmlElement") | import("./XmlCdata"))[] | undefined);
16
- /**
17
- Name of this element.
18
-
19
- @type {string}
20
- @public
21
- */
22
- public name: string;
23
- /**
24
- Attributes on this element.
25
-
26
- @type {{[attrName: string]: string}}
27
- @public
28
- */
29
- public attributes: {
30
- [attrName: string]: string;
31
- };
32
- /**
33
- Child nodes of this element.
34
-
35
- @type {Array<XmlCdata|XmlComment|XmlElement|XmlProcessingInstruction|XmlText>}
36
- @public
37
- */
38
- public children: Array<XmlCdata | XmlComment | XmlElement | XmlProcessingInstruction | XmlText>;
39
- /**
40
- Whether this node is empty (meaning it has no children).
41
-
42
- @type {boolean}
43
- @public
44
- */
45
- public get isEmpty(): boolean;
46
- /**
47
- Text content of this element and all its descendants.
48
-
49
- @type {string}
50
- @public
51
- */
52
- public get text(): string;
53
- }
54
- declare namespace XmlElement {
55
- export { XmlCdata, XmlComment, XmlProcessingInstruction, XmlText };
56
- }
57
- import XmlNode = require("./XmlNode");
58
- type XmlCdata = import("./XmlCdata");
59
- type XmlComment = import("./XmlComment");
60
- type XmlProcessingInstruction = import("./XmlProcessingInstruction");
61
- type XmlText = import("./XmlText");
62
- //# sourceMappingURL=XmlElement.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XmlElement.d.ts","sourceRoot":"","sources":["../../../src/lib/XmlElement.js"],"names":[],"mappings":";AAIA;;;;EAIE;AACF;IACE;;;;MAIE;IACF,kBAJQ,MAAM;;mLA8Bb;IAvBC;;;;;MAKE;IACF,aAHO,MAAM,CAGG;IAEhB;;;;;MAKE;IACF;;MAA4B;IAE5B;;;;;MAKE;IACF,iBAHO,MAAM,QAAQ,GAAC,UAAU,GAAC,UAAU,GAAC,wBAAwB,GAAC,OAAO,CAAC,CAGrD;IAG1B;;;;;MAKE;IACF,8BAEC;IAkBD;;;;;MAKE;IACF,0BAIC;CAcF"}
@@ -1,78 +0,0 @@
1
- export = XmlNode;
2
- /**
3
- Base interface for a node in an XML document.
4
-
5
- @public
6
- */
7
- declare class XmlNode {
8
- /**
9
- Parent node of this node, or `null` if this node has no parent.
10
-
11
- @type {XmlDocument|XmlElement|null}
12
- @public
13
- */
14
- public parent: XmlDocument | XmlElement | null;
15
- /**
16
- Document that contains this node, or `null` if this node is not associated
17
- with a document.
18
-
19
- @type {XmlDocument?}
20
- @public
21
- */
22
- public get document(): import("./XmlDocument") | null;
23
- /**
24
- Whether this node is the root node of the document.
25
-
26
- @returns {boolean}
27
- @public
28
- */
29
- public get isRootNode(): boolean;
30
- /**
31
- Whether whitespace should be preserved in the content of this element and
32
- its children.
33
-
34
- This is influenced by the value of the special `xml:space` attribute, and
35
- will be `true` for any node whose `xml:space` attribute is set to
36
- "preserve". If a node has no such attribute, it will inherit the value of
37
- the nearest ancestor that does (if any).
38
-
39
- @type {boolean}
40
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space
41
- @public
42
- */
43
- public get preserveWhitespace(): boolean;
44
- /**
45
- Type of this node.
46
-
47
- The value of this property is a string that matches one of the static `TYPE_*`
48
- properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`, `TYPE_TEXT`, etc.).
49
-
50
- The `XmlNode` class itself is a base class and doesn't have its own type name.
51
-
52
- @type {string}
53
- @public
54
- */
55
- public get type(): string;
56
- /**
57
- Returns a JSON-serializable object representing this node, minus properties
58
- that could result in circular references.
59
-
60
- @returns {{[key: string]: any}}
61
- @public
62
- */
63
- public toJSON(): {
64
- [key: string]: any;
65
- };
66
- }
67
- declare namespace XmlNode {
68
- export { TYPE_CDATA, TYPE_COMMENT, TYPE_DOCUMENT, TYPE_ELEMENT, TYPE_PROCESSING_INSTRUCTION, TYPE_TEXT, XmlDocument, XmlElement };
69
- }
70
- type XmlDocument = import("./XmlDocument");
71
- type XmlElement = import("./XmlElement");
72
- declare var TYPE_CDATA: string;
73
- declare var TYPE_COMMENT: string;
74
- declare var TYPE_DOCUMENT: string;
75
- declare var TYPE_ELEMENT: string;
76
- declare var TYPE_PROCESSING_INSTRUCTION: string;
77
- declare var TYPE_TEXT: string;
78
- //# sourceMappingURL=XmlNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XmlNode.d.ts","sourceRoot":"","sources":["../../../src/lib/XmlNode.js"],"names":[],"mappings":";AAEA;;;;EAIE;AACF;IAEI;;;;;MAKE;IACF,eAHO,WAAW,GAAC,UAAU,GAAC,IAAI,CAGhB;IAGpB;;;;;;MAME;IACF,sDAIC;IAED;;;;;MAKE;IACF,iCAIC;IAED;;;;;;;;;;;;MAYE;IACF,yCAEC;IAED;;;;;;;;;;MAUE;IACF,0BAEC;IAED;;;;;;MAME;IACF;;MAeC;CACF;;;;;;wBAKM,MAAM;0BAQN,MAAM;2BAQN,MAAM;0BAQN,MAAM;yCAQN,MAAM;uBAQN,MAAM"}
@@ -1,30 +0,0 @@
1
- export = XmlProcessingInstruction;
2
- /**
3
- A processing instruction within an XML document.
4
-
5
- @public
6
- */
7
- declare class XmlProcessingInstruction extends XmlNode {
8
- /**
9
- @param {string} name
10
- @param {string} [content]
11
- */
12
- constructor(name: string, content?: string | undefined);
13
- /**
14
- Name of this processing instruction. Also sometimes referred to as the
15
- processing instruction "target".
16
-
17
- @type {string}
18
- @public
19
- */
20
- public name: string;
21
- /**
22
- Content of this processing instruction.
23
-
24
- @type {string}
25
- @public
26
- */
27
- public content: string;
28
- }
29
- import XmlNode = require("./XmlNode");
30
- //# sourceMappingURL=XmlProcessingInstruction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XmlProcessingInstruction.d.ts","sourceRoot":"","sources":["../../../src/lib/XmlProcessingInstruction.js"],"names":[],"mappings":";AAIA;;;;EAIE;AACF;IACE;;;MAGE;IACF,kBAHQ,MAAM,gCAsBb;IAhBC;;;;;;MAME;IACF,aAHO,MAAM,CAGG;IAEhB;;;;;MAKE;IACF,gBAHO,MAAM,CAGS;CAazB"}
@@ -1,21 +0,0 @@
1
- export = XmlText;
2
- /**
3
- Text content within an XML document.
4
-
5
- @public
6
- */
7
- declare class XmlText extends XmlNode {
8
- /**
9
- @param {string} [text]
10
- */
11
- constructor(text?: string | undefined);
12
- /**
13
- Text content of this node.
14
-
15
- @type {string}
16
- @public
17
- */
18
- public text: string;
19
- }
20
- import XmlNode = require("./XmlNode");
21
- //# sourceMappingURL=XmlText.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XmlText.d.ts","sourceRoot":"","sources":["../../../src/lib/XmlText.js"],"names":[],"mappings":";AAIA;;;;EAIE;AACF;IACE;;MAEE;IACF,uCAUC;IAPC;;;;;MAKE;IACF,aAHO,MAAM,CAGG;CAYnB"}
@@ -1,59 +0,0 @@
1
- /**
2
- Mapping of predefined entity names to their replacement values.
3
-
4
- @type {Readonly<{[name: string]: string}>}
5
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent
6
- */
7
- export const predefinedEntities: Readonly<{
8
- [name: string]: string;
9
- }>;
10
- /**
11
- Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.
12
-
13
- @param {string} char
14
- @returns {boolean}
15
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar
16
- */
17
- export function isNameChar(char: string): boolean;
18
- /**
19
- Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.
20
-
21
- @param {string} char
22
- @returns {boolean}
23
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar
24
- */
25
- export function isNameStartChar(char: string): boolean;
26
- /**
27
- Returns `true` if _char_ is not a valid XML `Char`, `false` otherwise.
28
-
29
- @param {string} char
30
- @returns {boolean}
31
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char
32
- */
33
- export function isNotXmlChar(char: string): boolean;
34
- /**
35
- Returns `true` if _char_ is a valid reference character (which may appear
36
- between `&` and `;` in a reference), `false` otherwise.
37
-
38
- @param {string} char
39
- @returns {boolean}
40
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references
41
- */
42
- export function isReferenceChar(char: string): boolean;
43
- /**
44
- Returns `true` if _char_ is an XML whitespace character, `false` otherwise.
45
-
46
- @param {string} char
47
- @returns {boolean}
48
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
49
- */
50
- export function isWhitespace(char: string): boolean;
51
- /**
52
- Returns `true` if _char_ is a valid XML `Char`, `false` otherwise.
53
-
54
- @param {string} char
55
- @returns {boolean}
56
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char
57
- */
58
- export function isXmlChar(char: string): boolean;
59
- //# sourceMappingURL=syntax.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../../../src/lib/syntax.js"],"names":[],"mappings":"AAIA;;;;;EAKE;AACF;;GAMI;AAMJ;;;;;;EAME;AACF,iCAJQ,MAAM,GACJ,OAAO,CAgBhB;AAID;;;;;;EAME;AACF,sCAJQ,MAAM,GACJ,OAAO,CAsBhB;AAID;;;;;;EAME;AACF,mCAJQ,MAAM,GACJ,OAAO,CAKhB;AAID;;;;;;;EAOE;AACF,sCAJQ,MAAM,GACJ,OAAO,CAKhB;AAID;;;;;;EAME;AACF,mCAJQ,MAAM,GACJ,OAAO,CAUhB;AAID;;;;;;EAME;AACF,gCAJQ,MAAM,GACJ,OAAO,CAYhB"}
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["parse-xml"]=t():e.parseXml=t()}("undefined"==typeof self?this:self,(function(){return(()=>{"use strict";var e={138:(e,t,n)=>{const s=n(567),r=n(12),i=n(190),o=n(315),c=n(914),a=n(526),h=n(141),u=n(684);function l(e,t){return new s(e,t).document}l.XmlCdata=r,l.XmlComment=i,l.XmlDocument=o,l.XmlElement=c,l.XmlNode=a,l.XmlProcessingInstruction=h,l.XmlText=u,e.exports=l},567:(e,t,n)=>{const s=n(444),r=n(531),i=n(12),o=n(190),c=n(315),a=n(914),h=n(141),u=n(684);e.exports=class{constructor(e,t={}){for(this.document=new c,this.currentNode=this.document,this.options=t,this.scanner=new s(function(e){return"\ufeff"===e[0]&&(e=e.slice(1)),e.replace(/\r\n?/g,"\n")}(e)),this.consumeProlog(),this.consumeElement()||this.error("Root element is missing or invalid");this.consumeMisc(););this.scanner.isEnd||this.error("Extra content at the end of the document")}addNode(e){e.parent=this.currentNode,this.currentNode.children.push(e)}addText(e){let{children:t}=this.currentNode;if(t.length>0){let n=t[t.length-1];if(n instanceof u)return void(n.text+=e)}this.addNode(new u(e))}consumeAttributeValue(){let e,{scanner:t}=this,n=t.peek();if('"'!==n&&"'"!==n)return!1;t.advance();let s=!1,r="",i='"'===n?/[^"&<]+/y:/[^'&<]+/y;e:for(;!t.isEnd;)switch(e=t.consumeMatch(i),e&&(this.validateChars(e),r+=e.replace(/[\t\r\n]/g," ")),t.peek()){case n:s=!0;break e;case"&":r+=this.consumeReference();continue;case"<":this.error("Unescaped `<` is not allowed in an attribute value");break;case"":this.error("Unclosed attribute")}return s||this.error("Unclosed attribute"),t.advance(),r}consumeCdataSection(){let{scanner:e}=this;if(!e.consumeStringFast("<![CDATA["))return!1;let t=e.consumeUntilString("]]>");return this.validateChars(t),e.consumeStringFast("]]>")||this.error("Unclosed CDATA section"),this.options.preserveCdata?this.addNode(new i(t)):this.addText(t),!0}consumeCharData(){let{scanner:e}=this,t=e.consumeUntilMatch(/<|&|]]>/g);return!!t&&(this.validateChars(t),"]"===e.peek()&&"]]>"===e.peek(3)&&this.error("Element content may not contain the CDATA section close delimiter `]]>`"),this.addText(t),!0)}consumeComment(){let{scanner:e}=this;if(!e.consumeStringFast("\x3c!--"))return!1;let t=e.consumeUntilString("--");return this.validateChars(t),e.consumeStringFast("--\x3e")||("--"===e.peek(2)?this.error("The string `--` isn't allowed inside a comment"):this.error("Unclosed comment")),this.options.preserveComments&&this.addNode(new o(t.trim())),!0}consumeContentReference(){let e=this.consumeReference();return!!e&&(this.addText(e),!0)}consumeDoctypeDeclaration(){let{scanner:e}=this;return!(!e.consumeStringFast("<!DOCTYPE")||!this.consumeWhitespace()||(e.consumeMatch(/[^[>]+/y),e.consumeMatch(/\[[\s\S]+?\][\x20\t\r\n]*>/y)||e.consumeStringFast(">")||this.error("Unclosed doctype declaration"),0))}consumeElement(){let{scanner:e}=this,t=e.charIndex;if("<"!==e.peek())return!1;e.advance();let n=this.consumeName();if(!n)return e.reset(t),!1;let s=Object.create(null);for(;this.consumeWhitespace();){let e=this.consumeName();if(!e)continue;let t=this.consumeEqual()&&this.consumeAttributeValue();!1===t&&this.error("Attribute value expected"),e in s&&this.error(`Duplicate attribute: ${e}`),"xml:space"===e&&"default"!==t&&"preserve"!==t&&this.error('Value of the `xml:space` attribute must be "default" or "preserve"'),s[e]=t}if(this.options.sortAttributes){let e=Object.keys(s).sort(),t=Object.create(null);for(let n=0;n<e.length;++n){let r=e[n];t[r]=s[r]}s=t}let r=Boolean(e.consumeStringFast("/>")),i=new a(n,s);if(i.parent=this.currentNode,!r){for(e.consumeStringFast(">")||this.error(`Unclosed start tag for element \`${n}\``),this.currentNode=i,this.consumeCharData();this.consumeElement()||this.consumeContentReference()||this.consumeCdataSection()||this.consumeProcessingInstruction()||this.consumeComment();)this.consumeCharData();let t,s=e.charIndex;e.consumeStringFast("</")&&(t=this.consumeName())&&t===n||(e.reset(s),this.error(`Missing end tag for element ${n}`)),this.consumeWhitespace(),e.consumeStringFast(">")||this.error(`Unclosed end tag for element ${n}`),this.currentNode=i.parent}return this.addNode(i),!0}consumeEqual(){return this.consumeWhitespace(),!!this.scanner.consumeStringFast("=")&&(this.consumeWhitespace(),!0)}consumeMisc(){return this.consumeComment()||this.consumeProcessingInstruction()||this.consumeWhitespace()}consumeName(){return r.isNameStartChar(this.scanner.peek())?this.scanner.consumeMatchFn(r.isNameChar):""}consumeProcessingInstruction(){let{scanner:e}=this,t=e.charIndex;if(!e.consumeStringFast("<?"))return!1;let n=this.consumeName();if(n?"xml"===n.toLowerCase()&&(e.reset(t),this.error("XML declaration isn't allowed here")):this.error("Invalid processing instruction"),!this.consumeWhitespace()){if(e.consumeStringFast("?>"))return this.addNode(new h(n)),!0;this.error("Whitespace is required after a processing instruction name")}let s=e.consumeUntilString("?>");return this.validateChars(s),e.consumeStringFast("?>")||this.error("Unterminated processing instruction"),this.addNode(new h(n,s)),!0}consumeProlog(){let{scanner:e}=this,t=e.charIndex;for(this.consumeXmlDeclaration();this.consumeMisc(););if(this.consumeDoctypeDeclaration())for(;this.consumeMisc(););return t<e.charIndex}consumeReference(){let{scanner:e}=this;if("&"!==e.peek())return!1;e.advance();let t,n=e.consumeMatchFn(r.isReferenceChar);if(";"!==e.consume()&&this.error("Unterminated reference (a reference must end with `;`)"),"#"===n[0]){let e="x"===n[1]?parseInt(n.slice(2),16):parseInt(n.slice(1),10);isNaN(e)&&this.error("Invalid character reference"),t=String.fromCodePoint(e),r.isXmlChar(t)||this.error("Character reference resolves to an invalid character")}else if(t=r.predefinedEntities[n],void 0===t){let{ignoreUndefinedEntities:t,resolveUndefinedEntity:s}=this.options,r=`&${n};`;if(s){let e=s(r);if(null!=e){let t=typeof e;if("string"!==t)throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${t}`);return e}}if(t)return r;e.reset(-r.length),this.error(`Named entity isn't defined: ${r}`)}return t}consumeSystemLiteral(){let{scanner:e}=this,t=e.consumeStringFast('"')||e.consumeStringFast("'");if(!t)return!1;let n=e.consumeUntilString(t);return this.validateChars(n),e.consumeStringFast(t)||this.error("Missing end quote"),n}consumeWhitespace(){return Boolean(this.scanner.consumeMatchFn(r.isWhitespace))}consumeXmlDeclaration(){let{scanner:e}=this;if(!e.consumeStringFast("<?xml"))return!1;this.consumeWhitespace()||this.error("Invalid XML declaration");let t=Boolean(e.consumeStringFast("version"))&&this.consumeEqual()&&this.consumeSystemLiteral();if(!1===t?this.error("XML version is missing or invalid"):/^1\.[0-9]+$/.test(t)||this.error("Invalid character in version number"),this.consumeWhitespace()){Boolean(e.consumeStringFast("encoding"))&&this.consumeEqual()&&this.consumeSystemLiteral()&&this.consumeWhitespace();let t=Boolean(e.consumeStringFast("standalone"))&&this.consumeEqual()&&this.consumeSystemLiteral();t&&("yes"!==t&&"no"!==t&&this.error('Only "yes" and "no" are permitted as values of `standalone`'),this.consumeWhitespace())}return e.consumeStringFast("?>")||this.error("Invalid or unclosed XML declaration"),!0}error(e){let{charIndex:t,string:n}=this.scanner,s=1,r="",i=1;for(let e=0;e<t;++e){let t=n[e];"\n"===t?(s=1,r="",i+=1):(s+=1,r+=t)}let o=n.indexOf("\n",t);r+=-1===o?n.slice(t):n.slice(t,o);let c=0;r.length>50&&(s<40?r=r.slice(0,50):(c=s-20,r=r.slice(c,s+30)));let a=new Error(`${e} (line ${i}, column ${s})\n ${r}\n`+" ".repeat(s-c+1)+"^\n");throw Object.assign(a,{column:s,excerpt:r,line:i,pos:t}),a}validateChars(e){let t=0;for(let n of e)r.isNotXmlChar(n)&&(this.scanner.reset(-([...e].length-t)),this.error("Invalid character")),t+=1}}},444:e=>{const t="";e.exports=class{constructor(e){this.chars=[...e],this.charCount=this.chars.length,this.charIndex=0,this.charsToBytes=new Array(this.charCount),this.multiByteMode=!1,this.string=e;let{chars:t,charCount:n,charsToBytes:s}=this;if(n===e.length)for(let e=0;e<n;++e)s[e]=e;else{for(let e=0,r=0;r<n;++r)s[r]=e,e+=t[r].length;this.multiByteMode=!0}}get isEnd(){return this.charIndex>=this.charCount}_charLength(e){let{length:t}=e;return t<2||!this.multiByteMode?t:e.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"_").length}advance(e=1){this.charIndex=Math.min(this.charCount,this.charIndex+e)}consume(e=1){let t=this.peek(e);return this.advance(e),t}consumeMatch(e){if(!e.sticky)throw new Error('`regex` must have a sticky flag ("y")');e.lastIndex=this.charsToBytes[this.charIndex];let n=e.exec(this.string);if(null===n)return t;let s=n[0];return this.advance(this._charLength(s)),s}consumeMatchFn(e){let n=this.charIndex;for(;!this.isEnd&&e(this.peek());)this.advance();return this.charIndex>n?this.string.slice(this.charsToBytes[n],this.charsToBytes[this.charIndex]):t}consumeString(e){if(this.consumeStringFast(e))return e;if(!this.multiByteMode)return t;let{length:n}=e,s=this._charLength(e);return s!==n&&e===this.peek(s)?(this.advance(s),e):t}consumeStringFast(e){if(this.peek()===e[0]){let{length:t}=e;if(1===t)return this.advance(),e;if(this.peek(t)===e)return this.advance(t),e}return t}consumeUntilMatch(e){if(!e.global)throw new Error('`regex` must have a global flag ("g")');let n=this.charsToBytes[this.charIndex];e.lastIndex=n;let s=e.exec(this.string);if(null===s||s.index===n)return t;let r=this.string.slice(n,s.index);return this.advance(this._charLength(r)),r}consumeUntilString(e){let{charIndex:n,charsToBytes:s,string:r}=this,i=s[n],o=r.indexOf(e,i);if(o<=0)return t;let c=r.slice(i,o);return this.advance(this._charLength(c)),c}peek(e=1){if(this.charIndex>=this.charCount)return t;if(1===e)return this.chars[this.charIndex];let{charsToBytes:n,charIndex:s}=this;return this.string.slice(n[s],n[s+e])}reset(e=0){this.charIndex=e>=0?Math.min(this.charCount,e):Math.max(0,this.charIndex+e)}}},12:(e,t,n)=>{const s=n(526),r=n(684);e.exports=class extends r{get type(){return s.TYPE_CDATA}}},190:(e,t,n)=>{const s=n(526);e.exports=class extends s{constructor(e=""){super(),this.content=e}get type(){return s.TYPE_COMMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{content:this.content})}}},315:(e,t,n)=>{const s=n(914),r=n(526);e.exports=class extends r{constructor(e=[]){super(),this.children=e}get document(){return this}get root(){return this.children.find((e=>e instanceof s))||null}get text(){return this.children.map((e=>"text"in e?e.text:"")).join("")}get type(){return r.TYPE_DOCUMENT}toJSON(){return Object.assign(r.prototype.toJSON.call(this),{children:this.children.map((e=>e.toJSON()))})}}},914:(e,t,n)=>{const s=n(526);class r extends s{constructor(e,t=Object.create(null),n=[]){super(),this.name=e,this.attributes=t,this.children=n}get isEmpty(){return 0===this.children.length}get preserveWhitespace(){let e=this;for(;e instanceof r;){if("xml:space"in e.attributes)return"preserve"===e.attributes["xml:space"];e=e.parent}return!1}get text(){return this.children.map((e=>"text"in e?e.text:"")).join("")}get type(){return s.TYPE_ELEMENT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{name:this.name,attributes:this.attributes,children:this.children.map((e=>e.toJSON()))})}}e.exports=r},526:e=>{class t{constructor(){this.parent=null}get document(){return this.parent?this.parent.document:null}get isRootNode(){return!!this.parent&&this.parent===this.document}get preserveWhitespace(){return Boolean(this.parent&&this.parent.preserveWhitespace)}get type(){return""}toJSON(){let e={type:this.type};return this.isRootNode&&(e.isRootNode=!0),this.preserveWhitespace&&(e.preserveWhitespace=!0),e}}t.TYPE_CDATA="cdata",t.TYPE_COMMENT="comment",t.TYPE_DOCUMENT="document",t.TYPE_ELEMENT="element",t.TYPE_PROCESSING_INSTRUCTION="pi",t.TYPE_TEXT="text",e.exports=t},141:(e,t,n)=>{const s=n(526);e.exports=class extends s{constructor(e,t=""){super(),this.name=e,this.content=t}get type(){return s.TYPE_PROCESSING_INSTRUCTION}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{name:this.name,content:this.content})}}},684:(e,t,n)=>{const s=n(526);e.exports=class extends s{constructor(e=""){super(),this.text=e}get type(){return s.TYPE_TEXT}toJSON(){return Object.assign(s.prototype.toJSON.call(this),{text:this.text})}}},531:(e,t)=>{const n=Object.freeze(Object.assign(Object.create(null),{amp:"&",apos:"'",gt:">",lt:"<",quot:'"'}));function s(e){if(r(e))return!0;let t=o(e);return 45===t||46===t||t>=48&&t<=57||183===t||t>=768&&t<=879||t>=8255&&t<=8256}function r(e){let t=o(e);return 58===t||95===t||t>=65&&t<=90||t>=97&&t<=122||t>=192&&t<=214||t>=216&&t<=246||t>=248&&t<=767||t>=880&&t<=893||t>=895&&t<=8191||t>=8204&&t<=8205||t>=8304&&t<=8591||t>=11264&&t<=12271||t>=12289&&t<=55295||t>=63744&&t<=64975||t>=65008&&t<=65533||t>=65536&&t<=983039}function i(e){let t=o(e);return 9===t||10===t||13===t||t>=32&&t<=55295||t>=57344&&t<=65533||t>=65536&&t<=1114111}function o(e){return e.codePointAt(0)||-1}t.predefinedEntities=n,t.isNameChar=s,t.isNameStartChar=r,t.isNotXmlChar=function(e){return!i(e)},t.isReferenceChar=function(e){return"#"===e||s(e)},t.isWhitespace=function(e){let t=o(e);return 32===t||9===t||10===t||13===t},t.isXmlChar=i}},t={};return function n(s){if(t[s])return t[s].exports;var r=t[s]={exports:{}};return e[s](r,r.exports,n),r.exports}(138)})()}));
2
- //# sourceMappingURL=parse-xml.min.js.map