xml-twig 1.9.1 → 1.9.3

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 +54 -34
  2. package/package.json +3 -3
  3. package/twig.js +1 -1
package/doc/twig.md CHANGED
@@ -259,7 +259,8 @@ Purges the current, typically used after element has been processed.<br>The root
259
259
  <a name="Twig+purgeUpTo"></a>
260
260
 
261
261
  ### twig.purgeUpTo
262
- Purges up to the elt element. This allows you to keep part of the tree in memory when you purge.<br>
262
+ Purges up to the elt element. This allows you to keep part of the tree in memory when you purge.<br>
263
+ The `elt` object is not purged. If you like to purge including `elt`, use `.purgeUpTo(elt.previous())`
263
264
 
264
265
  **Kind**: instance property of [<code>Twig</code>](#Twig)
265
266
 
@@ -281,7 +282,8 @@ Escapes special XML characters. According W3C specification these are only `&, <
281
282
  <a name="Twig+isEmpty"></a>
282
283
 
283
284
  ### twig.isEmpty ⇒ <code>boolean</code>
284
- Returns `true` if the element is empty, otherwise `false`.
285
+ Returns `true` if the element is empty, otherwise `false`.
286
+ An empty element has no text nor any child elements, however empty elements can have attributes.
285
287
 
286
288
  **Kind**: instance property of [<code>Twig</code>](#Twig)
287
289
  **Returns**: <code>boolean</code> - true if empty element
@@ -316,7 +318,8 @@ The position in `#children` array. For root object 0
316
318
  <a name="Twig+path"></a>
317
319
 
318
320
  ### twig.path ⇒ <code>string</code>
319
- The X-Path position of the element
321
+ The X-Path position of the element
322
+ NOTE: Applies only to currently loaded elements.
320
323
 
321
324
  **Kind**: instance property of [<code>Twig</code>](#Twig)
322
325
  **Returns**: <code>string</code> - X-Path
@@ -337,7 +340,8 @@ Returns the name of the element. Synonym for `twig.name`
337
340
  <a name="Twig+text"></a>
338
341
 
339
342
  ### twig.text ⇒ <code>string</code>
340
- The text of the element. No matter if given as text or CDATA entity.
343
+ The text of the element. No matter if given as text or CDATA entity.
344
+ If option `trim: true`, then whitespace from both ends of the string are removed
341
345
 
342
346
  **Kind**: instance property of [<code>Twig</code>](#Twig)
343
347
  **Returns**: <code>string</code> - Element text or empty string
@@ -416,7 +420,8 @@ Creates xml-writer from current element
416
420
  <a name="Twig+attr"></a>
417
421
 
418
422
  ### twig.attr ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
419
- Returns attribute value or `null` if not found.<br>
423
+ Returns attribute value or `null` if not found.<br>
424
+ If more than one matches the condition, then it returns object as [attribute()](#attribute)
420
425
 
421
426
  **Kind**: instance property of [<code>Twig</code>](#Twig)
422
427
  **Returns**: <code>string</code> \| <code>number</code> \| <code>object</code> - - The value of the attribute or `null` if the does not exist
@@ -459,7 +464,10 @@ Retrieve or update XML attribute. For update, the condition must be a string, i.
459
464
 
460
465
  **Example**
461
466
  ```js
462
- attribute((name, val) => { return name === 'age' && val > 50})
467
+ attribute((name, val) => { return name === 'age' && val > 50})
468
+ attribute((name) => { return ['firstName', 'lastName'].includes(name) })
469
+ attribute('firstName')
470
+ attribute(/name/i)
463
471
  ```
464
472
  <a name="Twig+deleteAttribute"></a>
465
473
 
@@ -744,7 +752,8 @@ Deletes the current element from tree, same as `purge()`. The root object cannot
744
752
  <a name="Twig+setRoot"></a>
745
753
 
746
754
  ### twig.setRoot(name) ℗
747
- Sets the name of root element. In some cases the root is created before the XML-Root element is available<br>
755
+ Sets the name of root element. In some cases the root is created before the XML-Root element is available<br>
756
+ Used internally!
748
757
 
749
758
  **Kind**: instance method of [<code>Twig</code>](#Twig)
750
759
  **Access**: private
@@ -925,7 +934,8 @@ Purges the current, typically used after element has been processed.<br>The root
925
934
  <a name="Twig+purgeUpTo"></a>
926
935
 
927
936
  ### twig.purgeUpTo
928
- Purges up to the elt element. This allows you to keep part of the tree in memory when you purge.<br>
937
+ Purges up to the elt element. This allows you to keep part of the tree in memory when you purge.<br>
938
+ The `elt` object is not purged. If you like to purge including `elt`, use `.purgeUpTo(elt.previous())`
929
939
 
930
940
  **Kind**: instance property of [<code>Twig</code>](#Twig)
931
941
 
@@ -947,7 +957,8 @@ Escapes special XML characters. According W3C specification these are only `&, <
947
957
  <a name="Twig+isEmpty"></a>
948
958
 
949
959
  ### twig.isEmpty ⇒ <code>boolean</code>
950
- Returns `true` if the element is empty, otherwise `false`.
960
+ Returns `true` if the element is empty, otherwise `false`.
961
+ An empty element has no text nor any child elements, however empty elements can have attributes.
951
962
 
952
963
  **Kind**: instance property of [<code>Twig</code>](#Twig)
953
964
  **Returns**: <code>boolean</code> - true if empty element
@@ -982,7 +993,8 @@ The position in `#children` array. For root object 0
982
993
  <a name="Twig+path"></a>
983
994
 
984
995
  ### twig.path ⇒ <code>string</code>
985
- The X-Path position of the element
996
+ The X-Path position of the element
997
+ NOTE: Applies only to currently loaded elements.
986
998
 
987
999
  **Kind**: instance property of [<code>Twig</code>](#Twig)
988
1000
  **Returns**: <code>string</code> - X-Path
@@ -1003,7 +1015,8 @@ Returns the name of the element. Synonym for `twig.name`
1003
1015
  <a name="Twig+text"></a>
1004
1016
 
1005
1017
  ### twig.text ⇒ <code>string</code>
1006
- The text of the element. No matter if given as text or CDATA entity.
1018
+ The text of the element. No matter if given as text or CDATA entity.
1019
+ If option `trim: true`, then whitespace from both ends of the string are removed
1007
1020
 
1008
1021
  **Kind**: instance property of [<code>Twig</code>](#Twig)
1009
1022
  **Returns**: <code>string</code> - Element text or empty string
@@ -1082,7 +1095,8 @@ Creates xml-writer from current element
1082
1095
  <a name="Twig+attr"></a>
1083
1096
 
1084
1097
  ### twig.attr ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
1085
- Returns attribute value or `null` if not found.<br>
1098
+ Returns attribute value or `null` if not found.<br>
1099
+ If more than one matches the condition, then it returns object as [attribute()](#attribute)
1086
1100
 
1087
1101
  **Kind**: instance property of [<code>Twig</code>](#Twig)
1088
1102
  **Returns**: <code>string</code> \| <code>number</code> \| <code>object</code> - - The value of the attribute or `null` if the does not exist
@@ -1125,7 +1139,10 @@ Retrieve or update XML attribute. For update, the condition must be a string, i.
1125
1139
 
1126
1140
  **Example**
1127
1141
  ```js
1128
- attribute((name, val) => { return name === 'age' && val > 50})
1142
+ attribute((name, val) => { return name === 'age' && val > 50})
1143
+ attribute((name) => { return ['firstName', 'lastName'].includes(name) })
1144
+ attribute('firstName')
1145
+ attribute(/name/i)
1129
1146
  ```
1130
1147
  <a name="Twig+deleteAttribute"></a>
1131
1148
 
@@ -1410,7 +1427,8 @@ Deletes the current element from tree, same as `purge()`. The root object cannot
1410
1427
  <a name="Twig+setRoot"></a>
1411
1428
 
1412
1429
  ### twig.setRoot(name) ℗
1413
- Sets the name of root element. In some cases the root is created before the XML-Root element is available<br>
1430
+ Sets the name of root element. In some cases the root is created before the XML-Root element is available<br>
1431
+ Used internally!
1414
1432
 
1415
1433
  **Kind**: instance method of [<code>Twig</code>](#Twig)
1416
1434
  **Access**: private
@@ -1510,7 +1528,7 @@ Generic error for unsupported condition
1510
1528
 
1511
1529
  ## SAX
1512
1530
  **Kind**: global constant
1513
- **Version:**: 1.9.1
1531
+ **Version:**: 1.9.3
1514
1532
  **Author:**: Wernfried Domscheit
1515
1533
  **Copyright:**: Copyright (c) 2025 Wernfried Domscheit. All rights reserved.
1516
1534
  **Website:**: https://www.npmjs.com/package/xml-twig
@@ -1593,7 +1611,9 @@ Optional settings for the Twig parser
1593
1611
  <a name="TwigHandler"></a>
1594
1612
 
1595
1613
  ## TwigHandler
1596
- Reference to handler functions for Twig objects.<br>
1614
+ Reference to handler functions for Twig objects.<br>
1615
+ Element can be specified as string, Regular Expression, custom function, `Twig.Root` or `Twig.Any`<br>
1616
+ You can specify a `function` or a `event` name
1597
1617
 
1598
1618
  **Kind**: global typedef
1599
1619
  **Properties**
@@ -1607,7 +1627,13 @@ Reference to handler functions for Twig objects.<br>
1607
1627
  <a name="HandlerCondition"></a>
1608
1628
 
1609
1629
  ## 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)
1610
- Condition to specify when handler shall be called<br>
1611
- If `string` then the element name must be equal to the string
1612
- If `string[]` then the element name must be included in string array
1613
- If `RegExp` then the element name must match the Regular Expression
1614
- If [HandlerConditionFilter](#HandlerConditionFilter) then function must return `true`
1615
- Use `Twig.Root` to call the handler on root element, i.e. when the end of document is reached
1616
- Use `Twig.Any` to call the handler on every element
1630
+ Condition to specify when handler shall be called<br>
1631
+ - If `string` then the element name must be equal to the string
1632
+ - If `string[]` then the element name must be included in string array
1633
+ - If `RegExp` then the element name must match the Regular Expression
1634
+ - If [HandlerConditionFilter](#HandlerConditionFilter) then function must return `true`
1635
+ - Use `Twig.Root` to call the handler on root element, i.e. when the end of document is reached
1636
+ - Use `Twig.Any` to call the handler on every element
1617
1637
 
1618
1638
  **Kind**: global typedef
1619
1639
  <a name="HandlerFunction"></a>
@@ -1636,7 +1662,12 @@ Custom filter function to specify when handler shall be called
1636
1662
  <a name="ElementCondition"></a>
1637
1663
 
1638
1664
  ## ElementCondition : <code>string</code> \| <code>RegExp</code> \| [<code>ElementConditionFilter</code>](#ElementConditionFilter) \| [<code>Twig</code>](#Twig) \| <code>undefined</code>
1639
- Optional condition to get elements<br>
1640
- If `undefined`, then all elements are returned.<br>
1641
- If `string` then the element name must be equal to the string
1642
- If `RegExp` then the element name must match the Regular Expression
1643
- If [ElementConditionFilter](#ElementConditionFilter) then function must return `true`
1644
- Use [Twig](#Twig) object to find a specific element
1665
+ Optional condition to get elements<br>
1666
+ - If `undefined`, then all elements are returned.<br>
1667
+ - If `string` then the element name must be equal to the string
1668
+ - If `RegExp` then the element name must match the Regular Expression
1669
+ - If [ElementConditionFilter](#ElementConditionFilter) then function must return `true`
1670
+ - Use [Twig](#Twig) object to find a specific element
1645
1671
 
1646
1672
  **Kind**: global typedef
1647
1673
  <a name="ElementConditionFilter"></a>
@@ -1670,7 +1701,11 @@ Custom filter function to select desired elements
1670
1701
  <a name="AttributeCondition"></a>
1671
1702
 
1672
1703
  ## AttributeCondition : <code>string</code> \| <code>RegExp</code> \| [<code>AttributeConditionFilter</code>](#AttributeConditionFilter)
1673
- Optional condition to get attributes<br>
1674
- If `undefined`, then all attributes are returned.<br>
1675
- If `string` then the attribute name must be equal to the string
1676
- If `RegExp` then the attribute name must match the Regular Expression
1677
- If [AttributeConditionFilter](#AttributeConditionFilter) then the attribute must filter function
1704
+ Optional condition to get attributes<br>
1705
+ - If `undefined`, then all attributes are returned.<br>
1706
+ - If `string` then the attribute name must be equal to the string
1707
+ - If `RegExp` then the attribute name must match the Regular Expression
1708
+ - If [AttributeConditionFilter](#AttributeConditionFilter) then the attribute must filter function
1678
1709
 
1679
1710
  **Kind**: global typedef
1680
1711
  <a name="AttributeConditionFilter"></a>
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "name": "xml-twig",
7
7
  "description": "Node module for processing huge XML documents in tree mode",
8
- "version": "1.9.1",
8
+ "version": "1.9.3",
9
9
  "main": "twig.js",
10
10
  "directories": {
11
11
  "doc": "doc"
@@ -15,8 +15,8 @@
15
15
  "doc/*.md"
16
16
  ],
17
17
  "devDependencies": {
18
- "jsdoc-to-markdown": "^9.1.1",
19
- "luxon": "^3.6.1",
18
+ "jsdoc-to-markdown": "^9.1.3",
19
+ "luxon": "^3.7.2",
20
20
  "node-expat": "^2.4.1"
21
21
  },
22
22
  "scripts": {
package/twig.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @version: 1.9.1
2
+ * @version: 1.9.3
3
3
  * @author: Wernfried Domscheit
4
4
  * @copyright: Copyright (c) 2025 Wernfried Domscheit. All rights reserved.
5
5
  * @website: https://www.npmjs.com/package/xml-twig