xml-twig 1.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.
package/doc/twig.md ADDED
@@ -0,0 +1,1449 @@
1
+ ## Classes
2
+
3
+ <dl>
4
+ <dt><a href="#Twig">Twig</a></dt>
5
+ <dd></dd>
6
+ <dt><a href="#Twig">Twig</a></dt>
7
+ <dd></dd>
8
+ <dt><a href="#UnsupportedParser">UnsupportedParser</a></dt>
9
+ <dd><p>Error for unsupported data types</p>
10
+ </dd>
11
+ <dt><a href="#UnsupportedType">UnsupportedType</a></dt>
12
+ <dd><p>Generic error for unsupported data types</p>
13
+ </dd>
14
+ <dt><a href="#UnsupportedCondition">UnsupportedCondition</a></dt>
15
+ <dd><p>Generic error for unsupported data types</p>
16
+ </dd>
17
+ <dt><a href="#NotImplementedYet">NotImplementedYet</a></dt>
18
+ <dd><p>Generic error for unsupported data types</p>
19
+ </dd>
20
+ </dl>
21
+
22
+ ## Functions
23
+
24
+ <dl>
25
+ <dt><a href="#createParser">createParser(handler, options)</a></dt>
26
+ <dd><p>Create a new Twig parser</p>
27
+ </dd>
28
+ </dl>
29
+
30
+ ## Typedefs
31
+
32
+ <dl>
33
+ <dt><a href="#ParserOptions">ParserOptions</a></dt>
34
+ <dd><p>Optional settings for the Twig parser</p>
35
+ </dd>
36
+ <dt><a href="#TwigHandler">TwigHandler</a></dt>
37
+ <dd><p>Reference to handler functions for Twig objects.<br>
38
+ If <code>name</code> is not specified, then handler is called on every element.<br>
39
+ Otherwise the element name must be equal to the string or Regular Expression. You can specify custom function</p>
40
+ </dd>
41
+ <dt><a href="#HandlerFunction">HandlerFunction</a></dt>
42
+ <dd><p>Handler function for Twig objects, i.e. the way you like to use the XML element.</p>
43
+ </dd>
44
+ <dt><a href="#ElementCondition">ElementCondition</a> : <code>string</code> | <code>RegExp</code> | <code><a href="#ElementConditionFilter">ElementConditionFilter</a></code> | <code><a href="#Twig">Twig</a></code></dt>
45
+ <dd><p>Optional condition to get elements<br> </p>
46
+ <ul>
47
+ <li>If <code>undefined</code>, then all elements are returned.<br> </li>
48
+ <li>If <code>string</code> then the element name must be equal to the string</li>
49
+ <li>If <code>RegExp</code> then the element name must match the Regular Expression</li>
50
+ <li>If <a href="#ElementConditionFilter">ElementConditionFilter</a> then the element must filter function </li>
51
+ <li>Use <a href="#Twig">Twig</a> object to find a specific element (rarely used in <code>createParser(handler)</code>)</li>
52
+ </ul>
53
+ </dd>
54
+ <dt><a href="#ElementConditionFilter">ElementConditionFilter</a> : <code>function</code></dt>
55
+ <dd><p>Custom filter function to get desired elements</p>
56
+ </dd>
57
+ <dt><a href="#AttributeCondition">AttributeCondition</a> : <code>string</code> | <code>RegExp</code> | <code><a href="#AttributeConditionFilter">AttributeConditionFilter</a></code></dt>
58
+ <dd><p>Optional condition to get attributes<br> </p>
59
+ <ul>
60
+ <li>If <code>undefined</code>, then all attributes are returned.<br> </li>
61
+ <li>If <code>string</code> then the attribute name must be equal to the string</li>
62
+ <li>If <code>RegExp</code> then the attribute name must match the Regular Expression</li>
63
+ <li>If <a href="#AttributeConditionFilter">AttributeConditionFilter</a> then the attribute must filter function</li>
64
+ </ul>
65
+ </dd>
66
+ <dt><a href="#AttributeConditionFilter">AttributeConditionFilter</a> : <code>function</code></dt>
67
+ <dd><p>Custom filter function to get desired attributes</p>
68
+ </dd>
69
+ <dt><a href="#+PI">#PI</a> : <code>object</code></dt>
70
+ <dd><p>XML Processing Instruction object, exist only on root</p>
71
+ </dd>
72
+ <dt><a href="#+declaration">#declaration</a> : <code>object</code></dt>
73
+ <dd><p>XML Declaration object, exist only on root</p>
74
+ </dd>
75
+ <dt><a href="#+namespace">#namespace</a> : <code>object</code></dt>
76
+ <dd><p>XML namespace of element. Exist onl when parsed with <code>xmlns: true</code></p>
77
+ </dd>
78
+ <dt><a href="#+comment">#comment</a> : <code>string</code> | <code>Array.&lt;string&gt;</code></dt>
79
+ <dd><p>Comment or array of comments inside the XML Elements</p>
80
+ </dd>
81
+ </dl>
82
+
83
+ <a name="Twig"></a>
84
+
85
+ ## Twig
86
+ **Kind**: global class
87
+
88
+ * [Twig](#Twig)
89
+ * [new Twig()](#new_Twig_new)
90
+ * [new Twig(name, parent, attributes)](#new_Twig_new)
91
+ * [.attributes](#Twig+attributes) ℗
92
+ * [.text](#Twig+text) ℗
93
+ * [.name](#Twig+name) ℗
94
+ * [.children](#Twig+children) ℗
95
+ * [.parent](#Twig+parent) ℗
96
+ * [.postion](#Twig+postion) ℗
97
+ * [.level](#Twig+level) ℗
98
+ * [.isEmpty](#Twig+isEmpty) ⇒ <code>boolean</code>
99
+ * [.level](#Twig+level) ⇒ <code>number</code>
100
+ * [.isRoot](#Twig+isRoot) ⇒ <code>boolean</code>
101
+ * [.hasChildren](#Twig+hasChildren) ⇒ <code>boolean</code>
102
+ * [.line](#Twig+line) ⇒ <code>number</code>
103
+ * [.column](#Twig+column) ⇒ <code>number</code>
104
+ * [.index](#Twig+index) ⇒ <code>number</code>
105
+ * [.name](#Twig+name) ⇒ <code>string</code>
106
+ * [.tag](#Twig+tag) ⇒ <code>string</code>
107
+ * [.text](#Twig+text) ⇒ <code>string</code>
108
+ * [.text](#Twig+text)
109
+ * [.close](#Twig+close)
110
+ * [.addChild](#Twig+addChild) ℗
111
+ * [.writer](#Twig+writer) ⇒ <code>XMLWriter</code>
112
+ * [.attr](#Twig+attr) ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
113
+ * [.hasAttribute](#Twig+hasAttribute) ⇒ <code>boolean</code>
114
+ * [.attribute](#Twig+attribute) ⇒ <code>object</code>
115
+ * [.root](#Twig+root) ⇒ [<code>Twig</code>](#Twig)
116
+ * [.parent](#Twig+parent) ⇒ [<code>Twig</code>](#Twig)
117
+ * [.self](#Twig+self) ⇒ [<code>Twig</code>](#Twig)
118
+ * [.children](#Twig+children) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
119
+ * [.next](#Twig+next) ⇒ [<code>Twig</code>](#Twig)
120
+ * [.previous](#Twig+previous) ⇒ [<code>Twig</code>](#Twig)
121
+ * [.first](#Twig+first) ⇒ [<code>Twig</code>](#Twig)
122
+ * [.last](#Twig+last) ⇒ [<code>Twig</code>](#Twig)
123
+ * [.isFirstChild](#Twig+isFirstChild) ⇒ <code>boolean</code>
124
+ * [.isLastChild](#Twig+isLastChild) ⇒ <code>boolean</code>
125
+ * [.descendant](#Twig+descendant) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
126
+ * [.descendantOrSelf](#Twig+descendantOrSelf) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
127
+ * [.ancestor](#Twig+ancestor) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
128
+ * [.ancestorOrSelf](#Twig+ancestorOrSelf) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
129
+ * [.sibling](#Twig+sibling) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
130
+ * [.siblingOrSelf](#Twig+siblingOrSelf) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
131
+ * [.followingSibling](#Twig+followingSibling) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
132
+ * [.precedingSibling](#Twig+precedingSibling) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
133
+ * [.nextSibling](#Twig+nextSibling) ⇒ [<code>Twig</code>](#Twig)
134
+ * [.prevSibling](#Twig+prevSibling) ⇒ [<code>Twig</code>](#Twig)
135
+ * [.find](#Twig+find) ⇒ [<code>Twig</code>](#Twig)
136
+ * [.purge()](#Twig+purge)
137
+ * [.purgeUpTo(elt)](#Twig+purgeUpTo)
138
+ * [.setRoot(name)](#Twig+setRoot) ℗
139
+ * [.filterElements(elts, condition)](#Twig+filterElements) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
140
+ * [.filterElement(elt, condition)](#Twig+filterElement) ⇒ <code>boolean</code>
141
+
142
+ <a name="new_Twig_new"></a>
143
+
144
+ ### new Twig()
145
+ Generic class modeling a XML Node
146
+
147
+ <a name="new_Twig_new"></a>
148
+
149
+ ### new Twig(name, parent, attributes)
150
+ Create a new Twig object
151
+
152
+
153
+ | Param | Type | Description |
154
+ | --- | --- | --- |
155
+ | name | <code>string</code> | The name of the XML element |
156
+ | parent | [<code>Twig</code>](#Twig) | The parent object |
157
+ | attributes | <code>object</code> | Attriubte object |
158
+
159
+ <a name="Twig+attributes"></a>
160
+
161
+ ### twig.attributes ℗
162
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
163
+ **Access**: private
164
+ **Properties**
165
+
166
+ | Name | Type | Description |
167
+ | --- | --- | --- |
168
+ | #attributes | <code>object</code> | XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }` |
169
+
170
+ <a name="Twig+text"></a>
171
+
172
+ ### twig.text ℗
173
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
174
+ **Access**: private
175
+ **Properties**
176
+
177
+ | Name | Type | Description |
178
+ | --- | --- | --- |
179
+ | #text | <code>string</code> \| <code>number</code> | Content of XML Element |
180
+
181
+ <a name="Twig+name"></a>
182
+
183
+ ### twig.name ℗
184
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
185
+ **Access**: private
186
+ **Properties**
187
+
188
+ | Name | Type | Description |
189
+ | --- | --- | --- |
190
+ | #name | <code>string</code> | The XML tag name |
191
+
192
+ <a name="Twig+children"></a>
193
+
194
+ ### twig.children ℗
195
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
196
+ **Access**: private
197
+ **Properties**
198
+
199
+ | Name | Type | Description |
200
+ | --- | --- | --- |
201
+ | #children | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Child XML Elements |
202
+
203
+ <a name="Twig+parent"></a>
204
+
205
+ ### twig.parent ℗
206
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
207
+ **Access**: private
208
+ **Properties**
209
+
210
+ | Name | Type | Description |
211
+ | --- | --- | --- |
212
+ | #parent | [<code>Twig</code>](#Twig) | The parent object. Undefined on root element |
213
+
214
+ <a name="Twig+postion"></a>
215
+
216
+ ### twig.postion ℗
217
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
218
+ **Access**: private
219
+ **Properties**
220
+
221
+ | Name | Type | Description |
222
+ | --- | --- | --- |
223
+ | #postion | <code>object</code> | The postion of the element in #children array |
224
+
225
+ <a name="Twig+level"></a>
226
+
227
+ ### twig.level ℗
228
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
229
+ **Access**: private
230
+ **Properties**
231
+
232
+ | Name | Type | Description |
233
+ | --- | --- | --- |
234
+ | #level | <code>number</code> | Root element is level 0, children have 1 and so on |
235
+
236
+ <a name="Twig+isEmpty"></a>
237
+
238
+ ### twig.isEmpty ⇒ <code>boolean</code>
239
+ Returns `true` if the element is empty, otherwise `false`.
240
+
241
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
242
+ **Returns**: <code>boolean</code> - true if empty element
243
+ <a name="Twig+level"></a>
244
+
245
+ ### twig.level ⇒ <code>number</code>
246
+ Returns the level of the element. Root element has 0, children have 1, grand-children 2 and so on
247
+
248
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
249
+ **Returns**: <code>number</code> - The level of the element.
250
+ <a name="Twig+isRoot"></a>
251
+
252
+ ### twig.isRoot ⇒ <code>boolean</code>
253
+ Returns `true` if element is the root object
254
+
255
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
256
+ **Returns**: <code>boolean</code> - true if root element
257
+ <a name="Twig+hasChildren"></a>
258
+
259
+ ### twig.hasChildren ⇒ <code>boolean</code>
260
+ Returns `true` if element has child elements
261
+
262
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
263
+ **Returns**: <code>boolean</code> - true if has child elements exists
264
+ <a name="Twig+line"></a>
265
+
266
+ ### twig.line ⇒ <code>number</code>
267
+ Returns the line where current element is closed
268
+
269
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
270
+ **Returns**: <code>number</code> - Current line
271
+ <a name="Twig+column"></a>
272
+
273
+ ### twig.column ⇒ <code>number</code>
274
+ Returns the column where current element is closed
275
+
276
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
277
+ **Returns**: <code>number</code> - Current column
278
+ <a name="Twig+index"></a>
279
+
280
+ ### twig.index ⇒ <code>number</code>
281
+ The position in `#children` array. For root object 0
282
+
283
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
284
+ **Returns**: <code>number</code> - Position of element in parent
285
+ <a name="Twig+name"></a>
286
+
287
+ ### twig.name ⇒ <code>string</code>
288
+ Returns the name of the element.
289
+
290
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
291
+ **Returns**: <code>string</code> - Element name
292
+ <a name="Twig+tag"></a>
293
+
294
+ ### twig.tag ⇒ <code>string</code>
295
+ Returns the name of the element. Synonym for `twig.name`
296
+
297
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
298
+ **Returns**: <code>string</code> - Element name
299
+ <a name="Twig+text"></a>
300
+
301
+ ### twig.text ⇒ <code>string</code>
302
+ The text of the element. No matter if given as text or CDATA entity
303
+
304
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
305
+ **Returns**: <code>string</code> - Element text
306
+ <a name="Twig+text"></a>
307
+
308
+ ### twig.text
309
+ Modifies the text of the element
310
+
311
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
312
+ **Throws**:
313
+
314
+ - [<code>UnsupportedType</code>](#UnsupportedType) - If value is not a string or numeric type
315
+
316
+
317
+ | Param | Type | Description |
318
+ | --- | --- | --- |
319
+ | value | <code>string</code> | New value of the attribute |
320
+
321
+ <a name="Twig+close"></a>
322
+
323
+ ### twig.close
324
+ Closes the element
325
+
326
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
327
+
328
+ | Param | Type | Description |
329
+ | --- | --- | --- |
330
+ | pos | <code>object</code> | The current possion (line and column) in the XML document |
331
+
332
+ <a name="Twig+addChild"></a>
333
+
334
+ ### twig.addChild ℗
335
+ Internal recursive function used by `writer()`
336
+
337
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
338
+ **Access**: private
339
+
340
+ | Param | Type | Description |
341
+ | --- | --- | --- |
342
+ | xw | <code>XMLWriter</code> | The writer object |
343
+ | children | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Array of child elements |
344
+
345
+ <a name="Twig+writer"></a>
346
+
347
+ ### twig.writer ⇒ <code>XMLWriter</code>
348
+ Creates xml-writer from current element
349
+
350
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
351
+
352
+ | Param | Type | Description |
353
+ | --- | --- | --- |
354
+ | indented | <code>boolean</code> \| <code>string</code> | `true` or intention character |
355
+
356
+ <a name="Twig+attr"></a>
357
+
358
+ ### twig.attr ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
359
+ Returns attriute value or `null` if not found.<br>
360
+
361
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
362
+ **Returns**: <code>string</code> \| <code>number</code> \| <code>object</code> - - The value of the attrubute or `null` if the does not exist
363
+
364
+ | Param | Type | Description |
365
+ | --- | --- | --- |
366
+ | condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attribute |
367
+
368
+ <a name="Twig+hasAttribute"></a>
369
+
370
+ ### twig.hasAttribute ⇒ <code>boolean</code>
371
+ Check if the attribute exist or not
372
+
373
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
374
+ **Returns**: <code>boolean</code> - - Returns `true` if the attribute exists, else `false`
375
+
376
+ | Param | Type | Description |
377
+ | --- | --- | --- |
378
+ | name | <code>string</code> | The name of the attribute |
379
+
380
+ <a name="Twig+attribute"></a>
381
+
382
+ ### twig.attribute ⇒ <code>object</code>
383
+ Retrieve or update XML attribute.
384
+
385
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
386
+ **Returns**: <code>object</code> - Attributes or `null` if no matching attribute found
387
+
388
+ | Param | Type | Description |
389
+ | --- | --- | --- |
390
+ | condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attributes |
391
+ | text | <code>string</code> \| <code>number</code> | New value of the attribute |
392
+
393
+ **Example**
394
+ ```js
395
+ attribute((name, val) => { return name === 'age' && val > 50})
396
+ ```
397
+ <a name="Twig+root"></a>
398
+
399
+ ### twig.root ⇒ [<code>Twig</code>](#Twig)
400
+ Returns the root object
401
+
402
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
403
+ **Returns**: [<code>Twig</code>](#Twig) - The root element of XML tree
404
+ <a name="Twig+parent"></a>
405
+
406
+ ### twig.parent ⇒ [<code>Twig</code>](#Twig)
407
+ Returns the parent element or null if root element
408
+
409
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
410
+ **Returns**: [<code>Twig</code>](#Twig) - The parament element
411
+ <a name="Twig+self"></a>
412
+
413
+ ### twig.self ⇒ [<code>Twig</code>](#Twig)
414
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
415
+ **Returns**: [<code>Twig</code>](#Twig) - - The current element
416
+ <a name="Twig+children"></a>
417
+
418
+ ### twig.children ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
419
+ All children, optionally matching `condition` of the current element or empty array
420
+
421
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
422
+
423
+ | Param | Type | Description |
424
+ | --- | --- | --- |
425
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
426
+
427
+ <a name="Twig+next"></a>
428
+
429
+ ### twig.next ⇒ [<code>Twig</code>](#Twig)
430
+ Returns the next matching element.
431
+
432
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
433
+ **Returns**: [<code>Twig</code>](#Twig) - - The next element
434
+
435
+ | Param | Type | Description |
436
+ | --- | --- | --- |
437
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
438
+
439
+ <a name="Twig+previous"></a>
440
+
441
+ ### twig.previous ⇒ [<code>Twig</code>](#Twig)
442
+ Returns the previous matching element.
443
+
444
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
445
+ **Returns**: [<code>Twig</code>](#Twig) - - The previous element
446
+
447
+ | Param | Type | Description |
448
+ | --- | --- | --- |
449
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
450
+
451
+ <a name="Twig+first"></a>
452
+
453
+ ### twig.first ⇒ [<code>Twig</code>](#Twig)
454
+ Returns the first matching element. This is usally the first child element
455
+
456
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
457
+ **Returns**: [<code>Twig</code>](#Twig) - - The first element
458
+
459
+ | Param | Type | Description |
460
+ | --- | --- | --- |
461
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
462
+
463
+ <a name="Twig+last"></a>
464
+
465
+ ### twig.last ⇒ [<code>Twig</code>](#Twig)
466
+ Returns the last matching element. This is usally the root element
467
+
468
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
469
+ **Returns**: [<code>Twig</code>](#Twig) - - The last element
470
+
471
+ | Param | Type | Description |
472
+ | --- | --- | --- |
473
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
474
+
475
+ <a name="Twig+isFirstChild"></a>
476
+
477
+ ### twig.isFirstChild ⇒ <code>boolean</code>
478
+ Check if the element is the first child of the parent
479
+
480
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
481
+ **Returns**: <code>boolean</code> - `true` if the first child else `false`
482
+ <a name="Twig+isLastChild"></a>
483
+
484
+ ### twig.isLastChild ⇒ <code>boolean</code>
485
+ Check if the element is the last child of the parent
486
+
487
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
488
+ **Returns**: <code>boolean</code> - `true` if the last child else `false`
489
+ <a name="Twig+descendant"></a>
490
+
491
+ ### twig.descendant ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
492
+ Returns descendants (children, grandchildren, etc.) of the current element
493
+
494
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
495
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of descendants or empty array
496
+
497
+ | Param | Type | Description |
498
+ | --- | --- | --- |
499
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
500
+
501
+ <a name="Twig+descendantOrSelf"></a>
502
+
503
+ ### twig.descendantOrSelf ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
504
+ Returns descendants (children, grandchildren, etc.) of the current element and the current element itself
505
+
506
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
507
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of descendants or empty array
508
+
509
+ | Param | Type | Description |
510
+ | --- | --- | --- |
511
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
512
+
513
+ <a name="Twig+ancestor"></a>
514
+
515
+ ### twig.ancestor ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
516
+ Returns ancestors (parent, grandparent, etc.) of the current element
517
+
518
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
519
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of ancestors or empty array
520
+
521
+ | Param | Type | Description |
522
+ | --- | --- | --- |
523
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
524
+
525
+ <a name="Twig+ancestorOrSelf"></a>
526
+
527
+ ### twig.ancestorOrSelf ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
528
+ Returns ancestors (parent, grandparent, etc.) of the current element and the current element itself
529
+
530
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
531
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of ancestors or empty array
532
+
533
+ | Param | Type | Description |
534
+ | --- | --- | --- |
535
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
536
+
537
+ <a name="Twig+sibling"></a>
538
+
539
+ ### twig.sibling ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
540
+ Returns all sibling element of the current element
541
+
542
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
543
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
544
+
545
+ | Param | Type | Description |
546
+ | --- | --- | --- |
547
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
548
+
549
+ <a name="Twig+siblingOrSelf"></a>
550
+
551
+ ### twig.siblingOrSelf ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
552
+ Returns all sibling element of the current element and the current element itself
553
+
554
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
555
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
556
+
557
+ | Param | Type | Description |
558
+ | --- | --- | --- |
559
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
560
+
561
+ <a name="Twig+followingSibling"></a>
562
+
563
+ ### twig.followingSibling ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
564
+ Returns all following sibling element of the current element
565
+
566
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
567
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
568
+
569
+ | Param | Type | Description |
570
+ | --- | --- | --- |
571
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
572
+
573
+ <a name="Twig+precedingSibling"></a>
574
+
575
+ ### twig.precedingSibling ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
576
+ Returns all preceding sibling element of the current element
577
+
578
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
579
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
580
+
581
+ | Param | Type | Description |
582
+ | --- | --- | --- |
583
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
584
+
585
+ <a name="Twig+nextSibling"></a>
586
+
587
+ ### twig.nextSibling ⇒ [<code>Twig</code>](#Twig)
588
+ Returns next sibling element of the current element
589
+
590
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
591
+ **Returns**: [<code>Twig</code>](#Twig) - - The next sibling or `null`
592
+
593
+ | Param | Type | Description |
594
+ | --- | --- | --- |
595
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
596
+
597
+ <a name="Twig+prevSibling"></a>
598
+
599
+ ### twig.prevSibling ⇒ [<code>Twig</code>](#Twig)
600
+ Returns previous sibling element of the current element
601
+
602
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
603
+ **Returns**: [<code>Twig</code>](#Twig) - - The previous sibling or `null`
604
+
605
+ | Param | Type | Description |
606
+ | --- | --- | --- |
607
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
608
+
609
+ <a name="Twig+find"></a>
610
+
611
+ ### twig.find ⇒ [<code>Twig</code>](#Twig)
612
+ Find a specific element within current element. Same as `.descendant(condition)[0]`
613
+
614
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
615
+ **Returns**: [<code>Twig</code>](#Twig) - - First matching element or `null`
616
+
617
+ | Param | Type | Description |
618
+ | --- | --- | --- |
619
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Find condition |
620
+
621
+ <a name="Twig+purge"></a>
622
+
623
+ ### twig.purge()
624
+ Purges the current, typically used after element has been processed.<br>The root object cannot be purged.
625
+
626
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
627
+ <a name="Twig+purgeUpTo"></a>
628
+
629
+ ### twig.purgeUpTo(elt)
630
+ Purges up to the elt element. This allows you to keep part of the tree in memory when you purge.
631
+
632
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
633
+
634
+ | Param | Type | Description |
635
+ | --- | --- | --- |
636
+ | elt | [<code>Twig</code>](#Twig) | Up to this element the tree will be purged. If `undefined` then `purge()` is called.<br> The `elt` object itself is not purged. (use `.purge()` is you like to do so) |
637
+
638
+ <a name="Twig+setRoot"></a>
639
+
640
+ ### twig.setRoot(name) ℗
641
+ Sets the name of root element. In some cases the root is created before the XML-Root element is available<br>
642
+
643
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
644
+ **Access**: private
645
+
646
+ | Param | Type | Description |
647
+ | --- | --- | --- |
648
+ | name | <code>string</code> | The element name |
649
+
650
+ <a name="Twig+filterElements"></a>
651
+
652
+ ### twig.filterElements(elts, condition) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
653
+ Common function to filter Twig elements from array
654
+
655
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
656
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - List of matching elements or empty array
657
+
658
+ | Param | Type | Description |
659
+ | --- | --- | --- |
660
+ | elts | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Array of elements you like to filter |
661
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
662
+
663
+ <a name="Twig+filterElement"></a>
664
+
665
+ ### twig.filterElement(elt, condition) ⇒ <code>boolean</code>
666
+ Common function to filter Twig element
667
+
668
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
669
+ **Returns**: <code>boolean</code> - `true` if the condition matches
670
+
671
+ | Param | Type | Description |
672
+ | --- | --- | --- |
673
+ | elt | [<code>Twig</code>](#Twig) | Element you like to filter |
674
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
675
+
676
+ <a name="Twig"></a>
677
+
678
+ ## Twig
679
+ **Kind**: global class
680
+
681
+ * [Twig](#Twig)
682
+ * [new Twig()](#new_Twig_new)
683
+ * [new Twig(name, parent, attributes)](#new_Twig_new)
684
+ * [.attributes](#Twig+attributes) ℗
685
+ * [.text](#Twig+text) ℗
686
+ * [.name](#Twig+name) ℗
687
+ * [.children](#Twig+children) ℗
688
+ * [.parent](#Twig+parent) ℗
689
+ * [.postion](#Twig+postion) ℗
690
+ * [.level](#Twig+level) ℗
691
+ * [.isEmpty](#Twig+isEmpty) ⇒ <code>boolean</code>
692
+ * [.level](#Twig+level) ⇒ <code>number</code>
693
+ * [.isRoot](#Twig+isRoot) ⇒ <code>boolean</code>
694
+ * [.hasChildren](#Twig+hasChildren) ⇒ <code>boolean</code>
695
+ * [.line](#Twig+line) ⇒ <code>number</code>
696
+ * [.column](#Twig+column) ⇒ <code>number</code>
697
+ * [.index](#Twig+index) ⇒ <code>number</code>
698
+ * [.name](#Twig+name) ⇒ <code>string</code>
699
+ * [.tag](#Twig+tag) ⇒ <code>string</code>
700
+ * [.text](#Twig+text) ⇒ <code>string</code>
701
+ * [.text](#Twig+text)
702
+ * [.close](#Twig+close)
703
+ * [.addChild](#Twig+addChild) ℗
704
+ * [.writer](#Twig+writer) ⇒ <code>XMLWriter</code>
705
+ * [.attr](#Twig+attr) ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
706
+ * [.hasAttribute](#Twig+hasAttribute) ⇒ <code>boolean</code>
707
+ * [.attribute](#Twig+attribute) ⇒ <code>object</code>
708
+ * [.root](#Twig+root) ⇒ [<code>Twig</code>](#Twig)
709
+ * [.parent](#Twig+parent) ⇒ [<code>Twig</code>](#Twig)
710
+ * [.self](#Twig+self) ⇒ [<code>Twig</code>](#Twig)
711
+ * [.children](#Twig+children) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
712
+ * [.next](#Twig+next) ⇒ [<code>Twig</code>](#Twig)
713
+ * [.previous](#Twig+previous) ⇒ [<code>Twig</code>](#Twig)
714
+ * [.first](#Twig+first) ⇒ [<code>Twig</code>](#Twig)
715
+ * [.last](#Twig+last) ⇒ [<code>Twig</code>](#Twig)
716
+ * [.isFirstChild](#Twig+isFirstChild) ⇒ <code>boolean</code>
717
+ * [.isLastChild](#Twig+isLastChild) ⇒ <code>boolean</code>
718
+ * [.descendant](#Twig+descendant) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
719
+ * [.descendantOrSelf](#Twig+descendantOrSelf) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
720
+ * [.ancestor](#Twig+ancestor) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
721
+ * [.ancestorOrSelf](#Twig+ancestorOrSelf) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
722
+ * [.sibling](#Twig+sibling) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
723
+ * [.siblingOrSelf](#Twig+siblingOrSelf) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
724
+ * [.followingSibling](#Twig+followingSibling) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
725
+ * [.precedingSibling](#Twig+precedingSibling) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
726
+ * [.nextSibling](#Twig+nextSibling) ⇒ [<code>Twig</code>](#Twig)
727
+ * [.prevSibling](#Twig+prevSibling) ⇒ [<code>Twig</code>](#Twig)
728
+ * [.find](#Twig+find) ⇒ [<code>Twig</code>](#Twig)
729
+ * [.purge()](#Twig+purge)
730
+ * [.purgeUpTo(elt)](#Twig+purgeUpTo)
731
+ * [.setRoot(name)](#Twig+setRoot) ℗
732
+ * [.filterElements(elts, condition)](#Twig+filterElements) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
733
+ * [.filterElement(elt, condition)](#Twig+filterElement) ⇒ <code>boolean</code>
734
+
735
+ <a name="new_Twig_new"></a>
736
+
737
+ ### new Twig()
738
+ Generic class modeling a XML Node
739
+
740
+ <a name="new_Twig_new"></a>
741
+
742
+ ### new Twig(name, parent, attributes)
743
+ Create a new Twig object
744
+
745
+
746
+ | Param | Type | Description |
747
+ | --- | --- | --- |
748
+ | name | <code>string</code> | The name of the XML element |
749
+ | parent | [<code>Twig</code>](#Twig) | The parent object |
750
+ | attributes | <code>object</code> | Attriubte object |
751
+
752
+ <a name="Twig+attributes"></a>
753
+
754
+ ### twig.attributes ℗
755
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
756
+ **Access**: private
757
+ **Properties**
758
+
759
+ | Name | Type | Description |
760
+ | --- | --- | --- |
761
+ | #attributes | <code>object</code> | XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }` |
762
+
763
+ <a name="Twig+text"></a>
764
+
765
+ ### twig.text ℗
766
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
767
+ **Access**: private
768
+ **Properties**
769
+
770
+ | Name | Type | Description |
771
+ | --- | --- | --- |
772
+ | #text | <code>string</code> \| <code>number</code> | Content of XML Element |
773
+
774
+ <a name="Twig+name"></a>
775
+
776
+ ### twig.name ℗
777
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
778
+ **Access**: private
779
+ **Properties**
780
+
781
+ | Name | Type | Description |
782
+ | --- | --- | --- |
783
+ | #name | <code>string</code> | The XML tag name |
784
+
785
+ <a name="Twig+children"></a>
786
+
787
+ ### twig.children ℗
788
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
789
+ **Access**: private
790
+ **Properties**
791
+
792
+ | Name | Type | Description |
793
+ | --- | --- | --- |
794
+ | #children | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Child XML Elements |
795
+
796
+ <a name="Twig+parent"></a>
797
+
798
+ ### twig.parent ℗
799
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
800
+ **Access**: private
801
+ **Properties**
802
+
803
+ | Name | Type | Description |
804
+ | --- | --- | --- |
805
+ | #parent | [<code>Twig</code>](#Twig) | The parent object. Undefined on root element |
806
+
807
+ <a name="Twig+postion"></a>
808
+
809
+ ### twig.postion ℗
810
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
811
+ **Access**: private
812
+ **Properties**
813
+
814
+ | Name | Type | Description |
815
+ | --- | --- | --- |
816
+ | #postion | <code>object</code> | The postion of the element in #children array |
817
+
818
+ <a name="Twig+level"></a>
819
+
820
+ ### twig.level ℗
821
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
822
+ **Access**: private
823
+ **Properties**
824
+
825
+ | Name | Type | Description |
826
+ | --- | --- | --- |
827
+ | #level | <code>number</code> | Root element is level 0, children have 1 and so on |
828
+
829
+ <a name="Twig+isEmpty"></a>
830
+
831
+ ### twig.isEmpty ⇒ <code>boolean</code>
832
+ Returns `true` if the element is empty, otherwise `false`.
833
+
834
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
835
+ **Returns**: <code>boolean</code> - true if empty element
836
+ <a name="Twig+level"></a>
837
+
838
+ ### twig.level ⇒ <code>number</code>
839
+ Returns the level of the element. Root element has 0, children have 1, grand-children 2 and so on
840
+
841
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
842
+ **Returns**: <code>number</code> - The level of the element.
843
+ <a name="Twig+isRoot"></a>
844
+
845
+ ### twig.isRoot ⇒ <code>boolean</code>
846
+ Returns `true` if element is the root object
847
+
848
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
849
+ **Returns**: <code>boolean</code> - true if root element
850
+ <a name="Twig+hasChildren"></a>
851
+
852
+ ### twig.hasChildren ⇒ <code>boolean</code>
853
+ Returns `true` if element has child elements
854
+
855
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
856
+ **Returns**: <code>boolean</code> - true if has child elements exists
857
+ <a name="Twig+line"></a>
858
+
859
+ ### twig.line ⇒ <code>number</code>
860
+ Returns the line where current element is closed
861
+
862
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
863
+ **Returns**: <code>number</code> - Current line
864
+ <a name="Twig+column"></a>
865
+
866
+ ### twig.column ⇒ <code>number</code>
867
+ Returns the column where current element is closed
868
+
869
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
870
+ **Returns**: <code>number</code> - Current column
871
+ <a name="Twig+index"></a>
872
+
873
+ ### twig.index ⇒ <code>number</code>
874
+ The position in `#children` array. For root object 0
875
+
876
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
877
+ **Returns**: <code>number</code> - Position of element in parent
878
+ <a name="Twig+name"></a>
879
+
880
+ ### twig.name ⇒ <code>string</code>
881
+ Returns the name of the element.
882
+
883
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
884
+ **Returns**: <code>string</code> - Element name
885
+ <a name="Twig+tag"></a>
886
+
887
+ ### twig.tag ⇒ <code>string</code>
888
+ Returns the name of the element. Synonym for `twig.name`
889
+
890
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
891
+ **Returns**: <code>string</code> - Element name
892
+ <a name="Twig+text"></a>
893
+
894
+ ### twig.text ⇒ <code>string</code>
895
+ The text of the element. No matter if given as text or CDATA entity
896
+
897
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
898
+ **Returns**: <code>string</code> - Element text
899
+ <a name="Twig+text"></a>
900
+
901
+ ### twig.text
902
+ Modifies the text of the element
903
+
904
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
905
+ **Throws**:
906
+
907
+ - [<code>UnsupportedType</code>](#UnsupportedType) - If value is not a string or numeric type
908
+
909
+
910
+ | Param | Type | Description |
911
+ | --- | --- | --- |
912
+ | value | <code>string</code> | New value of the attribute |
913
+
914
+ <a name="Twig+close"></a>
915
+
916
+ ### twig.close
917
+ Closes the element
918
+
919
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
920
+
921
+ | Param | Type | Description |
922
+ | --- | --- | --- |
923
+ | pos | <code>object</code> | The current possion (line and column) in the XML document |
924
+
925
+ <a name="Twig+addChild"></a>
926
+
927
+ ### twig.addChild ℗
928
+ Internal recursive function used by `writer()`
929
+
930
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
931
+ **Access**: private
932
+
933
+ | Param | Type | Description |
934
+ | --- | --- | --- |
935
+ | xw | <code>XMLWriter</code> | The writer object |
936
+ | children | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Array of child elements |
937
+
938
+ <a name="Twig+writer"></a>
939
+
940
+ ### twig.writer ⇒ <code>XMLWriter</code>
941
+ Creates xml-writer from current element
942
+
943
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
944
+
945
+ | Param | Type | Description |
946
+ | --- | --- | --- |
947
+ | indented | <code>boolean</code> \| <code>string</code> | `true` or intention character |
948
+
949
+ <a name="Twig+attr"></a>
950
+
951
+ ### twig.attr ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
952
+ Returns attriute value or `null` if not found.<br>
953
+
954
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
955
+ **Returns**: <code>string</code> \| <code>number</code> \| <code>object</code> - - The value of the attrubute or `null` if the does not exist
956
+
957
+ | Param | Type | Description |
958
+ | --- | --- | --- |
959
+ | condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attribute |
960
+
961
+ <a name="Twig+hasAttribute"></a>
962
+
963
+ ### twig.hasAttribute ⇒ <code>boolean</code>
964
+ Check if the attribute exist or not
965
+
966
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
967
+ **Returns**: <code>boolean</code> - - Returns `true` if the attribute exists, else `false`
968
+
969
+ | Param | Type | Description |
970
+ | --- | --- | --- |
971
+ | name | <code>string</code> | The name of the attribute |
972
+
973
+ <a name="Twig+attribute"></a>
974
+
975
+ ### twig.attribute ⇒ <code>object</code>
976
+ Retrieve or update XML attribute.
977
+
978
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
979
+ **Returns**: <code>object</code> - Attributes or `null` if no matching attribute found
980
+
981
+ | Param | Type | Description |
982
+ | --- | --- | --- |
983
+ | condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attributes |
984
+ | text | <code>string</code> \| <code>number</code> | New value of the attribute |
985
+
986
+ **Example**
987
+ ```js
988
+ attribute((name, val) => { return name === 'age' && val > 50})
989
+ ```
990
+ <a name="Twig+root"></a>
991
+
992
+ ### twig.root ⇒ [<code>Twig</code>](#Twig)
993
+ Returns the root object
994
+
995
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
996
+ **Returns**: [<code>Twig</code>](#Twig) - The root element of XML tree
997
+ <a name="Twig+parent"></a>
998
+
999
+ ### twig.parent ⇒ [<code>Twig</code>](#Twig)
1000
+ Returns the parent element or null if root element
1001
+
1002
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1003
+ **Returns**: [<code>Twig</code>](#Twig) - The parament element
1004
+ <a name="Twig+self"></a>
1005
+
1006
+ ### twig.self ⇒ [<code>Twig</code>](#Twig)
1007
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1008
+ **Returns**: [<code>Twig</code>](#Twig) - - The current element
1009
+ <a name="Twig+children"></a>
1010
+
1011
+ ### twig.children ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1012
+ All children, optionally matching `condition` of the current element or empty array
1013
+
1014
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1015
+
1016
+ | Param | Type | Description |
1017
+ | --- | --- | --- |
1018
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1019
+
1020
+ <a name="Twig+next"></a>
1021
+
1022
+ ### twig.next ⇒ [<code>Twig</code>](#Twig)
1023
+ Returns the next matching element.
1024
+
1025
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1026
+ **Returns**: [<code>Twig</code>](#Twig) - - The next element
1027
+
1028
+ | Param | Type | Description |
1029
+ | --- | --- | --- |
1030
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1031
+
1032
+ <a name="Twig+previous"></a>
1033
+
1034
+ ### twig.previous ⇒ [<code>Twig</code>](#Twig)
1035
+ Returns the previous matching element.
1036
+
1037
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1038
+ **Returns**: [<code>Twig</code>](#Twig) - - The previous element
1039
+
1040
+ | Param | Type | Description |
1041
+ | --- | --- | --- |
1042
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1043
+
1044
+ <a name="Twig+first"></a>
1045
+
1046
+ ### twig.first ⇒ [<code>Twig</code>](#Twig)
1047
+ Returns the first matching element. This is usally the first child element
1048
+
1049
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1050
+ **Returns**: [<code>Twig</code>](#Twig) - - The first element
1051
+
1052
+ | Param | Type | Description |
1053
+ | --- | --- | --- |
1054
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1055
+
1056
+ <a name="Twig+last"></a>
1057
+
1058
+ ### twig.last ⇒ [<code>Twig</code>](#Twig)
1059
+ Returns the last matching element. This is usally the root element
1060
+
1061
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1062
+ **Returns**: [<code>Twig</code>](#Twig) - - The last element
1063
+
1064
+ | Param | Type | Description |
1065
+ | --- | --- | --- |
1066
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1067
+
1068
+ <a name="Twig+isFirstChild"></a>
1069
+
1070
+ ### twig.isFirstChild ⇒ <code>boolean</code>
1071
+ Check if the element is the first child of the parent
1072
+
1073
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1074
+ **Returns**: <code>boolean</code> - `true` if the first child else `false`
1075
+ <a name="Twig+isLastChild"></a>
1076
+
1077
+ ### twig.isLastChild ⇒ <code>boolean</code>
1078
+ Check if the element is the last child of the parent
1079
+
1080
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1081
+ **Returns**: <code>boolean</code> - `true` if the last child else `false`
1082
+ <a name="Twig+descendant"></a>
1083
+
1084
+ ### twig.descendant ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1085
+ Returns descendants (children, grandchildren, etc.) of the current element
1086
+
1087
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1088
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of descendants or empty array
1089
+
1090
+ | Param | Type | Description |
1091
+ | --- | --- | --- |
1092
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1093
+
1094
+ <a name="Twig+descendantOrSelf"></a>
1095
+
1096
+ ### twig.descendantOrSelf ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1097
+ Returns descendants (children, grandchildren, etc.) of the current element and the current element itself
1098
+
1099
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1100
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of descendants or empty array
1101
+
1102
+ | Param | Type | Description |
1103
+ | --- | --- | --- |
1104
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1105
+
1106
+ <a name="Twig+ancestor"></a>
1107
+
1108
+ ### twig.ancestor ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1109
+ Returns ancestors (parent, grandparent, etc.) of the current element
1110
+
1111
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1112
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of ancestors or empty array
1113
+
1114
+ | Param | Type | Description |
1115
+ | --- | --- | --- |
1116
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1117
+
1118
+ <a name="Twig+ancestorOrSelf"></a>
1119
+
1120
+ ### twig.ancestorOrSelf ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1121
+ Returns ancestors (parent, grandparent, etc.) of the current element and the current element itself
1122
+
1123
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1124
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of ancestors or empty array
1125
+
1126
+ | Param | Type | Description |
1127
+ | --- | --- | --- |
1128
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1129
+
1130
+ <a name="Twig+sibling"></a>
1131
+
1132
+ ### twig.sibling ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1133
+ Returns all sibling element of the current element
1134
+
1135
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1136
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
1137
+
1138
+ | Param | Type | Description |
1139
+ | --- | --- | --- |
1140
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1141
+
1142
+ <a name="Twig+siblingOrSelf"></a>
1143
+
1144
+ ### twig.siblingOrSelf ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1145
+ Returns all sibling element of the current element and the current element itself
1146
+
1147
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1148
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
1149
+
1150
+ | Param | Type | Description |
1151
+ | --- | --- | --- |
1152
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1153
+
1154
+ <a name="Twig+followingSibling"></a>
1155
+
1156
+ ### twig.followingSibling ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1157
+ Returns all following sibling element of the current element
1158
+
1159
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1160
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
1161
+
1162
+ | Param | Type | Description |
1163
+ | --- | --- | --- |
1164
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1165
+
1166
+ <a name="Twig+precedingSibling"></a>
1167
+
1168
+ ### twig.precedingSibling ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1169
+ Returns all preceding sibling element of the current element
1170
+
1171
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1172
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - - Array of sibling or empty array
1173
+
1174
+ | Param | Type | Description |
1175
+ | --- | --- | --- |
1176
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1177
+
1178
+ <a name="Twig+nextSibling"></a>
1179
+
1180
+ ### twig.nextSibling ⇒ [<code>Twig</code>](#Twig)
1181
+ Returns next sibling element of the current element
1182
+
1183
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1184
+ **Returns**: [<code>Twig</code>](#Twig) - - The next sibling or `null`
1185
+
1186
+ | Param | Type | Description |
1187
+ | --- | --- | --- |
1188
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1189
+
1190
+ <a name="Twig+prevSibling"></a>
1191
+
1192
+ ### twig.prevSibling ⇒ [<code>Twig</code>](#Twig)
1193
+ Returns previous sibling element of the current element
1194
+
1195
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1196
+ **Returns**: [<code>Twig</code>](#Twig) - - The previous sibling or `null`
1197
+
1198
+ | Param | Type | Description |
1199
+ | --- | --- | --- |
1200
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
1201
+
1202
+ <a name="Twig+find"></a>
1203
+
1204
+ ### twig.find ⇒ [<code>Twig</code>](#Twig)
1205
+ Find a specific element within current element. Same as `.descendant(condition)[0]`
1206
+
1207
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
1208
+ **Returns**: [<code>Twig</code>](#Twig) - - First matching element or `null`
1209
+
1210
+ | Param | Type | Description |
1211
+ | --- | --- | --- |
1212
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | Find condition |
1213
+
1214
+ <a name="Twig+purge"></a>
1215
+
1216
+ ### twig.purge()
1217
+ Purges the current, typically used after element has been processed.<br>The root object cannot be purged.
1218
+
1219
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
1220
+ <a name="Twig+purgeUpTo"></a>
1221
+
1222
+ ### twig.purgeUpTo(elt)
1223
+ Purges up to the elt element. This allows you to keep part of the tree in memory when you purge.
1224
+
1225
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
1226
+
1227
+ | Param | Type | Description |
1228
+ | --- | --- | --- |
1229
+ | elt | [<code>Twig</code>](#Twig) | Up to this element the tree will be purged. If `undefined` then `purge()` is called.<br> The `elt` object itself is not purged. (use `.purge()` is you like to do so) |
1230
+
1231
+ <a name="Twig+setRoot"></a>
1232
+
1233
+ ### twig.setRoot(name) ℗
1234
+ Sets the name of root element. In some cases the root is created before the XML-Root element is available<br>
1235
+
1236
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
1237
+ **Access**: private
1238
+
1239
+ | Param | Type | Description |
1240
+ | --- | --- | --- |
1241
+ | name | <code>string</code> | The element name |
1242
+
1243
+ <a name="Twig+filterElements"></a>
1244
+
1245
+ ### twig.filterElements(elts, condition) ⇒ [<code>Array.&lt;Twig&gt;</code>](#Twig)
1246
+ Common function to filter Twig elements from array
1247
+
1248
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
1249
+ **Returns**: [<code>Array.&lt;Twig&gt;</code>](#Twig) - List of matching elements or empty array
1250
+
1251
+ | Param | Type | Description |
1252
+ | --- | --- | --- |
1253
+ | elts | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Array of elements you like to filter |
1254
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
1255
+
1256
+ <a name="Twig+filterElement"></a>
1257
+
1258
+ ### twig.filterElement(elt, condition) ⇒ <code>boolean</code>
1259
+ Common function to filter Twig element
1260
+
1261
+ **Kind**: instance method of [<code>Twig</code>](#Twig)
1262
+ **Returns**: <code>boolean</code> - `true` if the condition matches
1263
+
1264
+ | Param | Type | Description |
1265
+ | --- | --- | --- |
1266
+ | elt | [<code>Twig</code>](#Twig) | Element you like to filter |
1267
+ | condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
1268
+
1269
+ <a name="UnsupportedParser"></a>
1270
+
1271
+ ## UnsupportedParser
1272
+ Error for unsupported data types
1273
+
1274
+ **Kind**: global class
1275
+ <a name="new_UnsupportedParser_new"></a>
1276
+
1277
+ ### new UnsupportedParser(t)
1278
+ **Throws**:
1279
+
1280
+ - UnsupportedParser
1281
+
1282
+
1283
+ | Param | Type | Description |
1284
+ | --- | --- | --- |
1285
+ | t | <code>string</code> | Parser type |
1286
+
1287
+ <a name="UnsupportedType"></a>
1288
+
1289
+ ## UnsupportedType
1290
+ Generic error for unsupported data types
1291
+
1292
+ **Kind**: global class
1293
+ <a name="new_UnsupportedType_new"></a>
1294
+
1295
+ ### new UnsupportedType(t)
1296
+ **Throws**:
1297
+
1298
+ - UnsupportedType
1299
+
1300
+
1301
+ | Param | Type | Description |
1302
+ | --- | --- | --- |
1303
+ | t | <code>\*</code> | Parameter which was used |
1304
+
1305
+ <a name="UnsupportedCondition"></a>
1306
+
1307
+ ## UnsupportedCondition
1308
+ Generic error for unsupported data types
1309
+
1310
+ **Kind**: global class
1311
+ <a name="new_UnsupportedCondition_new"></a>
1312
+
1313
+ ### new UnsupportedCondition(condition, t)
1314
+ **Throws**:
1315
+
1316
+ - UnsupportedCondition
1317
+
1318
+
1319
+ | Param | Type | Description |
1320
+ | --- | --- | --- |
1321
+ | condition | <code>\*</code> | The condition value |
1322
+ | t | <code>Array.&lt;string&gt;</code> | List of supported data types |
1323
+
1324
+ <a name="NotImplementedYet"></a>
1325
+
1326
+ ## NotImplementedYet
1327
+ Generic error for unsupported data types
1328
+
1329
+ **Kind**: global class
1330
+ <a name="createParser"></a>
1331
+
1332
+ ## createParser(handler, options)
1333
+ Create a new Twig parser
1334
+
1335
+ **Kind**: global function
1336
+ **Throws**:
1337
+
1338
+ - [<code>UnsupportedParser</code>](#UnsupportedParser) - For an unsupported parser. Currently `expat` (default) and `sax` are supported.
1339
+
1340
+
1341
+ | Param | Type | Description |
1342
+ | --- | --- | --- |
1343
+ | handler | [<code>TwigHandler</code>](#TwigHandler) \| [<code>Array.&lt;TwigHandler&gt;</code>](#TwigHandler) | Function or array of function to handle elements |
1344
+ | options | [<code>ParserOptions</code>](#ParserOptions) | Object of optional options |
1345
+
1346
+ <a name="ParserOptions"></a>
1347
+
1348
+ ## ParserOptions
1349
+ Optional settings for the Twig parser
1350
+
1351
+ **Kind**: global typedef
1352
+ **Default**: <code>{ method: &#x27;expat&#x27;, encoding: &#x27;UTF-8&#x27;, xmlns: false, trim: true, resumeAfterError: false, partial: false }</code>
1353
+
1354
+ | Param | Type | Description |
1355
+ | --- | --- | --- |
1356
+ | method | <code>string</code> | The underlaying parser. Either `'sax'` or `'expat'`. |
1357
+ | encoding | <code>string</code> | Encoding of the XML File. Applies only to `expat` parser. |
1358
+ | xmlns | <code>boolean</code> | If true, then namespaces are accessible by `namespace` property. |
1359
+ | trim | <code>boolean</code> | If true, then turn any whitespace into a single space. Text and comments are trimmed. |
1360
+ | resumeAfterError | <code>boolean</code> | If true then parser continues reading after an error. Otherwiese it throws exception. |
1361
+ | partial | <code>boolean</code> | It true then unhandled elements are purged. |
1362
+
1363
+ **Example**
1364
+ ```js
1365
+ { encoding: 'UTF-8', xmlns: true }
1366
+ ```
1367
+ <a name="TwigHandler"></a>
1368
+
1369
+ ## TwigHandler
1370
+ Reference to handler functions for Twig objects.<br>
1371
+
1372
+ **Kind**: global typedef
1373
+
1374
+ | Param | Type | Description |
1375
+ | --- | --- | --- |
1376
+ | name | <code>string</code> \| <code>RegExp</code> \| [<code>ElementCondition</code>](#ElementCondition) | Name of handled element or any element if not specified |
1377
+ | HandlerFunction | <code>function</code> | Definition of handler function, either anonymous or explict function |
1378
+
1379
+ <a name="HandlerFunction"></a>
1380
+
1381
+ ## HandlerFunction
1382
+ Handler function for Twig objects, i.e. the way you like to use the XML element.
1383
+
1384
+ **Kind**: global typedef
1385
+
1386
+ | Param | Type | Description |
1387
+ | --- | --- | --- |
1388
+ | elt | [<code>Twig</code>](#Twig) | The current Twig element on which the function was called. |
1389
+
1390
+ <a name="ElementCondition"></a>
1391
+
1392
+ ## ElementCondition : <code>string</code> \| <code>RegExp</code> \| [<code>ElementConditionFilter</code>](#ElementConditionFilter) \| [<code>Twig</code>](#Twig)
1393
+ Optional condition to get elements<br>
- If `undefined`, then all elements are returned.<br>
1
- If `string` then the element name must be equal to the string
2
- If `RegExp` then the element name must match the Regular Expression
3
- If [ElementConditionFilter](#ElementConditionFilter) then the element must filter function
4
- Use [Twig](#Twig) object to find a specific element (rarely used in `createParser(handler)`)
1394
+
1395
+ **Kind**: global typedef
1396
+ <a name="ElementConditionFilter"></a>
1397
+
1398
+ ## ElementConditionFilter : <code>function</code>
1399
+ Custom filter function to get desired elements
1400
+
1401
+ **Kind**: global typedef
1402
+
1403
+ | Param | Type | Description |
1404
+ | --- | --- | --- |
1405
+ | name | <code>string</code> | Name of the element |
1406
+ | elt | [<code>Twig</code>](#Twig) | The full Twig object |
1407
+
1408
+ <a name="AttributeCondition"></a>
1409
+
1410
+ ## AttributeCondition : <code>string</code> \| <code>RegExp</code> \| [<code>AttributeConditionFilter</code>](#AttributeConditionFilter)
1411
+ Optional condition to get attributes<br>
5
- If `undefined`, then all attributes are returned.<br>
6
- If `string` then the attribute name must be equal to the string
7
- If `RegExp` then the attribute name must match the Regular Expression
8
- If [AttributeConditionFilter](#AttributeConditionFilter) then the attribute must filter function
1412
+
1413
+ **Kind**: global typedef
1414
+ <a name="AttributeConditionFilter"></a>
1415
+
1416
+ ## AttributeConditionFilter : <code>function</code>
1417
+ Custom filter function to get desired attributes
1418
+
1419
+ **Kind**: global typedef
1420
+
1421
+ | Param | Type | Description |
1422
+ | --- | --- | --- |
1423
+ | name | <code>string</code> | Name of the attribute |
1424
+ | value | <code>string</code> \| <code>number</code> | Value of the attribute |
1425
+
1426
+ <a name="+PI"></a>
1427
+
1428
+ ## #PI : <code>object</code>
1429
+ XML Processing Instruction object, exist only on root
1430
+
1431
+ **Kind**: global typedef
1432
+ <a name="+declaration"></a>
1433
+
1434
+ ## #declaration : <code>object</code>
1435
+ XML Declaration object, exist only on root
1436
+
1437
+ **Kind**: global typedef
1438
+ <a name="+namespace"></a>
1439
+
1440
+ ## #namespace : <code>object</code>
1441
+ XML namespace of element. Exist onl when parsed with `xmlns: true`
1442
+
1443
+ **Kind**: global typedef
1444
+ <a name="+comment"></a>
1445
+
1446
+ ## #comment : <code>string</code> \| <code>Array.&lt;string&gt;</code>
1447
+ Comment or array of comments inside the XML Elements
1448
+
1449
+ **Kind**: global typedef