xml-twig 1.9.0 → 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 +21 -3
  2. package/package.json +3 -3
  3. package/twig.js +21 -4
package/doc/twig.md CHANGED
@@ -127,6 +127,7 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
127
127
  * [.children](#Twig+children) : [<code>Array.&lt;Twig&gt;</code>](#Twig) ℗
128
128
  * [.parent](#Twig+parent) : [<code>Twig</code>](#Twig) \| <code>undefined</code> ℗
129
129
  * [.pinned](#Twig+pinned) : <code>boolean</code> ℗
130
+ * [.trim](#Twig+trim) : <code>boolean</code> ℗
130
131
  * [.purge](#Twig+purge)
131
132
  * [.purgeUpTo](#Twig+purgeUpTo)
132
133
  * [.escapeEntity](#Twig+escapeEntity)
@@ -240,6 +241,13 @@ The parent object. Undefined on root element
240
241
  ### twig.pinned : <code>boolean</code> ℗
241
242
  Determines whether twig is needed in partial load
242
243
 
244
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
245
+ **Access**: private
246
+ <a name="Twig+trim"></a>
247
+
248
+ ### twig.trim : <code>boolean</code> ℗
249
+ Determines whether text is trimmed
250
+
243
251
  **Kind**: instance property of [<code>Twig</code>](#Twig)
244
252
  **Access**: private
245
253
  <a name="Twig+purge"></a>
@@ -332,7 +340,8 @@ Returns the name of the element. Synonym for `twig.name`
332
340
  <a name="Twig+text"></a>
333
341
 
334
342
  ### twig.text ⇒ <code>string</code>
335
- 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
336
345
 
337
346
  **Kind**: instance property of [<code>Twig</code>](#Twig)
338
347
  **Returns**: <code>string</code> - Element text or empty string
@@ -793,6 +802,7 @@ Common function to filter Twig element
793
802
  * [.children](#Twig+children) : [<code>Array.&lt;Twig&gt;</code>](#Twig) ℗
794
803
  * [.parent](#Twig+parent) : [<code>Twig</code>](#Twig) \| <code>undefined</code> ℗
795
804
  * [.pinned](#Twig+pinned) : <code>boolean</code> ℗
805
+ * [.trim](#Twig+trim) : <code>boolean</code> ℗
796
806
  * [.purge](#Twig+purge)
797
807
  * [.purgeUpTo](#Twig+purgeUpTo)
798
808
  * [.escapeEntity](#Twig+escapeEntity)
@@ -906,6 +916,13 @@ The parent object. Undefined on root element
906
916
  ### twig.pinned : <code>boolean</code> ℗
907
917
  Determines whether twig is needed in partial load
908
918
 
919
+ **Kind**: instance property of [<code>Twig</code>](#Twig)
920
+ **Access**: private
921
+ <a name="Twig+trim"></a>
922
+
923
+ ### twig.trim : <code>boolean</code> ℗
924
+ Determines whether text is trimmed
925
+
909
926
  **Kind**: instance property of [<code>Twig</code>](#Twig)
910
927
  **Access**: private
911
928
  <a name="Twig+purge"></a>
@@ -998,7 +1015,8 @@ Returns the name of the element. Synonym for `twig.name`
998
1015
  <a name="Twig+text"></a>
999
1016
 
1000
1017
  ### twig.text ⇒ <code>string</code>
1001
- 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
1002
1020
 
1003
1021
  **Kind**: instance property of [<code>Twig</code>](#Twig)
1004
1022
  **Returns**: <code>string</code> - Element text or empty string
@@ -1510,7 +1528,7 @@ Generic error for unsupported condition
1510
1528
 
1511
1529
  ## SAX
1512
1530
  **Kind**: global constant
1513
- **Version:**: 1.9.0
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
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.0",
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.0
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
@@ -278,6 +278,12 @@ function createParser(handler, options = {}) {
278
278
  enumerable: true
279
279
  });
280
280
 
281
+ Object.defineProperty(parser, 'trimText', {
282
+ value: options.trim,
283
+ writable: false,
284
+ enumerable: true
285
+ });
286
+
281
287
  if (options.file != null) {
282
288
  Object.defineProperty(parser, 'file', {
283
289
  value: options.file,
@@ -289,7 +295,7 @@ function createParser(handler, options = {}) {
289
295
  // Common events
290
296
  parser.on('text', function (str) {
291
297
  if (parser.twig.current === null) return;
292
- parser.twig.current.text = options.trim ? str.trim() : str;
298
+ parser.twig.current.text = str;
293
299
  });
294
300
 
295
301
  parser.on("comment", function (str) {
@@ -513,6 +519,12 @@ class Twig {
513
519
  */
514
520
  #pinned = false;
515
521
 
522
+ /**
523
+ * Determines whether text is trimmed
524
+ * @type {boolean}
525
+ */
526
+ #trim = true;
527
+
516
528
  /**
517
529
  * Create a new Twig object
518
530
  * @param {Parser} parser - The main parser object
@@ -525,6 +537,7 @@ class Twig {
525
537
  if (index === undefined)
526
538
  parser.twig.current = this;
527
539
 
540
+ this.#trim = parser.trimText;
528
541
  if (name === null) {
529
542
  // Root element not available yet
530
543
  parser.twig.tree = this;
@@ -698,11 +711,15 @@ class Twig {
698
711
  }
699
712
 
700
713
  /**
701
- * The text of the element. No matter if given as text or CDATA entity
714
+ * The text of the element. No matter if given as text or CDATA entity.
715
+ * If option `trim: true`, then whitespace from both ends of the string are removed
702
716
  * @returns {string} Element text or empty string
703
717
  */
704
718
  get text() {
705
- return this.#text ?? '';
719
+ if (this.#text === null)
720
+ return ''
721
+ else
722
+ return this.#trim ? this.#text.trim() : this.#text;
706
723
  }
707
724
 
708
725
  /**