jtlt 0.4.0 → 0.6.0
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/CHANGES.md +16 -0
- package/demo/index.css +4 -0
- package/demo/index.html +4 -4
- package/demo/index.js +6 -2
- package/demo/vendor/fontoxpath/dist/fontoxpath.esm.js +600 -0
- package/demo/vendor/prsc/dist/prsc.esm.js +2 -0
- package/demo/vendor/whynot/dist/whynot.esm.js +2 -0
- package/demo/vendor/xspattern/dist/xspattern.esm.js +2 -0
- package/dist/AbstractJoiningTransformer.d.ts +35 -0
- package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
- package/dist/DOMJoiningTransformer.d.ts +85 -8
- package/dist/DOMJoiningTransformer.d.ts.map +1 -1
- package/dist/JSONJoiningTransformer.d.ts +28 -10
- package/dist/JSONJoiningTransformer.d.ts.map +1 -1
- package/dist/JSONPathTransformer.d.ts.map +1 -1
- package/dist/JSONPathTransformerContext.d.ts +168 -3
- package/dist/JSONPathTransformerContext.d.ts.map +1 -1
- package/dist/StringJoiningTransformer.d.ts +25 -8
- package/dist/StringJoiningTransformer.d.ts.map +1 -1
- package/dist/XPathTransformer.d.ts.map +1 -1
- package/dist/XPathTransformerContext.d.ts +107 -1
- package/dist/XPathTransformerContext.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/docs/TO-DO.md +38 -36
- package/package.json +6 -2
- package/src/AbstractJoiningTransformer.js +53 -0
- package/src/DOMJoiningTransformer.js +199 -24
- package/src/JSONJoiningTransformer.js +89 -27
- package/src/JSONPathTransformer.js +2 -0
- package/src/JSONPathTransformerContext.js +572 -9
- package/src/StringJoiningTransformer.js +60 -22
- package/src/XPathTransformer.js +2 -0
- package/src/XPathTransformerContext.js +487 -11
- package/src/index.js +7 -1
|
@@ -13,7 +13,8 @@ import AbstractJoiningTransformer from './AbstractJoiningTransformer.js';
|
|
|
13
13
|
* mediaType?: string,
|
|
14
14
|
* version?: string,
|
|
15
15
|
* standalone?: boolean,
|
|
16
|
-
* method?: "xml"|"html"|"text"|"json"|"xhtml"
|
|
16
|
+
* method?: "xml"|"html"|"text"|"json"|"xhtml",
|
|
17
|
+
* useCharacterMaps?: string[]
|
|
17
18
|
* }} OutputConfig
|
|
18
19
|
*/
|
|
19
20
|
|
|
@@ -172,6 +173,16 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
172
173
|
return this;
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Alias for propValue(). Set a key-value pair in the current map/object.
|
|
178
|
+
* @param {string} prop - Property name
|
|
179
|
+
* @param {any} val - Property value
|
|
180
|
+
* @returns {StringJoiningTransformer}
|
|
181
|
+
*/
|
|
182
|
+
mapEntry (prop, val) {
|
|
183
|
+
return this.propValue(prop, val);
|
|
184
|
+
}
|
|
185
|
+
|
|
175
186
|
/**
|
|
176
187
|
* @param {string} prop - Property name
|
|
177
188
|
* @param {(this: StringJoiningTransformer) => void} cb - Callback function
|
|
@@ -257,6 +268,18 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
257
268
|
return this;
|
|
258
269
|
}
|
|
259
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Alias for object(). Build an object/map.
|
|
273
|
+
* @param {Record<string, unknown>|Element} obj - Object to serialize
|
|
274
|
+
* @param {(this: StringJoiningTransformer) => void} cb - Callback function
|
|
275
|
+
* @param {any[]} [usePropertySets] - Property sets to use
|
|
276
|
+
* @param {Record<string, unknown>} [propSets] - Additional property sets
|
|
277
|
+
* @returns {StringJoiningTransformer}
|
|
278
|
+
*/
|
|
279
|
+
map (obj, cb, usePropertySets, propSets) {
|
|
280
|
+
return this.object(obj, cb, usePropertySets, propSets);
|
|
281
|
+
}
|
|
282
|
+
|
|
260
283
|
/**
|
|
261
284
|
* @param {any[]|Element} [arr] - Array to serialize
|
|
262
285
|
* @param {(this: StringJoiningTransformer) => void} [cb] - Callback function
|
|
@@ -434,28 +457,15 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
434
457
|
return this;
|
|
435
458
|
}
|
|
436
459
|
|
|
437
|
-
/**
|
|
438
|
-
* @param {OutputConfig} cfg
|
|
439
|
-
* @returns {StringJoiningTransformer}
|
|
440
|
-
*/
|
|
441
|
-
output (cfg) {
|
|
442
|
-
// We wait until first element is set in `element()` to add
|
|
443
|
-
// XML declaration and DOCTYPE as latter depends on root element
|
|
444
|
-
this._outputConfig = cfg;
|
|
445
|
-
|
|
446
|
-
// Use for file extension if making downloadable?
|
|
447
|
-
this.mediaType = cfg.mediaType;
|
|
448
|
-
return this;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
460
|
/**
|
|
452
461
|
* @param {string|Element} elName - Element name or element object
|
|
453
462
|
* @param {ElementAttributes} [atts] - Element attributes
|
|
454
463
|
* @param {any[]} [childNodes] - Child nodes
|
|
455
464
|
* @param {(this: StringJoiningTransformer) => void} [cb] - Callback function
|
|
465
|
+
* @param {string[]} [useAttributeSets] - Attribute set names to apply
|
|
456
466
|
* @returns {StringJoiningTransformer}
|
|
457
467
|
*/
|
|
458
|
-
element (elName, atts, childNodes, cb) {
|
|
468
|
+
element (elName, atts, childNodes, cb, useAttributeSets) {
|
|
459
469
|
// If a parent element's start tag is still open, close it before
|
|
460
470
|
// starting a new element to ensure valid nesting.
|
|
461
471
|
if (this._openTagState) {
|
|
@@ -554,6 +564,17 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
554
564
|
elName = elObj.nodeName;
|
|
555
565
|
}
|
|
556
566
|
|
|
567
|
+
// Apply attribute sets if specified
|
|
568
|
+
if (useAttributeSets && useAttributeSets.length) {
|
|
569
|
+
const mergedAtts = {};
|
|
570
|
+
useAttributeSets.forEach((setName) => {
|
|
571
|
+
if (this._attributeSet[setName]) {
|
|
572
|
+
Object.assign(mergedAtts, this._attributeSet[setName]);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
atts = Object.assign(mergedAtts, atts);
|
|
576
|
+
}
|
|
577
|
+
|
|
557
578
|
this.append('<' + elName);
|
|
558
579
|
/** @type {any} */
|
|
559
580
|
const oldTagState = this._openTagState;
|
|
@@ -570,7 +591,9 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
570
591
|
}
|
|
571
592
|
if (childNodes && childNodes.length) {
|
|
572
593
|
this._openTagState = false;
|
|
573
|
-
this.append(
|
|
594
|
+
this.append(this._replaceCharacterMaps(
|
|
595
|
+
jml[method]({'#': childNodes})
|
|
596
|
+
));
|
|
574
597
|
}
|
|
575
598
|
cb.call(this);
|
|
576
599
|
|
|
@@ -585,6 +608,17 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
585
608
|
return this;
|
|
586
609
|
}
|
|
587
610
|
|
|
611
|
+
/**
|
|
612
|
+
* @param {string} prefix
|
|
613
|
+
* @param {string} namespaceURI
|
|
614
|
+
* @returns {StringJoiningTransformer}
|
|
615
|
+
*/
|
|
616
|
+
namespace (prefix, namespaceURI) {
|
|
617
|
+
this.append(' xmlns:' + prefix + '="' +
|
|
618
|
+
this._replaceCharacterMaps(namespaceURI) + '"');
|
|
619
|
+
return this;
|
|
620
|
+
}
|
|
621
|
+
|
|
588
622
|
/**
|
|
589
623
|
* @param {string} name - Attribute name
|
|
590
624
|
* @param {string|Record<string, unknown>|
|
|
@@ -648,7 +682,7 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
648
682
|
val = (this._cfg.preEscapedAttributes || avoidAttEscape)
|
|
649
683
|
? valStr
|
|
650
684
|
: valStr.replaceAll('&', '&').replaceAll('"', '"');
|
|
651
|
-
this.append(' ' + name + '="' + val + '"');
|
|
685
|
+
this.append(' ' + name + '="' + this._replaceCharacterMaps(val) + '"');
|
|
652
686
|
return this;
|
|
653
687
|
}
|
|
654
688
|
|
|
@@ -663,7 +697,11 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
663
697
|
this.append('>');
|
|
664
698
|
this._openTagState = false;
|
|
665
699
|
}
|
|
666
|
-
this.append(
|
|
700
|
+
this.append(
|
|
701
|
+
this._replaceCharacterMaps(
|
|
702
|
+
txt
|
|
703
|
+
).replaceAll('&', '&').replaceAll('<', '<')
|
|
704
|
+
);
|
|
667
705
|
return this;
|
|
668
706
|
}
|
|
669
707
|
|
|
@@ -734,7 +772,7 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
734
772
|
// Save current state
|
|
735
773
|
/** @type {any} */
|
|
736
774
|
const oldRoot = this.root;
|
|
737
|
-
/** @type {
|
|
775
|
+
/** @type {OutputConfig|undefined} */
|
|
738
776
|
const oldOutputConfig = this._outputConfig;
|
|
739
777
|
const oldStr = this._str;
|
|
740
778
|
/** @type {any} */
|
|
@@ -742,7 +780,7 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
742
780
|
|
|
743
781
|
// Reset state for new document
|
|
744
782
|
this.root = undefined;
|
|
745
|
-
/** @type {
|
|
783
|
+
/** @type {OutputConfig} */
|
|
746
784
|
this._outputConfig = cfg;
|
|
747
785
|
this._str = '';
|
|
748
786
|
this._openTagState = false;
|
|
@@ -795,7 +833,7 @@ class StringJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
795
833
|
|
|
796
834
|
// Reset state for new document
|
|
797
835
|
this.root = undefined;
|
|
798
|
-
/** @type {
|
|
836
|
+
/** @type {OutputConfig} */
|
|
799
837
|
this._outputConfig = cfg;
|
|
800
838
|
this._str = '';
|
|
801
839
|
this._openTagState = false;
|
package/src/XPathTransformer.js
CHANGED
|
@@ -83,6 +83,8 @@ class XPathTransformer {
|
|
|
83
83
|
if (len > 1) {
|
|
84
84
|
this._triggerEqualPriorityError();
|
|
85
85
|
}
|
|
86
|
+
// Set up parameter context for valueOf() access in root template
|
|
87
|
+
xte._params = {0: xte._contextNode};
|
|
86
88
|
const ret = templateObj.template.call(xte, undefined, {mode});
|
|
87
89
|
if (typeof ret !== 'undefined') {
|
|
88
90
|
/** @type {any} */ (xte)._getJoiningTransformer().append(ret);
|