@xmldom/xmldom 0.9.0-beta.8 → 0.9.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/CHANGELOG.md CHANGED
@@ -4,11 +4,124 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.9.0](https://github.com/xmldom/xmldom/compare/0.9.0-beta.11...0.9.0)
8
+
9
+ - [Discussion](https://github.com/xmldom/xmldom/discussions/435)
10
+ - [Summary on dev.to](https://dev.to/karfau/release-090-of-xmldomxmldom-4106)
11
+
12
+ ### Features
13
+
14
+ - feat: expose all DOM level 2 element prototypes [`#637`](https://github.com/xmldom/xmldom/pull/637) / [`#40`](https://github.com/xmldom/xmldom/issues/40)
15
+ - feat: add iterator function to NodeList and NamedNodeMap [`#634`](https://github.com/xmldom/xmldom/pull/634) / [`#633`](https://github.com/xmldom/xmldom/issues/633)
16
+
17
+ ### Fixed
18
+
19
+ - parse empty/whitspace only doctype internal subset [`#692`](https://github.com/xmldom/xmldom/pull/692)
20
+ - avoid prototype clash in namespace prefix [`#554`](https://github.com/xmldom/xmldom/pull/554)
21
+ - report fatalError when doctype is inside elements [`#550`](https://github.com/xmldom/xmldom/pull/550)
22
+
23
+ ### Other
24
+
25
+ - test: add fuzz target and regression tests [`#556`](https://github.com/xmldom/xmldom/pull/556)
26
+ - chore: improve .gitignore and provide .envrc.template [`#697`](https://github.com/xmldom/xmldom/pull/697)
27
+ - chore: Apply security best practices [`#546`](https://github.com/xmldom/xmldom/pull/546)
28
+ - ci: check test coverage in PRs [`#524`](https://github.com/xmldom/xmldom/pull/524)
29
+ - docs: add missing commas to readme [`#566`](https://github.com/xmldom/xmldom/pull/566)
30
+ - docs: click to copy install command in readme [`#644`](https://github.com/xmldom/xmldom/pull/644)
31
+ - docs: enhance jsdoc comments [`#511`](https://github.com/xmldom/xmldom/pull/511)
32
+
33
+ Thank you, [@kboshold](https://github.com/kboshold), [@edi9999](https://github.com/edi9999), [@apupier](https://github.com/apupier),
34
+ [@shunkica](https://github.com/shunkica), [@homer0](https://github.com/homer0), [@jhauga](https://github.com/jhauga),
35
+ [@UdayKharatmol](https://github.com/UdayKharatmol), for your contributions
36
+
37
+
38
+ ## [0.9.0-beta.11](https://github.com/xmldom/xmldom/compare/0.9.0-beta.10...0.9.0-beta.11)
39
+
40
+ ### Fixed
41
+
42
+ - report more non well-formed cases [`#519`](https://github.com/xmldom/xmldom/pull/519) / [`#45`](https://github.com/xmldom/xmldom/issues/45) / [`#125`](https://github.com/xmldom/xmldom/issues/125) / [`#467`](https://github.com/xmldom/xmldom/issues/467)
43
+ BREAKING-CHANGE: Reports more not well-formed documents as fatalError
44
+ and drop broken support for optional and unclosed tags in HTML.
45
+
46
+ ### Other
47
+
48
+ - Translate/drop non English comments [`#518`](https://github.com/xmldom/xmldom/pull/518)
49
+ - use node v16 for development [`#517`](https://github.com/xmldom/xmldom/pull/517)
50
+
51
+ Thank you, [@brodybits](https://github.com/brodybits), [@cbettinger](https://github.com/cbettinger), [@josecarlosrx](https://github.com/josecarlosrx), for your contributions
52
+
53
+
54
+ ## [0.9.0-beta.10](https://github.com/xmldom/xmldom/compare/0.9.0-beta.9...0.9.0-beta.10)
55
+
56
+ ### Fixed
57
+
58
+ - dom: prevent iteration over deleted items [`#514`](https://github.com/xmldom/xmldom/pull/514)/ [`#499`](https://github.com/xmldom/xmldom/issues/499)
59
+
60
+ ### Chore
61
+
62
+ - use prettier plugin for jsdoc [`#513`](https://github.com/xmldom/xmldom/pull/513)
63
+
64
+ Thank you, [@qtow](https://github.com/qtow), [@shunkica](https://github.com/shunkica), [@homer0](https://github.com/homer0), for your contributions
65
+
66
+
67
+ ## [0.8.10](https://github.com/xmldom/xmldom/compare/0.8.9...0.8.10)
68
+
69
+ ### Fixed
70
+
71
+ - dom: prevent iteration over deleted items [`#514`](https://github.com/xmldom/xmldom/pull/514)/ [`#499`](https://github.com/xmldom/xmldom/issues/499)
72
+
73
+ Thank you, [@qtow](https://github.com/qtow), for your contributions
74
+
75
+
76
+ ## [0.7.13](https://github.com/xmldom/xmldom/compare/0.7.12...0.7.13)
77
+
78
+ ### Fixed
79
+
80
+ - dom: prevent iteration over deleted items [`#514`](https://github.com/xmldom/xmldom/pull/514)/ [`#499`](https://github.com/xmldom/xmldom/issues/499)
81
+
82
+ Thank you, [@qtow](https://github.com/qtow), for your contributions
83
+
84
+
85
+ ## [0.9.0-beta.9](https://github.com/xmldom/xmldom/compare/0.9.0-beta.8...0.9.0-beta.9)
86
+
87
+ ### Fixed
88
+
89
+ - Set nodeName property in ProcessingInstruction [`#509`](https://github.com/xmldom/xmldom/pull/509) / [`#505`](https://github.com/xmldom/xmldom/issues/505)
90
+ - preserve DOCTYPE internal subset [`#498`](https://github.com/xmldom/xmldom/pull/498) / [`#497`](https://github.com/xmldom/xmldom/pull/497) / [`#117`](https://github.com/xmldom/xmldom/issues/117)\
91
+ BREAKING CHANGES: Many documents that were previously accepted by xmldom, esecially non well-formed ones are no longer accepted. Some issues that were formerly reported as errors are now a fatalError.
92
+ - DOMParser: Align parseFromString errors with specs [`#454`](https://github.com/xmldom/xmldom/pull/454)
93
+
94
+ ### Chore
95
+
96
+ - stop running mutation tests using stryker [`#496`](https://github.com/xmldom/xmldom/pull/496)
97
+ - make `toErrorSnapshot` windows compatible [`#503`](https://github.com/xmldom/xmldom/pull/503)
98
+
99
+ Thank you, [@cjbarth](https://github.com/cjbarth), [@shunkica](https://github.com/shunkica), [@pmahend1](https://github.com/pmahend1), [@niklasl](https://github.com/niklasl), for your contributions
100
+
101
+
102
+ ## [0.8.9](https://github.com/xmldom/xmldom/compare/0.8.8...0.8.9)
103
+
104
+ ### Fixed
105
+
106
+ - Set nodeName property in ProcessingInstruction [`#509`](https://github.com/xmldom/xmldom/pull/509) / [`#505`](https://github.com/xmldom/xmldom/issues/505)
107
+
108
+ Thank you, [@cjbarth](https://github.com/cjbarth), for your contributions
109
+
110
+
111
+ ## [0.7.12](https://github.com/xmldom/xmldom/compare/0.7.11...0.7.12)
112
+
113
+ ### Fixed
114
+
115
+ - Set nodeName property in ProcessingInstruction [`#509`](https://github.com/xmldom/xmldom/pull/509) / [`#505`](https://github.com/xmldom/xmldom/issues/505)
116
+
117
+ Thank you, [@cjbarth](https://github.com/cjbarth), for your contributions
118
+
119
+
7
120
  ## [0.9.0-beta.8](https://github.com/xmldom/xmldom/compare/0.9.0-beta.7...0.9.0-beta.8)
8
121
 
9
122
  ### Fixed
10
123
 
11
- - fix: Throw DOMException when calling removeChild with invalid parameter [`#494`](https://github.com/xmldom/xmldom/pull/494) / [`#135`](https://github.com/xmldom/xmldom/issues/135)
124
+ - Throw DOMException when calling removeChild with invalid parameter [`#494`](https://github.com/xmldom/xmldom/pull/494) / [`#135`](https://github.com/xmldom/xmldom/issues/135)
12
125
 
13
126
  BREAKING CHANGE: Previously it was possible (but not documented) to call `Node.removeChild` with any node in the tree,
14
127
  and with certain exceptions, it would work. This is no longer the case: calling `Node.removeChild` with an argument that is not a direct child of the node that it is called from, will throw a NotFoundError DOMException, as it is described by the specs.
package/index.d.ts CHANGED
@@ -1,45 +1,393 @@
1
1
  /// <reference lib="dom" />
2
2
 
3
3
  declare module '@xmldom/xmldom' {
4
- var DOMParser: DOMParserStatic
5
- var XMLSerializer: XMLSerializerStatic
6
- var DOMImplementation: DOMImplementationStatic
4
+ // START ./lib/conventions.js
5
+ /**
6
+ * Since xmldom can not rely on `Object.assign`,
7
+ * it uses/provides a simplified version that is sufficient for its needs.
8
+ *
9
+ * @throws {TypeError}
10
+ * If target is not an object.
11
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
12
+ * @see https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.assign
13
+ */
14
+ function assign<T, S>(target: T, source: S): T & S;
15
+ /**
16
+ * Only returns true if `value` matches MIME_TYPE.HTML, which indicates an HTML document.
17
+ *
18
+ * @see https://www.iana.org/assignments/media-types/text/html
19
+ * @see https://en.wikipedia.org/wiki/HTML
20
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString
21
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring
22
+ */
23
+ function isHtmlMimeType(mimeType: string): mimeType is MIME_TYPE.HTML;
24
+ /**
25
+ * Only returns true if `mimeType` is one of the allowed values for `DOMParser.parseFromString`.
26
+ */
27
+ function isValidMimeType(mimeType: string): mimeType is MIME_TYPE;
7
28
 
8
- interface DOMImplementationStatic {
9
- new (): DOMImplementation
29
+ /**
30
+ * All mime types that are allowed as input to `DOMParser.parseFromString`
31
+ *
32
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString#Argument02
33
+ * MDN
34
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparsersupportedtype
35
+ * WHATWG HTML Spec
36
+ * @see {@link DOMParser.prototype.parseFromString}
37
+ */
38
+ enum MIME_TYPE {
39
+ /**
40
+ * `text/html`, the only mime type that triggers treating an XML document as HTML.
41
+ *
42
+ * @see https://www.iana.org/assignments/media-types/text/html IANA MimeType registration
43
+ * @see https://en.wikipedia.org/wiki/HTML Wikipedia
44
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString MDN
45
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring
46
+ * WHATWG HTML Spec
47
+ */
48
+ HTML = 'text/html',
49
+ /**
50
+ * `application/xml`, the standard mime type for XML documents.
51
+ *
52
+ * @see https://www.iana.org/assignments/media-types/application/xml IANA MimeType
53
+ * registration
54
+ * @see https://tools.ietf.org/html/rfc7303#section-9.1 RFC 7303
55
+ * @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
56
+ */
57
+ XML_APPLICATION = 'application/xml',
58
+ /**
59
+ * `text/html`, an alias for `application/xml`.
60
+ *
61
+ * @see https://tools.ietf.org/html/rfc7303#section-9.2 RFC 7303
62
+ * @see https://www.iana.org/assignments/media-types/text/xml IANA MimeType registration
63
+ * @see https://en.wikipedia.org/wiki/XML_and_MIME Wikipedia
64
+ */
65
+ XML_TEXT = 'text/xml',
66
+ /**
67
+ * `application/xhtml+xml`, indicates an XML document that has the default HTML namespace,
68
+ * but is parsed as an XML document.
69
+ *
70
+ * @see https://www.iana.org/assignments/media-types/application/xhtml+xml IANA MimeType
71
+ * registration
72
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument WHATWG DOM Spec
73
+ * @see https://en.wikipedia.org/wiki/XHTML Wikipedia
74
+ */
75
+ XML_XHTML_APPLICATION = 'application/xhtml+xml',
76
+ /**
77
+ * `image/svg+xml`,
78
+ *
79
+ * @see https://www.iana.org/assignments/media-types/image/svg+xml IANA MimeType registration
80
+ * @see https://www.w3.org/TR/SVG11/ W3C SVG 1.1
81
+ * @see https://en.wikipedia.org/wiki/Scalable_Vector_Graphics Wikipedia
82
+ */
83
+ XML_SVG_IMAGE = 'image/svg+xml',
10
84
  }
85
+ /**
86
+ * Namespaces that are used in xmldom.
87
+ *
88
+ * @see http://www.w3.org/TR/REC-xml-names
89
+ */
90
+ enum NAMESPACE {
91
+ /**
92
+ * The XHTML namespace.
93
+ *
94
+ * @see http://www.w3.org/1999/xhtml
95
+ */
96
+ HTML = 'http://www.w3.org/1999/xhtml',
97
+ /**
98
+ * The SVG namespace.
99
+ *
100
+ * @see http://www.w3.org/2000/svg
101
+ */
102
+ SVG = 'http://www.w3.org/2000/svg',
103
+ /**
104
+ * The `xml:` namespace.
105
+ *
106
+ * @see http://www.w3.org/XML/1998/namespace
107
+ */
108
+ XML = 'http://www.w3.org/XML/1998/namespace',
11
109
 
12
- interface DOMParserStatic {
13
- new (): DOMParser
14
- new (options: DOMParserOptions): DOMParser
110
+ /**
111
+ * The `xmlns:` namespace.
112
+ *
113
+ * @see https://www.w3.org/2000/xmlns/
114
+ */
115
+ XMLNS = 'http://www.w3.org/2000/xmlns/',
116
+ }
117
+
118
+ /**
119
+ * A custom error that will not be caught by XMLReader aka the SAX parser.
120
+ */
121
+ class ParseError extends Error {
122
+ constructor(message: string, locator?: any);
123
+ }
124
+ // END ./lib/conventions.js
125
+
126
+ // START ./lib/dom.js
127
+ /**
128
+ * The error class for errors reported by the DOM API.
129
+ *
130
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException
131
+ * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
132
+ * @see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html
133
+ */
134
+ class DOMException extends Error {
135
+ constructor(code: number, message: string);
15
136
  }
16
137
 
138
+ interface DOMImplementation {
139
+ /**
140
+ * The DOMImplementation interface represents an object providing methods which are not
141
+ * dependent on any particular document.
142
+ * Such an object is returned by the `Document.implementation` property.
143
+ *
144
+ * __The individual methods describe the differences compared to the specs.__.
145
+ *
146
+ * @class
147
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation MDN
148
+ * @see https://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-102161490 DOM Level 1
149
+ * Core (Initial)
150
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-102161490 DOM Level 2 Core
151
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-102161490 DOM Level 3 Core
152
+ * @see https://dom.spec.whatwg.org/#domimplementation DOM Living Standard
153
+ */
154
+ new (): DOMImplementation;
155
+
156
+ /**
157
+ * Creates an XML Document object of the specified type with its document element.
158
+ *
159
+ * __It behaves slightly different from the description in the living standard__:
160
+ * - There is no interface/class `XMLDocument`, it returns a `Document` instance (with it's
161
+ * `type` set to `'xml'`).
162
+ * - `encoding`, `mode`, `origin`, `url` fields are currently not declared.
163
+ *
164
+ * @returns {Document} The XML document.
165
+ * @see {@link DOMImplementation.createHTMLDocument}
166
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocument MDN
167
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument DOM
168
+ * Level 2 Core (initial)
169
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocument DOM Level 2 Core
170
+ */
171
+ createDocument(
172
+ namespaceURI: string | null,
173
+ qualifiedName: string,
174
+ doctype?: DocumentType | null
175
+ ): Document;
176
+
177
+ /**
178
+ * Returns a doctype, with the given `qualifiedName`, `publicId`, and `systemId`.
179
+ *
180
+ * __This behavior is slightly different from the in the specs__:
181
+ * - `encoding`, `mode`, `origin`, `url` fields are currently not declared.
182
+ *
183
+ * @returns {DocumentType} which can either be used with `DOMImplementation.createDocument`
184
+ * upon document creation or can be put into the document via methods
185
+ * like `Node.insertBefore()` or `Node.replaceChild()`
186
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createDocumentType
187
+ * MDN
188
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocType DOM
189
+ * Level 2 Core
190
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype DOM Living
191
+ * Standard
192
+ */
193
+ createDocumentType(
194
+ qualifiedName: string,
195
+ publicId?: string,
196
+ systemId?: string
197
+ ): DocumentType;
198
+
199
+ /**
200
+ * Returns an HTML document, that might already have a basic DOM structure.
201
+ *
202
+ * __It behaves slightly different from the description in the living standard__:
203
+ * - If the first argument is `false` no initial nodes are added (steps 3-7 in the specs are
204
+ * omitted)
205
+ * - `encoding`, `mode`, `origin`, `url` fields are currently not declared.
206
+ *
207
+ * @see {@link DOMImplementation.createDocument}
208
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
209
+ * @see https://dom.spec.whatwg.org/#html-document
210
+ */
211
+ createHTMLDocument(title?: string | false): Document;
212
+
213
+ /**
214
+ * The DOMImplementation.hasFeature() method returns a Boolean flag indicating if a given
215
+ * feature is supported. The different implementations fairly diverged in what kind of
216
+ * features were reported. The latest version of the spec settled to force this method to
217
+ * always return true, where the functionality was accurate and in use.
218
+ *
219
+ * @deprecated
220
+ * It is deprecated and modern browsers return true in all cases.
221
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/hasFeature MDN
222
+ * @see https://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-5CED94D7 DOM Level 1
223
+ * Core
224
+ * @see https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature DOM Living Standard
225
+ */
226
+ hasFeature(feature: string, version?: string): true;
227
+ }
228
+
229
+ var XMLSerializer: XMLSerializerStatic;
17
230
  interface XMLSerializerStatic {
18
- new (): XMLSerializer
231
+ new (): XMLSerializer;
19
232
  }
233
+ // END ./lib/dom.js
20
234
 
235
+ // START ./lib/dom-parser.js
236
+ var DOMParser: DOMParserStatic;
237
+ interface DOMParserStatic {
238
+ /**
239
+ * The DOMParser interface provides the ability to parse XML or HTML source code from a
240
+ * string into a DOM `Document`.
241
+ *
242
+ * _xmldom is different from the spec in that it allows an `options` parameter,
243
+ * to control the behavior._.
244
+ *
245
+ * @class
246
+ * @param {DOMParserOptions} [options]
247
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
248
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
249
+ */
250
+ new (options?: DOMParserOptions): DOMParser;
251
+ }
252
+
253
+ /**
254
+ * The DOMParser interface provides the ability to parse XML or HTML source code from a string
255
+ * into a DOM `Document`.
256
+ *
257
+ * _xmldom is different from the spec in that it allows an `options` parameter,
258
+ * to control the behavior._.
259
+ *
260
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
261
+ * @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
262
+ */
21
263
  interface DOMParser {
22
- parseFromString(source: string, mimeType?: string): Document | undefined
264
+ /**
265
+ * Parses `source` using the options in the way configured by the `DOMParserOptions` of
266
+ * `this`
267
+ * `DOMParser`. If `mimeType` is `text/html` an HTML `Document` is created, otherwise an XML
268
+ * `Document` is created.
269
+ *
270
+ * __It behaves different from the description in the living standard__:
271
+ * - Uses the `options` passed to the `DOMParser` constructor to modify the behavior.
272
+ * - Any unexpected input is reported to `onError` with either a `warning`, `error` or
273
+ * `fatalError` level.
274
+ * - Any `fatalError` throws a `ParseError` which prevents further processing.
275
+ * - Any error thrown by `onError` is converted to a `ParseError` which prevents further
276
+ * processing - If no `Document` was created during parsing it is reported as a `fatalError`.
277
+ *
278
+ * @returns The `Document` node.
279
+ * @throws {ParseError}
280
+ * for any `fatalError` or anything that is thrown by `onError`
281
+ * @throws {TypeError} for any invalid `mimeType`
282
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString
283
+ * @see https://html.spec.whatwg.org/#dom-domparser-parsefromstring-dev
284
+ */
285
+ parseFromString(
286
+ source: string,
287
+ mimeType: MIME_TYPE = MIME_TYPE.XML_TEXT
288
+ ): Document;
23
289
  }
24
290
 
25
291
  interface XMLSerializer {
26
- serializeToString(node: Node): string
292
+ serializeToString(node: Node, nodeFilter?: (node: Node) => boolean): string;
27
293
  }
28
294
 
29
295
  interface DOMParserOptions {
30
- errorHandler?: ErrorHandlerFunction | ErrorHandlerObject
31
- locator?: boolean
32
- normalizeLineEndings?: (source: string) => string
33
- xmlns?: Record<string, string | null | undefined>
296
+ /**
297
+ * The method to use instead of `Object.assign` (defaults to `conventions.assign`),
298
+ * which is used to copy values from the options before they are used for parsing.
299
+ *
300
+ * @private
301
+ * @see {@link conventions.assign}
302
+ */
303
+ readonly assign?: typeof Object.assign;
304
+ /**
305
+ * For internal testing: The class for creating an instance for handling events from the SAX
306
+ * parser.
307
+ * *****Warning: By configuring a faulty implementation,
308
+ * the specified behavior can completely be broken*****.
309
+ *
310
+ * @private
311
+ */
312
+ readonly domHandler?: unknown;
313
+
314
+ /**
315
+ * DEPRECATED: Use `onError` instead!
316
+ *
317
+ * For backwards compatibility:
318
+ * If it is a function, it will be used as a value for `onError`,
319
+ * but it receives different argument types than before 0.9.0.
320
+ *
321
+ * @deprecated
322
+ * @throws {TypeError} If it is an object.
323
+ */
324
+ readonly errorHandler?: ErrorHandlerFunction;
325
+
326
+ /**
327
+ * Configures if the nodes created during parsing
328
+ * will have a `lineNumber` and a `columnNumber` attribute
329
+ * describing their location in the XML string.
330
+ * Default is true.
331
+ */
332
+ readonly locator?: boolean;
333
+
334
+ /**
335
+ * used to replace line endings before parsing, defaults to `normalizeLineEndings`,
336
+ * which normalizes line endings according to <https://www.w3.org/TR/xml11/#sec-line-ends>.
337
+ */
338
+ readonly normalizeLineEndings?: (source: string) => string;
339
+ /**
340
+ * A function that is invoked for every error that occurs during parsing.
341
+ *
342
+ * If it is not provided, all errors are reported to `console.error`
343
+ * and only `fatalError`s are thrown as a `ParseError`,
344
+ * which prevents any further processing.
345
+ * If the provided method throws, a `ParserError` is thrown,
346
+ * which prevents any further processing.
347
+ *
348
+ * Be aware that many `warning`s are considered an error that prevents further processing in
349
+ * most implementations.
350
+ *
351
+ * @param level
352
+ * The error level as reported by the SAXParser.
353
+ * @param message
354
+ * The error message.
355
+ * @param context
356
+ * The DOMHandler instance used for parsing.
357
+ * @see {@link onErrorStopParsing}
358
+ * @see {@link onWarningStopParsing}
359
+ */
360
+ readonly onError?: ErrorHandlerFunction;
361
+
362
+ /**
363
+ * The XML namespaces that should be assumed when parsing.
364
+ * The default namespace can be provided by the key that is the empty string.
365
+ * When the `mimeType` for HTML, XHTML or SVG are passed to `parseFromString`,
366
+ * the default namespace that will be used,
367
+ * will be overridden according to the specification.
368
+ */
369
+ readonly xmlns?: Readonly<Record<string, string | null | undefined>>;
34
370
  }
35
371
 
36
372
  interface ErrorHandlerFunction {
37
- (level: 'warn' | 'error' | 'fatalError', msg: string): void
373
+ (level: 'warn' | 'error' | 'fatalError', msg: string, context: any): void;
38
374
  }
39
375
 
40
- interface ErrorHandlerObject {
41
- warning?: (msg: string) => void
42
- error?: (msg: string) => void
43
- fatalError?: (msg: string) => void
44
- }
376
+ /**
377
+ * A method that prevents any further parsing when an `error`
378
+ * with level `error` is reported during parsing.
379
+ *
380
+ * @see {@link DOMParserOptions.onError}
381
+ * @see {@link onWarningStopParsing}
382
+ */
383
+ function onErrorStopParsing(): void | never;
384
+ /**
385
+ * A method that prevents any further parsing when an `error`
386
+ * with any level is reported during parsing.
387
+ *
388
+ * @see {@link DOMParserOptions.onError}
389
+ * @see {@link onErrorStopParsing}
390
+ */
391
+ function onWarningStopParsing(): never;
392
+ // END ./lib/dom-parser.js
45
393
  }
package/lib/.eslintrc.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  extends:
2
2
  - 'plugin:es5/no-es2015'
3
- - 'plugin:node/recommended'
3
+ - 'plugin:n/recommended'