@rgrove/parse-xml 3.0.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.
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 +30 -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 -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
@@ -0,0 +1,136 @@
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 const attValueCharDoubleQuote = /[^"&<]+/y;
8
+
9
+ /**
10
+ * Regular expression that matches one or more `AttValue` characters in a
11
+ * single-quoted attribute value.
12
+ *
13
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
14
+ */
15
+ export const attValueCharSingleQuote = /[^'&<]+/y;
16
+
17
+ /**
18
+ * Regular expression that matches a whitespace character that should be
19
+ * normalized to a space character in an attribute value.
20
+ *
21
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize
22
+ */
23
+ export const attValueNormalizedWhitespace = /[\t\n]/g;
24
+
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
+ export const endCharData = /<|&|]]>/;
32
+
33
+ /**
34
+ * Mapping of predefined entity names to their replacement values.
35
+ *
36
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-predefined-ent
37
+ */
38
+ export const predefinedEntities: Readonly<{[name: string]: string;}> = Object.freeze(Object.assign(Object.create(null), {
39
+ amp: '&',
40
+ apos: "'",
41
+ gt: '>',
42
+ lt: '<',
43
+ quot: '"',
44
+ }));
45
+
46
+ /**
47
+ * Returns `true` if _char_ is an XML `NameChar`, `false` if it isn't.
48
+ *
49
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar
50
+ */
51
+ export function isNameChar(char: string): boolean {
52
+ let cp = getCodePoint(char);
53
+
54
+ // Including the most common NameStartChars here improves performance
55
+ // slightly.
56
+ return (cp >= 0x61 && cp <= 0x7A) // a-z
57
+ || (cp >= 0x41 && cp <= 0x5A) // A-Z
58
+ || (cp >= 0x30 && cp <= 0x39) // 0-9
59
+ || cp === 0x2D // -
60
+ || cp === 0x2E // .
61
+ || cp === 0xB7
62
+ || (cp >= 0x300 && cp <= 0x36F)
63
+ || (cp >= 0x203F && cp <= 0x2040)
64
+ || isNameStartChar(char, cp);
65
+ }
66
+
67
+ /**
68
+ * Returns `true` if _char_ is an XML `NameStartChar`, `false` if it isn't.
69
+ *
70
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameStartChar
71
+ */
72
+ export function isNameStartChar(char: string, cp = getCodePoint(char)): boolean {
73
+ return (cp >= 0x61 && cp <= 0x7A) // a-z
74
+ || (cp >= 0x41 && cp <= 0x5A) // A-Z
75
+ || cp === 0x3A // :
76
+ || cp === 0x5F // _
77
+ || (cp >= 0xC0 && cp <= 0xD6)
78
+ || (cp >= 0xD8 && cp <= 0xF6)
79
+ || (cp >= 0xF8 && cp <= 0x2FF)
80
+ || (cp >= 0x370 && cp <= 0x37D)
81
+ || (cp >= 0x37F && cp <= 0x1FFF)
82
+ || (cp >= 0x200C && cp <= 0x200D)
83
+ || (cp >= 0x2070 && cp <= 0x218F)
84
+ || (cp >= 0x2C00 && cp <= 0x2FEF)
85
+ || (cp >= 0x3001 && cp <= 0xD7FF)
86
+ || (cp >= 0xF900 && cp <= 0xFDCF)
87
+ || (cp >= 0xFDF0 && cp <= 0xFFFD)
88
+ || (cp >= 0x10000 && cp <= 0xEFFFF);
89
+ }
90
+
91
+ /**
92
+ * Returns `true` if _char_ is a valid reference character (which may appear
93
+ * between `&` and `;` in a reference), `false` otherwise.
94
+ *
95
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references
96
+ */
97
+ export function isReferenceChar(char: string): boolean {
98
+ return char === '#' || isNameChar(char);
99
+ }
100
+
101
+ /**
102
+ * Returns `true` if _char_ is an XML whitespace character, `false` otherwise.
103
+ *
104
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
105
+ */
106
+ export function isWhitespace(char: string): boolean {
107
+ let cp = getCodePoint(char);
108
+
109
+ return cp === 0x20
110
+ || cp === 0x9
111
+ || cp === 0xA
112
+ || cp === 0xD;
113
+ }
114
+
115
+ /**
116
+ * Returns `true` if _codepoint_ is a valid XML `Char` code point, `false`
117
+ * otherwise.
118
+ *
119
+ * @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char
120
+ */
121
+ export function isXmlCodePoint(cp: number): boolean {
122
+ return cp === 0x9
123
+ || cp === 0xA
124
+ || cp === 0xD
125
+ || (cp >= 0x20 && cp <= 0xD7FF)
126
+ || (cp >= 0xE000 && cp <= 0xFFFD)
127
+ || (cp >= 0x10000 && cp <= 0x10FFFF);
128
+ }
129
+
130
+ /**
131
+ * Returns the Unicode code point value of the given character, or `-1` if
132
+ * _char_ is empty.
133
+ */
134
+ function getCodePoint(char: string): number {
135
+ return char.codePointAt(0) || -1;
136
+ }
@@ -0,0 +1,2 @@
1
+ export type JsonObject = {[key in string]?: JsonValue};
2
+ export type JsonValue = string | number | boolean | JsonObject | JsonValue[] | null;
package/CHANGELOG.md DELETED
@@ -1,162 +0,0 @@
1
- # parse-xml changelog
2
-
3
- All notable changes to parse-xml are documented in this file. The format is
4
- based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project
5
- adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
-
7
- ## 3.0.0 (2021-01-23)
8
-
9
- This release includes significant changes under the hood (such as a brand new
10
- parser!), but backwards compatibility has been a high priority. Most users
11
- should be able to upgrade without needing to make any changes (or with only
12
- minimal changes).
13
-
14
- ### Added
15
-
16
- - XML declarations (like `<?xml version="1.0"?>`) and processing instructions
17
- are now included in parsed documents as `XmlProcessingInstruction` nodes
18
- (with the `type` value "pi"). Previously they were discarded.
19
-
20
- - A new `sortAttributes` option. When `true`, attributes will be sorted in
21
- alphabetical order in an element's `attributes` object (which is no longer
22
- the default behavior).
23
-
24
- - TypeScript type definitions. While parse-xml is still written in JavaScript,
25
- it now has TypeScript-friendly JSDoc comments throughout, with strict type
26
- checking enabled. These comments are now used to generate type definitions
27
- at build time.
28
-
29
- ### Changed
30
-
31
- - The minimum supported Node.js version is now 12.x, and the minimum supported
32
- ECMAScript version is ES2017. Extremely old browsers (like IE11) are no
33
- longer supported out of the box, but you can still transpile parse-xml
34
- yourself if you need to support old browsers.
35
-
36
- - The XML parser has been completely rewritten with the primary goals of
37
- improving robustness and safety.
38
-
39
- While the previous parser was good, it relied heavily on complex regular
40
- expressions. This helped keep it extremely small, but also left it open to
41
- the possibility of regex denial of service bugs when parsing unusual or
42
- maliciously crafted input.
43
-
44
- The new parser uses a less interesting but overall safer approach, and
45
- employs regular expressions only sparingly and in ways that aren't risky
46
- (they're now only used as performance optimizations rather than as the basis
47
- for the entire parser).
48
-
49
- - The `parseXml()` function now returns an `XmlDocument` instance instead of a
50
- plain object. Its properties are backwards compatible.
51
-
52
- - Other node types (elements, text nodes, CDATA nodes, and comments) are also
53
- now represented by class instances (`XmlElement`, `XmlText`, `XmlCdata`, and
54
- `XmlComment`) rather than plain objects. Their properties are all backwards
55
- compatible.
56
-
57
- - Attributes are no longer sorted alphabetically by name in an element's
58
- `attributes` object by default. They're now defined in the same order that
59
- they're encountered in the document being parsed, unless the
60
- `sortAttributes` parser option is `true`.
61
-
62
- - If the value returned by an optional `resolveUndefinedEntity` function is
63
- not a string, `null`, or `undefined`, a `TypeError` will now be thrown. If
64
- you don't pass a custom `resolveUndefinedEntity` function to `parseXml()`,
65
- then this change won't affect you.
66
-
67
- - Some error messages have been changed to improve clarity, and more helpful
68
- errors have been added in some scenarios that previously would have resulted
69
- in generic or less helpful errors.
70
-
71
- - The `browser` field in `package.json` has been removed and the `main` field
72
- now points both Node.js and browser bundlers to the same untranspiled
73
- CommonJS source.
74
-
75
- When bundled using your favorite bundler, parse-xml will work great in all
76
- modern browsers with no transpilation needed. If you don't want to use a
77
- bundler, you can still use the prepackaged UMD bundle at
78
- `dist/umd/parse-xml.min.js`, which provides a `parseXml` global.
79
-
80
- ## 2.0.4 (2020-05-01)
81
-
82
- ### Fixed
83
-
84
- - Extremely long attribute values no longer cause the parser to throw a
85
- "Maximum call stack size exceeded" `RangeError`. [#13] (@rossj)
86
-
87
- [#13]:https://github.com/rgrove/parse-xml/pull/13
88
-
89
- ## 2.0.3 (2020-04-20)
90
-
91
- ### Fixed
92
-
93
- - Attribute values with many consecutive character references (such as `&lt;`)
94
- no longer cause the parser to hang. [#10] (@rossj)
95
-
96
- [#10]:https://github.com/rgrove/parse-xml/pull/10
97
-
98
- ## 2.0.2 (2020-01-10)
99
-
100
- ### Fixed
101
-
102
- - Whitespace in attribute values is now normalized correctly. [#7]
103
-
104
- Previously, attribute values were normalized according to the rules for
105
- non-CDATA attributes, but this was incorrect and based on a misreading of
106
- the spec.
107
-
108
- Attribute values are now correctly parsed as CDATA, meaning that whitespace
109
- is not collapsed or trimmed and whitespace character entities are resolved
110
- to their respective characters rather than being normalized to spaces (which
111
- was incorrect even by the non-CDATA rules!).
112
-
113
- [#7]:https://github.com/rgrove/parse-xml/pull/7
114
-
115
- ## 2.0.1 (2019-04-09)
116
-
117
- ### Fixed
118
-
119
- - A carriage return (`\r`) character that isn't followed by a line feed (`\n`)
120
- character is now [correctly normalized][xml-line-ends] to a line feed before
121
- parsing.
122
-
123
- [xml-line-ends]:https://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends
124
-
125
- ## 2.0.0 (2019-01-20)
126
-
127
- ### Added
128
-
129
- - There's a new minified UMD bundle at `dist/umd/parse-xml.min.js` in the npm
130
- package. This may be useful if you want to load parse-xml directly in a
131
- browser using a service like
132
- [unpkg](https://unpkg.com/@rgrove/parse-xml/dist/umd/parse-xml.min.js) or
133
- [jsDelivr](https://cdn.jsdelivr.net/npm/@rgrove/parse-xml/dist/umd/parse-xml.min.js).
134
-
135
- ### Changed
136
-
137
- - parse-xml no longer depends on CoreJS polyfills or the Babel runtime, which
138
- reduces the browser bundle size significantly. If you need to support older
139
- browsers, you should provide your own polyfills for `Object.assign()`,
140
- `Object.freeze()`, and `String.fromCodePoint()`.
141
-
142
- - The browser-friendly CommonJS build has moved from `dist/` to
143
- `dist/commonjs/` in the npm package.
144
-
145
- ## 1.1.1 (2017-09-20)
146
-
147
- ### Fixed
148
-
149
- - Attribute values are no longer truncated at the first `=` character.
150
-
151
- ## 1.1.0 (2017-09-10)
152
-
153
- ### Added
154
-
155
- - New parsing option `resolveUndefinedEntity`. [#2]
156
- ([@retorquere](https://github.com/retorquere))
157
-
158
- [#2]:https://github.com/rgrove/parse-xml/pull/2
159
-
160
- ## 1.0.0 (2017-06-04)
161
-
162
- - Initial release.
@@ -1,68 +0,0 @@
1
- export = parseXml;
2
- /**
3
- Parses the given XML string and returns an `XmlDocument` instance representing
4
- the document tree.
5
-
6
- @example
7
-
8
- const parseXml = require('@rgrove/parse-xml');
9
- let doc = parseXml('<kittens fuzzy="yes">I like fuzzy kittens.</kittens>');
10
-
11
- @param {string} xml
12
- XML string to parse.
13
-
14
- @param {object} [options]
15
- Parsing options.
16
-
17
- @param {boolean} [options.ignoreUndefinedEntities=false]
18
- When `true`, an undefined named entity (like "&bogus;") will be left in the
19
- output as is instead of causing a parse error.
20
-
21
- @param {boolean} [options.preserveCdata=false]
22
- When `true`, CDATA sections will be preserved in the document as `XmlCdata`
23
- nodes. Otherwise CDATA sections will be represented as `XmlText` nodes,
24
- which keeps the node tree simpler and easier to work with.
25
-
26
- @param {boolean} [options.preserveComments=false]
27
- When `true`, comments will be preserved in the document as `XmlComment`
28
- nodes. Otherwise comments will not be included in the node tree.
29
-
30
- @param {(entity: string) => string?} [options.resolveUndefinedEntity]
31
- When an undefined named entity is encountered, this function will be called
32
- with the entity as its only argument. It should return a string value with
33
- which to replace the entity, or `null` or `undefined` to treat the entity as
34
- undefined (which may result in a parse error depending on the value of
35
- `ignoreUndefinedEntities`).
36
-
37
- @param {boolean} [options.sortAttributes=false]
38
- When `true`, attributes in an element's `attributes` object will be sorted
39
- in alphanumeric order by name. Otherwise they'll retain their original order
40
- as found in the XML.
41
-
42
- @returns {XmlDocument}
43
- @public
44
- */
45
- declare function parseXml(xml: string, options?: {
46
- ignoreUndefinedEntities?: boolean | undefined;
47
- preserveCdata?: boolean | undefined;
48
- preserveComments?: boolean | undefined;
49
- resolveUndefinedEntity?: ((entity: string) => string | null) | undefined;
50
- sortAttributes?: boolean | undefined;
51
- } | undefined): XmlDocument;
52
- declare namespace parseXml {
53
- export { XmlCdata };
54
- export { XmlComment };
55
- export { XmlDocument };
56
- export { XmlElement };
57
- export { XmlNode };
58
- export { XmlProcessingInstruction };
59
- export { XmlText };
60
- }
61
- import XmlDocument = require("./lib/XmlDocument");
62
- import XmlCdata = require("./lib/XmlCdata");
63
- import XmlComment = require("./lib/XmlComment");
64
- import XmlElement = require("./lib/XmlElement");
65
- import XmlNode = require("./lib/XmlNode");
66
- import XmlProcessingInstruction = require("./lib/XmlProcessingInstruction");
67
- import XmlText = require("./lib/XmlText");
68
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CE;AACF,+BAlCQ,MAAM;;;;uCAmBK,MAAM,KAAK,MAAM;;gBAY1B,WAAW,CAKpB"}
@@ -1,234 +0,0 @@
1
- export = Parser;
2
- /**
3
- Parses an XML string into an `XmlDocument`.
4
-
5
- @private
6
- */
7
- declare class Parser {
8
- /**
9
- @param {string} xml
10
- XML string to parse.
11
-
12
- @param {object} [options]
13
- Parsing options.
14
-
15
- @param {boolean} [options.ignoreUndefinedEntities=false]
16
- @param {boolean} [options.preserveCdata=false]
17
- @param {boolean} [options.preserveComments=false]
18
- @param {(entity: string) => string?} [options.resolveUndefinedEntity]
19
- @param {boolean} [options.sortAttributes=false]
20
- */
21
- constructor(xml: string, options?: {
22
- ignoreUndefinedEntities?: boolean | undefined;
23
- preserveCdata?: boolean | undefined;
24
- preserveComments?: boolean | undefined;
25
- resolveUndefinedEntity?: ((entity: string) => string | null) | undefined;
26
- sortAttributes?: boolean | undefined;
27
- } | undefined);
28
- /** @type {XmlDocument} */
29
- document: XmlDocument;
30
- /** @type {XmlDocument|XmlElement} */
31
- currentNode: XmlDocument | XmlElement;
32
- options: {
33
- ignoreUndefinedEntities?: boolean | undefined;
34
- preserveCdata?: boolean | undefined;
35
- preserveComments?: boolean | undefined;
36
- resolveUndefinedEntity?: ((entity: string) => string | null) | undefined;
37
- sortAttributes?: boolean | undefined;
38
- };
39
- scanner: StringScanner;
40
- /**
41
- Adds the given `XmlNode` as a child of `this.currentNode`.
42
-
43
- @param {XmlNode} node
44
- */
45
- addNode(node: XmlNode): void;
46
- /**
47
- Adds the given _text_ to the document, either by appending it to a preceding
48
- `XmlText` node (if possible) or by creating a new `XmlText` node.
49
-
50
- @param {string} text
51
- */
52
- addText(text: string): void;
53
- /**
54
- Consumes an `AttValue` (attribute value) if possible.
55
-
56
- @returns {string|false}
57
- Contents of the `AttValue` minus quotes, or `false` if nothing was consumed.
58
- An empty string indicates that an `AttValue` was consumed but was empty.
59
-
60
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
61
- */
62
- consumeAttributeValue(): string | false;
63
- /**
64
- Consumes a CDATA section if possible.
65
-
66
- @returns {boolean}
67
- Whether a CDATA section was consumed.
68
-
69
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect
70
- */
71
- consumeCdataSection(): boolean;
72
- /**
73
- Consumes character data if possible.
74
-
75
- @returns {boolean}
76
- Whether character data was consumed.
77
-
78
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata
79
- */
80
- consumeCharData(): boolean;
81
- /**
82
- Consumes a comment if possible.
83
-
84
- @returns {boolean}
85
- Whether a comment was consumed.
86
-
87
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment
88
- */
89
- consumeComment(): boolean;
90
- /**
91
- Consumes a reference in a content context if possible.
92
-
93
- This differs from `consumeReference()` in that a consumed reference will be
94
- added to the document as a text node instead of returned.
95
-
96
- @returns {boolean}
97
- Whether a reference was consumed.
98
-
99
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc
100
- */
101
- consumeContentReference(): boolean;
102
- /**
103
- Consumes a doctype declaration if possible.
104
-
105
- This is a loose implementation since doctype declarations are currently
106
- discarded without further parsing.
107
-
108
- @returns {boolean}
109
- Whether a doctype declaration was consumed.
110
-
111
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd
112
- */
113
- consumeDoctypeDeclaration(): boolean;
114
- /**
115
- Consumes an element if possible.
116
-
117
- @returns {boolean}
118
- Whether an element was consumed.
119
-
120
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element
121
- */
122
- consumeElement(): boolean;
123
- /**
124
- Consumes an `Eq` production if possible.
125
-
126
- @returns {boolean}
127
- Whether an `Eq` production was consumed.
128
-
129
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq
130
- */
131
- consumeEqual(): boolean;
132
- /**
133
- Consumes `Misc` content if possible.
134
-
135
- @returns {boolean}
136
- Whether anything was consumed.
137
-
138
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc
139
- */
140
- consumeMisc(): boolean;
141
- /**
142
- Consumes one or more `Name` characters if possible.
143
-
144
- @returns {string}
145
- `Name` characters, or an empty string if none were consumed.
146
-
147
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name
148
- */
149
- consumeName(): string;
150
- /**
151
- Consumes a processing instruction if possible.
152
-
153
- @returns {boolean}
154
- Whether a processing instruction was consumed.
155
-
156
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi
157
- */
158
- consumeProcessingInstruction(): boolean;
159
- /**
160
- Consumes a prolog if possible.
161
-
162
- @returns {boolean}
163
- Whether a prolog was consumed.
164
-
165
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd
166
- */
167
- consumeProlog(): boolean;
168
- /**
169
- Consumes a reference if possible.
170
-
171
- This differs from `consumeContentReference()` in that a consumed reference
172
- will be returned rather than added to the document.
173
-
174
- @returns {string|false}
175
- Parsed reference value, or `false` if nothing was consumed (to distinguish
176
- from a reference that resolves to an empty string).
177
-
178
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference
179
- */
180
- consumeReference(): string | false;
181
- /**
182
- Consumes a `SystemLiteral` if possible.
183
-
184
- A `SystemLiteral` is similar to an attribute value, but allows the characters
185
- `<` and `&` and doesn't replace references.
186
-
187
- @returns {string|false}
188
- Value of the `SystemLiteral` minus quotes, or `false` if nothing was
189
- consumed. An empty string indicates that a `SystemLiteral` was consumed but
190
- was empty.
191
-
192
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral
193
- */
194
- consumeSystemLiteral(): string | false;
195
- /**
196
- Consumes one or more whitespace characters if possible.
197
-
198
- @returns {boolean}
199
- Whether any whitespace characters were consumed.
200
-
201
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
202
- */
203
- consumeWhitespace(): boolean;
204
- /**
205
- Consumes an XML declaration if possible.
206
-
207
- @returns {boolean}
208
- Whether an XML declaration was consumed.
209
-
210
- @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl
211
- */
212
- consumeXmlDeclaration(): boolean;
213
- /**
214
- Throws an error at the current scanner position.
215
-
216
- @param {string} message
217
- */
218
- error(message: string): void;
219
- /**
220
- Throws an invalid character error if any character in the given _string_ isn't
221
- a valid XML character.
222
-
223
- @param {string} string
224
- */
225
- validateChars(string: string): void;
226
- }
227
- declare namespace Parser {
228
- export { XmlNode };
229
- }
230
- import XmlDocument = require("./XmlDocument");
231
- import XmlElement = require("./XmlElement");
232
- import StringScanner = require("./StringScanner");
233
- type XmlNode = import("./XmlNode");
234
- //# sourceMappingURL=Parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/lib/Parser.js"],"names":[],"mappings":";AAaA;;;;EAIE;AACF;IACE;;;;;;;;;;;;MAYE;IACF,iBAZQ,MAAM;;;;2CASK,MAAM,KAAK,MAAM;;mBAwBnC;IApBC,0BAA0B;IAC1B,UADW,WAAW,CACW;IAEjC,qCAAqC;IACrC,aADW,WAAW,GAAC,UAAU,CACD;IAEhC;;;;2CAViB,MAAM,KAAK,MAAM;;MAUZ;IACtB,uBAAyD;IAe3D;;;;MAIE;IACF,cAFQ,OAAO,QAOd;IAED;;;;;MAKE;IACF,cAFQ,MAAM,QAiBb;IAED;;;;;;;;MAQE;IACF,yBANU,MAAM,GAAC,KAAK,CA2DrB;IAED;;;;;;;MAOE;IACF,uBALU,OAAO,CA0BhB;IAED;;;;;;;MAOE;IACF,mBALU,OAAO,CAqBhB;IAED;;;;;;;MAOE;IACF,kBALU,OAAO,CA4BhB;IAED;;;;;;;;;;MAUE;IACF,2BALU,OAAO,CAchB;IAED;;;;;;;;;;MAUE;IACF,6BALU,OAAO,CAyBhB;IAED;;;;;;;MAOE;IACF,kBALU,OAAO,CA4GhB;IAED;;;;;;;MAOE;IACF,gBALU,OAAO,CAchB;IAED;;;;;;;MAOE;IACF,eALU,OAAO,CAShB;IAED;;;;;;;MAOE;IACF,eALU,MAAM,CASf;IAED;;;;;;;MAOE;IACF,gCALU,OAAO,CA0ChB;IAED;;;;;;;MAOE;IACF,iBALU,OAAO,CAkBhB;IAED;;;;;;;;;;;MAWE;IACF,oBANU,MAAM,GAAC,KAAK,CA0ErB;IAED;;;;;;;;;;;;MAYE;IACF,wBAPU,MAAM,GAAC,KAAK,CAuBrB;IAED;;;;;;;MAOE;IACF,qBALU,OAAO,CAOhB;IAED;;;;;;;MAOE;IACF,yBALU,OAAO,CAqDhB;IAED;;;;MAIE;IACF,eAFQ,MAAM,QAuDb;IAED;;;;;MAKE;IACF,sBAFQ,MAAM,QAab;CACF"}