xml-twig 1.2.86 → 1.2.90

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 (4) hide show
  1. package/doc/twig.md +50 -99
  2. package/package.json +38 -38
  3. package/twig.js +28 -28
  4. package/twig.md +0 -0
package/doc/twig.md CHANGED
@@ -112,12 +112,12 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
112
112
  * [Twig](#Twig)
113
113
  * [new Twig()](#new_Twig_new)
114
114
  * [new Twig(name, [parent], [attributes], [index])](#new_Twig_new)
115
- * [.attributes](#Twig+attributes) ℗
116
- * [.text](#Twig+text) ℗
117
- * [.name](#Twig+name) ℗
118
- * [.children](#Twig+children) ℗
119
- * [.parent](#Twig+parent) ℗
120
- * [.pinned](#Twig+pinned) ℗
115
+ * [.attributes](#Twig+attributes) : <code>object</code>
116
+ * [.text](#Twig+text) : <code>string</code> \| <code>number</code>
117
+ * [.name](#Twig+name) : <code>string</code>
118
+ * [.children](#Twig+children) : [<code>Array.&lt;Twig&gt;</code>](#Twig)
119
+ * [.parent](#Twig+parent) : [<code>Twig</code>](#Twig) \| <code>undefined</code>
120
+ * [.pinned](#Twig+pinned) : <code>boolean</code>
121
121
  * [.purge](#Twig+purge)
122
122
  * [.purgeUpTo](#Twig+purgeUpTo)
123
123
  * [.escapeEntity](#Twig+escapeEntity)
@@ -187,70 +187,46 @@ Create a new Twig object
187
187
 
188
188
  <a name="Twig+attributes"></a>
189
189
 
190
- ### twig.attributes ℗
190
+ ### twig.attributes : <code>object</code>
191
+ XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }`
192
+
191
193
  **Kind**: instance property of [<code>Twig</code>](#Twig)
192
194
  **Access**: private
193
- **Properties**
194
-
195
- | Name | Type | Description |
196
- | --- | --- | --- |
197
- | #attributes | <code>object</code> | XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }` |
198
-
199
195
  <a name="Twig+text"></a>
200
196
 
201
- ### twig.text ℗
197
+ ### twig.text : <code>string</code> \| <code>number</code>
198
+ Content of XML Element
199
+
202
200
  **Kind**: instance property of [<code>Twig</code>](#Twig)
203
201
  **Access**: private
204
- **Properties**
205
-
206
- | Name | Type | Description |
207
- | --- | --- | --- |
208
- | #text | <code>string</code> \| <code>number</code> | Content of XML Element |
209
-
210
202
  <a name="Twig+name"></a>
211
203
 
212
- ### twig.name ℗
204
+ ### twig.name : <code>string</code>
205
+ The XML tag name
206
+
213
207
  **Kind**: instance property of [<code>Twig</code>](#Twig)
214
208
  **Access**: private
215
- **Properties**
216
-
217
- | Name | Type | Description |
218
- | --- | --- | --- |
219
- | #name | <code>string</code> | The XML tag name |
220
-
221
209
  <a name="Twig+children"></a>
222
210
 
223
- ### twig.children ℗
211
+ ### twig.children : [<code>Array.&lt;Twig&gt;</code>](#Twig)
212
+ Child XML Elements
213
+
224
214
  **Kind**: instance property of [<code>Twig</code>](#Twig)
225
215
  **Access**: private
226
- **Properties**
227
-
228
- | Name | Type | Description |
229
- | --- | --- | --- |
230
- | #children | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Child XML Elements |
231
-
232
216
  <a name="Twig+parent"></a>
233
217
 
234
- ### twig.parent ℗
218
+ ### twig.parent : [<code>Twig</code>](#Twig) \| <code>undefined</code>
219
+ The parent object. Undefined on root element
220
+
235
221
  **Kind**: instance property of [<code>Twig</code>](#Twig)
236
222
  **Access**: private
237
- **Properties**
238
-
239
- | Name | Type | Description |
240
- | --- | --- | --- |
241
- | #parent | [<code>Twig</code>](#Twig) | The parent object. Undefined on root element |
242
-
243
223
  <a name="Twig+pinned"></a>
244
224
 
245
- ### twig.pinned ℗
225
+ ### twig.pinned : <code>boolean</code>
226
+ Determines whether twig is needed in partial load
227
+
246
228
  **Kind**: instance property of [<code>Twig</code>](#Twig)
247
229
  **Access**: private
248
- **Properties**
249
-
250
- | Name | Type | Description |
251
- | --- | --- | --- |
252
- | #pinned | <code>boolean</code> | Determines whether twig is needed in partial load |
253
-
254
230
  <a name="Twig+purge"></a>
255
231
 
256
232
  ### twig.purge
@@ -745,12 +721,12 @@ Common function to filter Twig element
745
721
  * [Twig](#Twig)
746
722
  * [new Twig()](#new_Twig_new)
747
723
  * [new Twig(name, [parent], [attributes], [index])](#new_Twig_new)
748
- * [.attributes](#Twig+attributes) ℗
749
- * [.text](#Twig+text) ℗
750
- * [.name](#Twig+name) ℗
751
- * [.children](#Twig+children) ℗
752
- * [.parent](#Twig+parent) ℗
753
- * [.pinned](#Twig+pinned) ℗
724
+ * [.attributes](#Twig+attributes) : <code>object</code>
725
+ * [.text](#Twig+text) : <code>string</code> \| <code>number</code>
726
+ * [.name](#Twig+name) : <code>string</code>
727
+ * [.children](#Twig+children) : [<code>Array.&lt;Twig&gt;</code>](#Twig)
728
+ * [.parent](#Twig+parent) : [<code>Twig</code>](#Twig) \| <code>undefined</code>
729
+ * [.pinned](#Twig+pinned) : <code>boolean</code>
754
730
  * [.purge](#Twig+purge)
755
731
  * [.purgeUpTo](#Twig+purgeUpTo)
756
732
  * [.escapeEntity](#Twig+escapeEntity)
@@ -820,70 +796,46 @@ Create a new Twig object
820
796
 
821
797
  <a name="Twig+attributes"></a>
822
798
 
823
- ### twig.attributes ℗
799
+ ### twig.attributes : <code>object</code>
800
+ XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }`
801
+
824
802
  **Kind**: instance property of [<code>Twig</code>](#Twig)
825
803
  **Access**: private
826
- **Properties**
827
-
828
- | Name | Type | Description |
829
- | --- | --- | --- |
830
- | #attributes | <code>object</code> | XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }` |
831
-
832
804
  <a name="Twig+text"></a>
833
805
 
834
- ### twig.text ℗
806
+ ### twig.text : <code>string</code> \| <code>number</code>
807
+ Content of XML Element
808
+
835
809
  **Kind**: instance property of [<code>Twig</code>](#Twig)
836
810
  **Access**: private
837
- **Properties**
838
-
839
- | Name | Type | Description |
840
- | --- | --- | --- |
841
- | #text | <code>string</code> \| <code>number</code> | Content of XML Element |
842
-
843
811
  <a name="Twig+name"></a>
844
812
 
845
- ### twig.name ℗
813
+ ### twig.name : <code>string</code>
814
+ The XML tag name
815
+
846
816
  **Kind**: instance property of [<code>Twig</code>](#Twig)
847
817
  **Access**: private
848
- **Properties**
849
-
850
- | Name | Type | Description |
851
- | --- | --- | --- |
852
- | #name | <code>string</code> | The XML tag name |
853
-
854
818
  <a name="Twig+children"></a>
855
819
 
856
- ### twig.children ℗
820
+ ### twig.children : [<code>Array.&lt;Twig&gt;</code>](#Twig)
821
+ Child XML Elements
822
+
857
823
  **Kind**: instance property of [<code>Twig</code>](#Twig)
858
824
  **Access**: private
859
- **Properties**
860
-
861
- | Name | Type | Description |
862
- | --- | --- | --- |
863
- | #children | [<code>Array.&lt;Twig&gt;</code>](#Twig) | Child XML Elements |
864
-
865
825
  <a name="Twig+parent"></a>
866
826
 
867
- ### twig.parent ℗
827
+ ### twig.parent : [<code>Twig</code>](#Twig) \| <code>undefined</code>
828
+ The parent object. Undefined on root element
829
+
868
830
  **Kind**: instance property of [<code>Twig</code>](#Twig)
869
831
  **Access**: private
870
- **Properties**
871
-
872
- | Name | Type | Description |
873
- | --- | --- | --- |
874
- | #parent | [<code>Twig</code>](#Twig) | The parent object. Undefined on root element |
875
-
876
832
  <a name="Twig+pinned"></a>
877
833
 
878
- ### twig.pinned ℗
834
+ ### twig.pinned : <code>boolean</code>
835
+ Determines whether twig is needed in partial load
836
+
879
837
  **Kind**: instance property of [<code>Twig</code>](#Twig)
880
838
  **Access**: private
881
- **Properties**
882
-
883
- | Name | Type | Description |
884
- | --- | --- | --- |
885
- | #pinned | <code>boolean</code> | Determines whether twig is needed in partial load |
886
-
887
839
  <a name="Twig+purge"></a>
888
840
 
889
841
  ### twig.purge
@@ -1468,7 +1420,7 @@ Optional settings for the Twig parser
1468
1420
 
1469
1421
  | Name | Type | Description |
1470
1422
  | --- | --- | --- |
1471
- | [method] | <code>string</code> | The underlying parser. Either `'sax'` or `'expat'`. |
1423
+ | [method] | <code>&#x27;sax&#x27;</code> \| <code>&#x27;expat&#x27;</code> | The underlying parser. Either `'sax'` or `'expat'`. |
1472
1424
  | [encoding] | <code>string</code> | Encoding of the XML File. Applies only to `expat` parser. |
1473
1425
  | [xmlns] | <code>boolean</code> | If `true`, then namespaces are accessible by `namespace` property. |
1474
1426
  | [trim] | <code>boolean</code> | If `true`, then turn any whitespace into a single space. Text and comments are trimmed. |
@@ -1517,9 +1469,8 @@ Custom filter function to specify when handler shall be called
1517
1469
 
1518
1470
  **Kind**: global typedef
1519
1471
  **Returns**: <code>boolean</code> - If the function returns `true`, then it is included in the filter
1520
- **Properties**
1521
1472
 
1522
- | Name | Type | Description |
1473
+ | Param | Type | Description |
1523
1474
  | --- | --- | --- |
1524
1475
  | name | <code>string</code> | Name of the element |
1525
1476
 
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "dependencies": {
3
- "sax": "^1.3.0",
4
- "xml-writer": "^1.7.0"
5
- },
6
- "name": "xml-twig",
7
- "description": "Node module for processing huge XML documents in tree mode",
8
- "version": "1.2.86",
9
- "main": "twig.js",
10
- "directories": {
11
- "doc": "doc"
12
- },
13
- "devDependencies": {
14
- "jsdoc-to-markdown": "^8.0.0",
15
- "luxon": "^2.1.1",
16
- "node-expat": "^2.4.0"
17
- },
18
- "scripts": {
19
- "test": "node demo.js"
20
- },
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/Wernfried/xml-twig.git"
24
- },
25
- "keywords": [
26
- "xml",
27
- "sax",
28
- "expat",
29
- "parser",
30
- "xml-reader"
31
- ],
32
- "author": "Wernfried Domscheit",
33
- "license": "ISC",
34
- "bugs": {
35
- "url": "https://github.com/Wernfried/xml-twig/issues"
36
- },
37
- "homepage": "https://github.com/Wernfried/xml-twig#readme"
38
- }
1
+ {
2
+ "dependencies": {
3
+ "sax": "^1.3.0",
4
+ "xml-writer": "^1.7.0"
5
+ },
6
+ "name": "xml-twig",
7
+ "description": "Node module for processing huge XML documents in tree mode",
8
+ "version": "1.2.90",
9
+ "main": "twig.js",
10
+ "directories": {
11
+ "doc": "doc"
12
+ },
13
+ "devDependencies": {
14
+ "jsdoc-to-markdown": "^8.0.0",
15
+ "luxon": "^2.1.1",
16
+ "node-expat": "^2.4.0"
17
+ },
18
+ "scripts": {
19
+ "test": "node demo.js"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Wernfried/xml-twig.git"
24
+ },
25
+ "keywords": [
26
+ "xml",
27
+ "sax",
28
+ "expat",
29
+ "parser",
30
+ "xml-reader"
31
+ ],
32
+ "author": "Wernfried Domscheit",
33
+ "license": "ISC",
34
+ "bugs": {
35
+ "url": "https://github.com/Wernfried/xml-twig/issues"
36
+ },
37
+ "homepage": "https://github.com/Wernfried/xml-twig#readme"
38
+ }
package/twig.js CHANGED
@@ -26,7 +26,7 @@ const Any = new AnyHandler();
26
26
  /**
27
27
  * Optional settings for the Twig parser
28
28
  * @typedef ParserOptions
29
- * @property {string} [method] - The underlying parser. Either `'sax'` or `'expat'`.
29
+ * @property {'sax' | 'expat'} [method] - The underlying parser. Either `'sax'` or `'expat'`.
30
30
  * @property {string} [encoding] - Encoding of the XML File. Applies only to `expat` parser.
31
31
  * @property {boolean} [xmlns] - If `true`, then namespaces are accessible by `namespace` property.
32
32
  * @property {boolean} [trim] - If `true`, then turn any whitespace into a single space. Text and comments are trimmed.
@@ -41,9 +41,9 @@ const Any = new AnyHandler();
41
41
  * Element can be specified as string, Regular Expression, custom function, `Twig.Root` or `Twig.Any`<br>
42
42
  * You can specify a `function` or a `event` name
43
43
  * @typedef TwigHandler
44
- * @property {?HandlerCondition} tag - Element specification
44
+ * @property {HandlerCondition} tag - Element specification
45
45
  * @property {HandlerFunction} [function] - Definition of handler function, either anonymous or explicit function
46
- * @property {?string} [event] - Type of the event to be emitted
46
+ * @property {string} [event] - Type of the event to be emitted
47
47
  */
48
48
 
49
49
  /**
@@ -65,8 +65,8 @@ const Any = new AnyHandler();
65
65
 
66
66
  /**
67
67
  * Custom filter function to specify when handler shall be called
68
- * @typedef HandlerConditionFilter
69
- * @property {string} name - Name of the element
68
+ * @typedef {function} HandlerConditionFilter
69
+ * @param {string} name - Name of the element
70
70
  * @returns {boolean} If the function returns `true`, then it is included in the filter
71
71
  */
72
72
 
@@ -103,8 +103,8 @@ function createParser(handler, options) {
103
103
  let closeEvent;
104
104
 
105
105
  if (options.partial) {
106
- let hndl = Array.isArray(handler) ? handler : [handler];
107
- let any = hndl.find(x => x.tag instanceof AnyHandler);
106
+ const handle1 = Array.isArray(handler) ? handler : [handler];
107
+ let any = handle1.find(x => x.tag instanceof AnyHandler);
108
108
  if (any !== undefined)
109
109
  console.warn(`Using option '{ partial: true }' and handler '{ tag: Any, function: ${any.function.toString()} }' does not make much sense`);
110
110
  }
@@ -391,38 +391,38 @@ class Twig {
391
391
  */
392
392
 
393
393
  /**
394
- * @property {?object} #attributes - XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }`
395
- * @private
394
+ * XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }`
395
+ * @type {?object}
396
396
  */
397
397
  #attributes = {};
398
398
 
399
399
  /**
400
- * @property {?string|number} #text - Content of XML Element
401
- * @private
400
+ * Content of XML Element
401
+ * @type {?string|number}
402
402
  */
403
403
  #text = null;
404
404
 
405
405
  /**
406
- * @property {string} #name - The XML tag name
407
- * @private
406
+ * The XML tag name
407
+ * @type {string}
408
408
  */
409
409
  #name;
410
410
 
411
411
  /**
412
- * @property {?Twig[]} #children - Child XML Elements
413
- * @private
412
+ * Child XML Elements
413
+ * @type {Twig[]}
414
414
  */
415
415
  #children = [];
416
416
 
417
417
  /**
418
- * @property {?Twig} #parent - The parent object. Undefined on root element
419
- * @private
418
+ * The parent object. Undefined on root element
419
+ * @type {Twig | undefined}
420
420
  */
421
421
  #parent;
422
422
 
423
423
  /**
424
- * @property {boolean} #pinned - Determines whether twig is needed in partial load
425
- * @private
424
+ * Determines whether twig is needed in partial load
425
+ * @type {boolean}
426
426
  */
427
427
  #pinned = false;
428
428
 
@@ -482,14 +482,14 @@ class Twig {
482
482
  if (elt === undefined) {
483
483
  this.purge();
484
484
  } else {
485
- let purgeThis = this.descendantOrSelf();
486
- purgeThis = purgeThis[purgeThis.length - 1];
487
- let stopAt = elt.descendantOrSelf();
488
- stopAt = stopAt[stopAt.length - 1];
489
- while (purgeThis !== null && !Object.is(purgeThis, stopAt)) {
490
- let prev = purgeThis.previous();
491
- purgeThis.purge();
492
- purgeThis = prev;
485
+ const purgeThis = this.descendantOrSelf();
486
+ let toPurge = purgeThis[purgeThis.length - 1];
487
+ const descendantOrSelf = elt.descendantOrSelf();
488
+ const stopAt = descendantOrSelf[descendantOrSelf.length - 1];
489
+ while (toPurge !== null && !Object.is(toPurge, stopAt)) {
490
+ const prev = toPurge.previous();
491
+ toPurge.purge();
492
+ toPurge = prev;
493
493
  }
494
494
  }
495
495
  };
@@ -784,7 +784,7 @@ class Twig {
784
784
  if (typeof condition === 'string') {
785
785
  return elements.filter(x => x.name === condition);
786
786
  } else if (condition instanceof RegExp) {
787
- return elements.filter(x => x.condition.test(x.name));
787
+ return elements.filter(x => condition.test(x.name));
788
788
  } else if (condition instanceof Twig) {
789
789
  return elements.filter(x => Object.is(x, condition));
790
790
  } else if (typeof condition === 'function') {
package/twig.md DELETED
File without changes