xml-twig 1.2.88 → 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.
- package/doc/twig.md +49 -97
- package/package.json +1 -1
- package/twig.js +24 -24
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.<Twig></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.<Twig></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.<Twig></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.<Twig></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.<Twig></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.<Twig></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>
|
|
1423
|
+
| [method] | <code>'sax'</code> \| <code>'expat'</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. |
|
package/package.json
CHANGED
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 {
|
|
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.
|
|
@@ -103,8 +103,8 @@ function createParser(handler, options) {
|
|
|
103
103
|
let closeEvent;
|
|
104
104
|
|
|
105
105
|
if (options.partial) {
|
|
106
|
-
|
|
107
|
-
let any =
|
|
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
|
-
|
|
395
|
-
* @
|
|
394
|
+
* XML attribute `{ <attribute 1>: <value 1>, <attribute 2>: <value 2>, ... }`
|
|
395
|
+
* @type {?object}
|
|
396
396
|
*/
|
|
397
397
|
#attributes = {};
|
|
398
398
|
|
|
399
399
|
/**
|
|
400
|
-
|
|
401
|
-
* @
|
|
400
|
+
* Content of XML Element
|
|
401
|
+
* @type {?string|number}
|
|
402
402
|
*/
|
|
403
403
|
#text = null;
|
|
404
404
|
|
|
405
405
|
/**
|
|
406
|
-
|
|
407
|
-
* @
|
|
406
|
+
* The XML tag name
|
|
407
|
+
* @type {string}
|
|
408
408
|
*/
|
|
409
409
|
#name;
|
|
410
410
|
|
|
411
411
|
/**
|
|
412
|
-
|
|
413
|
-
* @
|
|
412
|
+
* Child XML Elements
|
|
413
|
+
* @type {Twig[]}
|
|
414
414
|
*/
|
|
415
415
|
#children = [];
|
|
416
416
|
|
|
417
417
|
/**
|
|
418
|
-
|
|
419
|
-
* @
|
|
418
|
+
* The parent object. Undefined on root element
|
|
419
|
+
* @type {Twig | undefined}
|
|
420
420
|
*/
|
|
421
421
|
#parent;
|
|
422
422
|
|
|
423
423
|
/**
|
|
424
|
-
|
|
425
|
-
* @
|
|
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
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
stopAt =
|
|
489
|
-
while (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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 =>
|
|
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') {
|