xml-twig 1.7.10 → 1.7.12

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