@xmldom/xmldom 0.8.10 → 0.9.0-beta.10

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/index.d.ts CHANGED
@@ -1,43 +1,393 @@
1
1
  /// <reference lib="dom" />
2
2
 
3
- declare module "@xmldom/xmldom" {
4
- var DOMParser: DOMParserStatic;
5
- var XMLSerializer: XMLSerializerStatic;
6
- var DOMImplementation: DOMImplementationStatic;
7
-
8
- interface DOMImplementationStatic {
9
- new(): DOMImplementation;
10
- }
11
-
12
- interface DOMParserStatic {
13
- new (): DOMParser;
14
- new (options: Options): DOMParser;
15
- }
16
-
17
- interface XMLSerializerStatic {
18
- new (): XMLSerializer;
19
- }
20
-
21
- interface DOMParser {
22
- parseFromString(xmlsource: string, mimeType?: string): Document;
23
- }
24
-
25
- interface XMLSerializer {
26
- serializeToString(node: Node): string;
27
- }
28
-
29
- interface Options {
30
- locator?: any;
31
- errorHandler?: ErrorHandlerFunction | ErrorHandlerObject | undefined;
32
- }
33
-
34
- interface ErrorHandlerFunction {
35
- (level: string, msg: any): any;
36
- }
37
-
38
- interface ErrorHandlerObject {
39
- warning?: ((msg: any) => any) | undefined;
40
- error?: ((msg: any) => any) | undefined;
41
- fatalError?: ((msg: any) => any) | undefined;
42
- }
3
+ declare module '@xmldom/xmldom' {
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;
28
+
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',
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',
109
+
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);
136
+ }
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;
230
+ interface XMLSerializerStatic {
231
+ new (): XMLSerializer;
232
+ }
233
+ // END ./lib/dom.js
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
+ */
263
+ interface DOMParser {
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;
289
+ }
290
+
291
+ interface XMLSerializer {
292
+ serializeToString(node: Node, nodeFilter?: (node: Node) => boolean): string;
293
+ }
294
+
295
+ interface DOMParserOptions {
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>>;
370
+ }
371
+
372
+ interface ErrorHandlerFunction {
373
+ (level: 'warn' | 'error' | 'fatalError', msg: string, context: any): void;
374
+ }
375
+
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
43
393
  }
package/lib/.eslintrc.yml CHANGED
@@ -1,2 +1,3 @@
1
1
  extends:
2
2
  - 'plugin:es5/no-es2015'
3
+ - 'plugin:node/recommended'