parse5 2.2.2 → 3.0.2

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.
@@ -1,578 +1,209 @@
1
- 'use strict';
2
-
3
- /**
4
- * @typedef {Object} TreeAdapter
5
- */
6
-
7
- //Node construction
8
-
9
- /**
10
- * Creates a document node.
11
- *
12
- * @function createDocument
13
- * @memberof TreeAdapter
14
- *
15
- * @returns {ASTNode<Document>} document
16
- *
17
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L19|default implementation.}
18
- */
19
- exports.createDocument = function () {
20
- return {
21
- nodeName: '#document',
22
- quirksMode: false,
23
- childNodes: []
24
- };
25
- };
26
-
27
- /**
28
- * Creates a document fragment node.
29
- *
30
- * @function createDocumentFragment
31
- * @memberof TreeAdapter
32
- *
33
- * @returns {ASTNode<DocumentFragment>} fragment
34
- *
35
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L37|default implementation.}
36
- */
37
- exports.createDocumentFragment = function () {
38
- return {
39
- nodeName: '#document-fragment',
40
- quirksMode: false,
41
- childNodes: []
42
- };
43
- };
44
-
45
-
46
- /**
47
- * Creates an element node.
48
- *
49
- * @function createElement
50
- * @memberof TreeAdapter
51
- *
52
- * @param {String} tagName - Tag name of the element.
53
- * @param {String} namespaceURI - Namespace of the element.
54
- * @param {Array} attrs - Attribute name-value pair array.
55
- * Foreign attributes may contain `namespace` and `prefix` fields as well.
56
- *
57
- * @returns {ASTNode<Element>} element
58
- *
59
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L61|default implementation.}
60
- */
61
- exports.createElement = function (tagName, namespaceURI, attrs) {
62
- return {
63
- nodeName: tagName,
64
- tagName: tagName,
65
- attrs: attrs,
66
- namespaceURI: namespaceURI,
67
- childNodes: [],
68
- parentNode: null
69
- };
70
- };
71
-
72
-
73
- /**
74
- * Creates a comment node.
75
- *
76
- * @function createCommentNode
77
- * @memberof TreeAdapter
78
- *
79
- * @param {String} data - Comment text.
80
- *
81
- * @returns {ASTNode<CommentNode>} comment
82
- *
83
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L85|default implementation.}
84
- */
85
- exports.createCommentNode = function (data) {
86
- return {
87
- nodeName: '#comment',
88
- data: data,
89
- parentNode: null
90
- };
91
- };
92
-
93
- var createTextNode = function (value) {
94
- return {
95
- nodeName: '#text',
96
- value: value,
97
- parentNode: null
98
- };
99
- };
100
-
101
-
102
- //Tree mutation
103
- /**
104
- * Appends a child node to the given parent node.
105
- *
106
- * @function appendChild
107
- * @memberof TreeAdapter
108
- *
109
- * @param {ASTNode} parentNode - Parent node.
110
- * @param {ASTNode} newNode - Child node.
111
- *
112
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L114|default implementation.}
113
- */
114
- var appendChild = exports.appendChild = function (parentNode, newNode) {
115
- parentNode.childNodes.push(newNode);
116
- newNode.parentNode = parentNode;
117
- };
118
-
119
- /**
120
- * Inserts a child node to the given parent node before the given reference node.
121
- *
122
- * @function insertBefore
123
- * @memberof TreeAdapter
124
- *
125
- * @param {ASTNode} parentNode - Parent node.
126
- * @param {ASTNode} newNode - Child node.
127
- * @param {ASTNode} referenceNode - Reference node.
128
- *
129
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L131|default implementation.}
130
- */
131
- var insertBefore = exports.insertBefore = function (parentNode, newNode, referenceNode) {
132
- var insertionIdx = parentNode.childNodes.indexOf(referenceNode);
133
-
134
- parentNode.childNodes.splice(insertionIdx, 0, newNode);
135
- newNode.parentNode = parentNode;
136
- };
137
-
138
- /**
139
- * Sets the `<template>` element content element.
140
- *
141
- * @function setTemplateContent
142
- * @memberof TreeAdapter
143
- *
144
- * @param {ASTNode<TemplateElement>} templateElement - `<template>` element.
145
- * @param {ASTNode<DocumentFragment>} contentTemplate - Content element.
146
- *
147
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L149|default implementation.}
148
- */
149
- exports.setTemplateContent = function (templateElement, contentElement) {
150
- templateElement.content = contentElement;
151
- };
152
-
153
-
154
- /**
155
- * Returns the `<template>` element content element.
156
- *
157
- * @function getTemplateContent
158
- * @memberof TreeAdapter
159
- *
160
- * @param {ASTNode<TemplateElement>} templateElement - `<template>` element.
161
-
162
- * @returns {ASTNode<DocumentFragment>}
163
- *
164
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L166|default implementation.}
165
- */
166
- exports.getTemplateContent = function (templateElement) {
167
- return templateElement.content;
168
- };
169
-
170
- /**
171
- * Sets the document type. If the `document` already contains a document type node, the `name`, `publicId` and `systemId`
172
- * properties of this node will be updated with the provided values. Otherwise, creates a new document type node
173
- * with the given properties and inserts it into the `document`.
174
- *
175
- * @function setDocumentType
176
- * @memberof TreeAdapter
177
- *
178
- * @param {ASTNode<Document>} document - Document node.
179
- * @param {String} name - Document type name.
180
- * @param {String} publicId - Document type public identifier.
181
- * @param {String} systemId - Document type system identifier.
182
- *
183
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L185|default implementation.}
184
- */
185
- exports.setDocumentType = function (document, name, publicId, systemId) {
186
- var doctypeNode = null;
187
-
188
- for (var i = 0; i < document.childNodes.length; i++) {
189
- if (document.childNodes[i].nodeName === '#documentType') {
190
- doctypeNode = document.childNodes[i];
191
- break;
192
- }
193
- }
194
-
195
- if (doctypeNode) {
196
- doctypeNode.name = name;
197
- doctypeNode.publicId = publicId;
198
- doctypeNode.systemId = systemId;
199
- }
200
-
201
- else {
202
- appendChild(document, {
203
- nodeName: '#documentType',
204
- name: name,
205
- publicId: publicId,
206
- systemId: systemId
207
- });
208
- }
209
- };
210
-
211
- /**
212
- * Sets the document's quirks mode flag.
213
- *
214
- * @function setQuirksMode
215
- * @memberof TreeAdapter
216
- *
217
- * @param {ASTNode<Document>} document - Document node.
218
- *
219
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L221|default implementation.}
220
- */
221
- exports.setQuirksMode = function (document) {
222
- document.quirksMode = true;
223
- };
224
-
225
- /**
226
- * Determines if the document's quirks mode flag is set.
227
- *
228
- * @function isQuirksMode
229
- * @memberof TreeAdapter
230
- *
231
- * @param {ASTNode<Document>} document - Document node.
232
-
233
- * @returns {Boolean}
234
- *
235
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L237|default implementation.}
236
- */
237
- exports.isQuirksMode = function (document) {
238
- return document.quirksMode;
239
- };
240
-
241
- /**
242
- * Removes a node from its parent.
243
- *
244
- * @function detachNode
245
- * @memberof TreeAdapter
246
- *
247
- * @param {ASTNode} node - Node.
248
-
249
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L251|default implementation.}
250
- */
251
- exports.detachNode = function (node) {
252
- if (node.parentNode) {
253
- var idx = node.parentNode.childNodes.indexOf(node);
254
-
255
- node.parentNode.childNodes.splice(idx, 1);
256
- node.parentNode = null;
257
- }
258
- };
259
-
260
- /**
261
- * Inserts text into a node. If the last child of the node is a text node, the provided text will be appended to the
262
- * text node content. Otherwise, inserts a new text node with the given text.
263
- *
264
- *
265
- * @function insertText
266
- * @memberof TreeAdapter
267
- *
268
- * @param {ASTNode} parentNode - Node to insert text into.
269
- * @param {String} text - Text to insert.
270
-
271
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L273|default implementation.}
272
- */
273
- exports.insertText = function (parentNode, text) {
274
- if (parentNode.childNodes.length) {
275
- var prevNode = parentNode.childNodes[parentNode.childNodes.length - 1];
276
-
277
- if (prevNode.nodeName === '#text') {
278
- prevNode.value += text;
279
- return;
280
- }
281
- }
282
-
283
- appendChild(parentNode, createTextNode(text));
284
- };
285
-
286
- /**
287
- * Inserts text into a sibling node that goes before the reference node. If this sibling node is the text node,
288
- * the provided text will be appended to the text node content. Otherwise, inserts a new sibling text node with
289
- * the given text before the reference node.
290
- *
291
- *
292
- * @function insertTextBefore
293
- * @memberof TreeAdapter
294
- *
295
- * @param {ASTNode} parentNode - Node to insert text into.
296
- * @param {String} text - Text to insert.
297
- * @param {ASTNode} referenceNode - Node to insert text before.
298
- *
299
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L301|default implementation.}
300
- */
301
- exports.insertTextBefore = function (parentNode, text, referenceNode) {
302
- var prevNode = parentNode.childNodes[parentNode.childNodes.indexOf(referenceNode) - 1];
303
-
304
- if (prevNode && prevNode.nodeName === '#text')
305
- prevNode.value += text;
306
- else
307
- insertBefore(parentNode, createTextNode(text), referenceNode);
308
- };
309
-
310
- /**
311
- * Copies attributes to the given node. Only attributes that are not yet present in the node are copied.
312
- *
313
- * @function adoptAttributes
314
- * @memberof TreeAdapter
315
- *
316
- * @param {ASTNode} recipientNode - Node to copy attributes into.
317
- * @param {Array} attrs - Attributes to copy.
318
-
319
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L321|default implementation.}
320
- */
321
- exports.adoptAttributes = function (recipientNode, attrs) {
322
- var recipientAttrsMap = [];
323
-
324
- for (var i = 0; i < recipientNode.attrs.length; i++)
325
- recipientAttrsMap.push(recipientNode.attrs[i].name);
326
-
327
- for (var j = 0; j < attrs.length; j++) {
328
- if (recipientAttrsMap.indexOf(attrs[j].name) === -1)
329
- recipientNode.attrs.push(attrs[j]);
330
- }
331
- };
332
-
333
-
334
- //Tree traversing
335
-
336
- /**
337
- * Returns the first child of the given node.
338
- *
339
- * @function getFirstChild
340
- * @memberof TreeAdapter
341
- *
342
- * @param {ASTNode} node - Node.
343
- *
344
- * @returns {ASTNode} firstChild
345
- *
346
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L348|default implementation.}
347
- */
348
- exports.getFirstChild = function (node) {
349
- return node.childNodes[0];
350
- };
351
-
352
- /**
353
- * Returns the given node's children in an array.
354
- *
355
- * @function getChildNodes
356
- * @memberof TreeAdapter
357
- *
358
- * @param {ASTNode} node - Node.
359
- *
360
- * @returns {Array} children
361
- *
362
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L364|default implementation.}
363
- */
364
- exports.getChildNodes = function (node) {
365
- return node.childNodes;
366
- };
367
-
368
- /**
369
- * Returns the given node's parent.
370
- *
371
- * @function getParentNode
372
- * @memberof TreeAdapter
373
- *
374
- * @param {ASTNode} node - Node.
375
- *
376
- * @returns {ASTNode} parent
377
- *
378
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L380|default implementation.}
379
- */
380
- exports.getParentNode = function (node) {
381
- return node.parentNode;
382
- };
383
-
384
- /**
385
- * Returns the given node's attributes in an array, in the form of name-value pairs.
386
- * Foreign attributes may contain `namespace` and `prefix` fields as well.
387
- *
388
- * @function getAttrList
389
- * @memberof TreeAdapter
390
- *
391
- * @param {ASTNode} node - Node.
392
- *
393
- * @returns {Array} attributes
394
- *
395
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L397|default implementation.}
396
- */
397
- exports.getAttrList = function (node) {
398
- return node.attrs;
399
- };
400
-
401
- //Node data
402
-
403
- /**
404
- * Returns the given element's tag name.
405
- *
406
- * @function getTagName
407
- * @memberof TreeAdapter
408
- *
409
- * @param {ASTNode<Element>} element - Element.
410
- *
411
- * @returns {String} tagName
412
- *
413
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L415|default implementation.}
414
- */
415
- exports.getTagName = function (element) {
416
- return element.tagName;
417
- };
418
-
419
- /**
420
- * Returns the given element's namespace.
421
- *
422
- * @function getNamespaceURI
423
- * @memberof TreeAdapter
424
- *
425
- * @param {ASTNode<Element>} element - Element.
426
- *
427
- * @returns {String} namespaceURI
428
- *
429
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L431|default implementation.}
430
- */
431
- exports.getNamespaceURI = function (element) {
432
- return element.namespaceURI;
433
- };
434
-
435
- /**
436
- * Returns the given text node's content.
437
- *
438
- * @function getTextNodeContent
439
- * @memberof TreeAdapter
440
- *
441
- * @param {ASTNode<Text>} textNode - Text node.
442
- *
443
- * @returns {String} text
444
- *
445
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L447|default implementation.}
446
- */
447
- exports.getTextNodeContent = function (textNode) {
448
- return textNode.value;
449
- };
450
-
451
- /**
452
- * Returns the given comment node's content.
453
- *
454
- * @function getCommentNodeContent
455
- * @memberof TreeAdapter
456
- *
457
- * @param {ASTNode<Comment>} commentNode - Comment node.
458
- *
459
- * @returns {String} commentText
460
- *
461
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L463|default implementation.}
462
- */
463
- exports.getCommentNodeContent = function (commentNode) {
464
- return commentNode.data;
465
- };
466
-
467
- /**
468
- * Returns the given document type node's name.
469
- *
470
- * @function getDocumentTypeNodeName
471
- * @memberof TreeAdapter
472
- *
473
- * @param {ASTNode<DocumentType>} doctypeNode - Document type node.
474
- *
475
- * @returns {String} name
476
- *
477
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L479|default implementation.}
478
- */
479
- exports.getDocumentTypeNodeName = function (doctypeNode) {
480
- return doctypeNode.name;
481
- };
482
-
483
- /**
484
- * Returns the given document type node's public identifier.
485
- *
486
- * @function getDocumentTypeNodePublicId
487
- * @memberof TreeAdapter
488
- *
489
- * @param {ASTNode<DocumentType>} doctypeNode - Document type node.
490
- *
491
- * @returns {String} publicId
492
- *
493
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L495|default implementation.}
494
- */
495
- exports.getDocumentTypeNodePublicId = function (doctypeNode) {
496
- return doctypeNode.publicId;
497
- };
498
-
499
- /**
500
- * Returns the given document type node's system identifier.
501
- *
502
- * @function getDocumentTypeNodeSystemId
503
- * @memberof TreeAdapter
504
- *
505
- * @param {ASTNode<DocumentType>} doctypeNode - Document type node.
506
- *
507
- * @returns {String} systemId
508
- *
509
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L511|default implementation.}
510
- */
511
- exports.getDocumentTypeNodeSystemId = function (doctypeNode) {
512
- return doctypeNode.systemId;
513
- };
514
-
515
- //Node types
516
- /**
517
- * Determines if the given node is a text node.
518
- *
519
- * @function isTextNode
520
- * @memberof TreeAdapter
521
- *
522
- * @param {ASTNode} node - Node.
523
- *
524
- * @returns {Boolean}
525
- *
526
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L526|default implementation.}
527
- */
528
- exports.isTextNode = function (node) {
529
- return node.nodeName === '#text';
530
- };
531
-
532
- /**
533
- * Determines if the given node is a comment node.
534
- *
535
- * @function isCommentNode
536
- * @memberof TreeAdapter
537
- *
538
- * @param {ASTNode} node - Node.
539
- *
540
- * @returns {Boolean}
541
- *
542
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L544|default implementation.}
543
- */
544
- exports.isCommentNode = function (node) {
545
- return node.nodeName === '#comment';
546
- };
547
-
548
- /**
549
- * Determines if the given node is a document type node.
550
- *
551
- * @function isDocumentTypeNode
552
- * @memberof TreeAdapter
553
- *
554
- * @param {ASTNode} node - Node.
555
- *
556
- * @returns {Boolean}
557
- *
558
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L560|default implementation.}
559
- */
560
- exports.isDocumentTypeNode = function (node) {
561
- return node.nodeName === '#documentType';
562
- };
563
-
564
- /**
565
- * Determines if the given node is an element.
566
- *
567
- * @function isElementNode
568
- * @memberof TreeAdapter
569
- *
570
- * @param {ASTNode} node - Node.
571
- *
572
- * @returns {Boolean}
573
- *
574
- * @see {@link https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L576|default implementation.}
575
- */
576
- exports.isElementNode = function (node) {
577
- return !!node.tagName;
578
- };
1
+ 'use strict';
2
+
3
+ var DOCUMENT_MODE = require('../common/html').DOCUMENT_MODE;
4
+
5
+ //Node construction
6
+ exports.createDocument = function () {
7
+ return {
8
+ nodeName: '#document',
9
+ mode: DOCUMENT_MODE.NO_QUIRKS,
10
+ childNodes: []
11
+ };
12
+ };
13
+
14
+ exports.createDocumentFragment = function () {
15
+ return {
16
+ nodeName: '#document-fragment',
17
+ childNodes: []
18
+ };
19
+ };
20
+
21
+ exports.createElement = function (tagName, namespaceURI, attrs) {
22
+ return {
23
+ nodeName: tagName,
24
+ tagName: tagName,
25
+ attrs: attrs,
26
+ namespaceURI: namespaceURI,
27
+ childNodes: [],
28
+ parentNode: null
29
+ };
30
+ };
31
+
32
+ exports.createCommentNode = function (data) {
33
+ return {
34
+ nodeName: '#comment',
35
+ data: data,
36
+ parentNode: null
37
+ };
38
+ };
39
+
40
+ var createTextNode = function (value) {
41
+ return {
42
+ nodeName: '#text',
43
+ value: value,
44
+ parentNode: null
45
+ };
46
+ };
47
+
48
+
49
+ //Tree mutation
50
+ var appendChild = exports.appendChild = function (parentNode, newNode) {
51
+ parentNode.childNodes.push(newNode);
52
+ newNode.parentNode = parentNode;
53
+ };
54
+
55
+ var insertBefore = exports.insertBefore = function (parentNode, newNode, referenceNode) {
56
+ var insertionIdx = parentNode.childNodes.indexOf(referenceNode);
57
+
58
+ parentNode.childNodes.splice(insertionIdx, 0, newNode);
59
+ newNode.parentNode = parentNode;
60
+ };
61
+
62
+ exports.setTemplateContent = function (templateElement, contentElement) {
63
+ templateElement.content = contentElement;
64
+ };
65
+
66
+ exports.getTemplateContent = function (templateElement) {
67
+ return templateElement.content;
68
+ };
69
+
70
+ exports.setDocumentType = function (document, name, publicId, systemId) {
71
+ var doctypeNode = null;
72
+
73
+ for (var i = 0; i < document.childNodes.length; i++) {
74
+ if (document.childNodes[i].nodeName === '#documentType') {
75
+ doctypeNode = document.childNodes[i];
76
+ break;
77
+ }
78
+ }
79
+
80
+ if (doctypeNode) {
81
+ doctypeNode.name = name;
82
+ doctypeNode.publicId = publicId;
83
+ doctypeNode.systemId = systemId;
84
+ }
85
+
86
+ else {
87
+ appendChild(document, {
88
+ nodeName: '#documentType',
89
+ name: name,
90
+ publicId: publicId,
91
+ systemId: systemId
92
+ });
93
+ }
94
+ };
95
+
96
+ exports.setDocumentMode = function (document, mode) {
97
+ document.mode = mode;
98
+ };
99
+
100
+ exports.getDocumentMode = function (document) {
101
+ return document.mode;
102
+ };
103
+
104
+ exports.detachNode = function (node) {
105
+ if (node.parentNode) {
106
+ var idx = node.parentNode.childNodes.indexOf(node);
107
+
108
+ node.parentNode.childNodes.splice(idx, 1);
109
+ node.parentNode = null;
110
+ }
111
+ };
112
+
113
+ exports.insertText = function (parentNode, text) {
114
+ if (parentNode.childNodes.length) {
115
+ var prevNode = parentNode.childNodes[parentNode.childNodes.length - 1];
116
+
117
+ if (prevNode.nodeName === '#text') {
118
+ prevNode.value += text;
119
+ return;
120
+ }
121
+ }
122
+
123
+ appendChild(parentNode, createTextNode(text));
124
+ };
125
+
126
+ exports.insertTextBefore = function (parentNode, text, referenceNode) {
127
+ var prevNode = parentNode.childNodes[parentNode.childNodes.indexOf(referenceNode) - 1];
128
+
129
+ if (prevNode && prevNode.nodeName === '#text')
130
+ prevNode.value += text;
131
+ else
132
+ insertBefore(parentNode, createTextNode(text), referenceNode);
133
+ };
134
+
135
+ exports.adoptAttributes = function (recipient, attrs) {
136
+ var recipientAttrsMap = [];
137
+
138
+ for (var i = 0; i < recipient.attrs.length; i++)
139
+ recipientAttrsMap.push(recipient.attrs[i].name);
140
+
141
+ for (var j = 0; j < attrs.length; j++) {
142
+ if (recipientAttrsMap.indexOf(attrs[j].name) === -1)
143
+ recipient.attrs.push(attrs[j]);
144
+ }
145
+ };
146
+
147
+
148
+ //Tree traversing
149
+ exports.getFirstChild = function (node) {
150
+ return node.childNodes[0];
151
+ };
152
+
153
+ exports.getChildNodes = function (node) {
154
+ return node.childNodes;
155
+ };
156
+
157
+ exports.getParentNode = function (node) {
158
+ return node.parentNode;
159
+ };
160
+
161
+ exports.getAttrList = function (element) {
162
+ return element.attrs;
163
+ };
164
+
165
+ //Node data
166
+ exports.getTagName = function (element) {
167
+ return element.tagName;
168
+ };
169
+
170
+ exports.getNamespaceURI = function (element) {
171
+ return element.namespaceURI;
172
+ };
173
+
174
+ exports.getTextNodeContent = function (textNode) {
175
+ return textNode.value;
176
+ };
177
+
178
+ exports.getCommentNodeContent = function (commentNode) {
179
+ return commentNode.data;
180
+ };
181
+
182
+ exports.getDocumentTypeNodeName = function (doctypeNode) {
183
+ return doctypeNode.name;
184
+ };
185
+
186
+ exports.getDocumentTypeNodePublicId = function (doctypeNode) {
187
+ return doctypeNode.publicId;
188
+ };
189
+
190
+ exports.getDocumentTypeNodeSystemId = function (doctypeNode) {
191
+ return doctypeNode.systemId;
192
+ };
193
+
194
+ //Node types
195
+ exports.isTextNode = function (node) {
196
+ return node.nodeName === '#text';
197
+ };
198
+
199
+ exports.isCommentNode = function (node) {
200
+ return node.nodeName === '#comment';
201
+ };
202
+
203
+ exports.isDocumentTypeNode = function (node) {
204
+ return node.nodeName === '#documentType';
205
+ };
206
+
207
+ exports.isElementNode = function (node) {
208
+ return !!node.tagName;
209
+ };