jtlt 0.2.0 → 0.3.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 +18 -0
- package/README.md +16 -87
- package/demo/calltemplate-params-demo.js +138 -0
- package/demo/index.html +31 -0
- package/demo/index.js +30 -0
- package/demo/xpath2-placeholder.js +1 -0
- package/dist/AbstractJoiningTransformer.d.ts +83 -9
- package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
- package/dist/DOMJoiningTransformer.d.ts +85 -25
- package/dist/DOMJoiningTransformer.d.ts.map +1 -1
- package/dist/JSONJoiningTransformer.d.ts +159 -51
- package/dist/JSONJoiningTransformer.d.ts.map +1 -1
- package/dist/JSONPathTransformer.d.ts +37 -38
- package/dist/JSONPathTransformer.d.ts.map +1 -1
- package/dist/JSONPathTransformerContext.d.ts +247 -121
- package/dist/JSONPathTransformerContext.d.ts.map +1 -1
- package/dist/StringJoiningTransformer.d.ts +132 -41
- package/dist/StringJoiningTransformer.d.ts.map +1 -1
- package/dist/XPathTransformer.d.ts +35 -20
- package/dist/XPathTransformer.d.ts.map +1 -1
- package/dist/XPathTransformerContext.d.ts +191 -99
- package/dist/XPathTransformerContext.d.ts.map +1 -1
- package/dist/index-browser.d.ts +4 -0
- package/dist/index-browser.d.ts.map +1 -0
- package/dist/index-node.d.ts +4 -0
- package/dist/index-node.d.ts.map +1 -0
- package/dist/index.d.ts +330 -57
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +204 -0
- package/dist/types.d.ts.map +1 -0
- package/docs/API.expanded.md +167 -2
- package/docs/API.md +91 -1
- package/docs/TO-DO.md +144 -0
- package/docs/calltemplate-params.md +251 -0
- package/eslint.config.js +9 -5
- package/package.json +13 -7
- package/pnpm-workspace.yaml +1 -0
- package/src/AbstractJoiningTransformer.js +54 -15
- package/src/DOMJoiningTransformer.js +275 -28
- package/src/JSONJoiningTransformer.js +351 -70
- package/src/JSONPathTransformer.js +48 -30
- package/src/JSONPathTransformerContext.js +308 -104
- package/src/StringJoiningTransformer.js +311 -57
- package/src/XPathTransformer.js +27 -12
- package/src/XPathTransformerContext.js +467 -89
- package/src/index-browser.js +5 -0
- package/src/index-node.js +7 -0
- package/src/index.js +498 -97
- package/typings/xpath2-js.d.ts +40 -1
- package/src/types/xpath2-js.d.ts +0 -2
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# jtlt CHANGES
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- feat: `if()`
|
|
6
|
+
- feat: `choose()`
|
|
7
|
+
- feat: propSets for DOM
|
|
8
|
+
- feat: add `comment()` and `processingInstruction()`
|
|
9
|
+
- feat: optional `path` may be omitted when `name` present (named-only templates)
|
|
10
|
+
- feat: XPath `copy()` (shallow) and `copyOf(select?)` (deep cloning / scalar append)
|
|
11
|
+
- feat: JSONPath cloning docs expanded (existing `copy`/`copyOf` clarified)
|
|
12
|
+
- fix: avoid appending `undefined` from `callTemplate` when template returns nothing
|
|
13
|
+
- fix: parameter fallback in `valueOf` for JSONPath param access
|
|
14
|
+
- fix: scalar XPath `copyOf()` prevents DOM hierarchy errors when expression returns Document
|
|
15
|
+
- feat: add `exposeDocuments` option
|
|
16
|
+
- feat: callTemplate in XPath
|
|
17
|
+
- feat: add `document()` (XSLT `xsl:document`-like) and `resultDocument()` (XSLT `xsl:result-document`-like) to all joiners
|
|
18
|
+
- feat: support `output({method})` values `json` and `xhtml` across joiners
|
|
19
|
+
- change: JSON joiner `$document` wrapper includes DOCTYPE only when `method` is `xml` or `xhtml`; XML declaration emitted for `xml`/`xhtml` unless `omitXmlDeclaration`
|
|
20
|
+
|
|
3
21
|
## 0.2.0
|
|
4
22
|
|
|
5
23
|
- fix: point to `types` and add `exports`
|
package/README.md
CHANGED
|
@@ -56,6 +56,15 @@ JTLT has two layers:
|
|
|
56
56
|
- DOMJoiningTransformer: Builds a DocumentFragment/Element tree. element()/attribute()/text() add real nodes; primitives append as text nodes.
|
|
57
57
|
- JSONJoiningTransformer: Builds real JS values (objects/arrays/primitives) without serialization.
|
|
58
58
|
|
|
59
|
+
### Output formats and multi-document
|
|
60
|
+
|
|
61
|
+
- Output formats supported via `output({method})`: `xml`, `html`, `text`, `xhtml`, and `json`.
|
|
62
|
+
- `xml`/`xhtml` behave like XML: XML declaration (unless omitted) and optional DOCTYPE.
|
|
63
|
+
- `html` is HTML‑centric; `text` is raw text; `json` is JSON‑centric (no XML declaration/DOCTYPE).
|
|
64
|
+
- Multi-document APIs:
|
|
65
|
+
- `document(cb, cfg?)`: Create additional documents; when a joiner is configured with `{exposeDocuments: true}`, `get()` returns an array of documents.
|
|
66
|
+
- `resultDocument(href, cb, cfg?)`: Create additional documents with metadata (`href`, `format`, and `document`) accessible on `joiner._resultDocuments`.
|
|
67
|
+
|
|
59
68
|
### Common joiner methods
|
|
60
69
|
|
|
61
70
|
- append(value): Central sink. Based on context, concatenates to string, pushes to array, or assigns to an object property.
|
|
@@ -109,7 +118,7 @@ const doc = parser.parseFromString(
|
|
|
109
118
|
'<root><item>a</item><item>b</item></root>', 'text/xml'
|
|
110
119
|
);
|
|
111
120
|
|
|
112
|
-
const joiner = new StringJoiningTransformer(''
|
|
121
|
+
const joiner = new StringJoiningTransformer('');
|
|
113
122
|
const templates = [
|
|
114
123
|
{name: 'root', path: '/', template () {
|
|
115
124
|
this.applyTemplates('//item');
|
|
@@ -427,7 +436,11 @@ Advantages (strong parallels with XSLT):
|
|
|
427
436
|
|
|
428
437
|
Differences / current limitations:
|
|
429
438
|
|
|
430
|
-
- Expression language: XPath 2.0 implementation is not fully feature complete.
|
|
439
|
+
- Expression language: XPath 2.0 implementation is not fully feature complete and the XPath 1.0 implementation from `jsdom` may not be either.
|
|
440
|
+
- As the syntax is JavaScript, it is not feasible to recursively transform
|
|
441
|
+
JTLT syntax with itself (at least not easily) as one can do with XSLT.
|
|
442
|
+
However, one can use arbitrary JavaScript, or using such as `jsep`,
|
|
443
|
+
allow a particuluar subset of JavaScript.
|
|
431
444
|
- Stylesheet composition/precedence: no `xsl:import`/`xsl:include` equivalents; only basic priority and modes.
|
|
432
445
|
- Schema awareness: no type-aware processing (a major XSLT/XQuery feature).
|
|
433
446
|
- Multi-output (`xsl:result-document`): not built-in; pick one output type per transform.
|
|
@@ -447,88 +460,4 @@ from XSLT):
|
|
|
447
460
|
|
|
448
461
|
## To-dos
|
|
449
462
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
1. Implement and demo equivalent to applying and calling templates, and
|
|
453
|
-
root template
|
|
454
|
-
|
|
455
|
-
2. Demo chaining of methods, including [equivalents](https://www.saxonica.com/papers/XTech2005/mhkpaper.html#S4.)
|
|
456
|
-
to XQuery's FLWOR expressions (see also Promises to-do), perhaps
|
|
457
|
-
even making aliases so that XQuery's friendlier terms can be used
|
|
458
|
-
instead of XSLT's.
|
|
459
|
-
|
|
460
|
-
2. Support processing of JSON documents with `$jtlt-stylesheet` to let
|
|
461
|
-
documents define their own targeted stylesheets.
|
|
462
|
-
|
|
463
|
-
3. When sufficiently documented, add as example library/tool to
|
|
464
|
-
JSONPath wiki.
|
|
465
|
-
|
|
466
|
-
4. Allow alternative to `element()`, `array()`, etc. methods by just
|
|
467
|
-
detecting those types from return values (and generic of each
|
|
468
|
-
type like `dom()` and `json()`).
|
|
469
|
-
|
|
470
|
-
5. Allow, depending on mode, containers to contain containers of other
|
|
471
|
-
types (e.g., a JS container containing DOM objects, or temporary use
|
|
472
|
-
of a string container, etc.).
|
|
473
|
-
|
|
474
|
-
1. Support XML and add [hXML](https://github.com/brettz9/hxml) methods.
|
|
475
|
-
|
|
476
|
-
2. Support [JHTML](https://github.com/brettz9/jhtml).
|
|
477
|
-
|
|
478
|
-
3. Support `appendJSON()`/`appendDOM()` and
|
|
479
|
-
`appendType('json', ...)` (allowing type extensions).
|
|
480
|
-
|
|
481
|
-
6. Add `appendResult(function () {return result})`.
|
|
482
|
-
|
|
483
|
-
7. Add JSON update functions (equivalent to Xquery Update Facility for
|
|
484
|
-
XML ([overview](http://www.xmlplease.com/xquery-update))) and create
|
|
485
|
-
JSON serialization (as with XSLT expressed itself in declarative XML)
|
|
486
|
-
so one can submit and evaluate
|
|
487
|
-
through [HTTPQuery](https://github.com/brettz9/httpquery) (and also
|
|
488
|
-
supply to JSONEditor, etc.). Utilize updating by reference.
|
|
489
|
-
|
|
490
|
-
8. Demo narrowing to subset of JavaScript (as with `jspe`) to make
|
|
491
|
-
JTLT truly "declarative" as far as freedom from scripting
|
|
492
|
-
|
|
493
|
-
## Possible to-dos
|
|
494
|
-
|
|
495
|
-
1. Make schema-aware so that templates could target types. Most reusable
|
|
496
|
-
application may be having a type-driven view of a JSON Schema instance
|
|
497
|
-
(e.g., dates could be shown inside a calendar widget). Perhaps this
|
|
498
|
-
schema-awareness could also drive a JSON editor (as with other existing
|
|
499
|
-
projects) (even using same API as JSONEditor?) (or type-aware filtered
|
|
500
|
-
search/raw queries). This would help not only for editors which edit a
|
|
501
|
-
JSON file in full, but also for providing schema paths or other identifiers
|
|
502
|
-
so that a transformed/queried subset of a file (or joining of multiple
|
|
503
|
-
files) could point the way for edited contents to be saved back to the
|
|
504
|
-
correct JSON file and position in the JSON file.
|
|
505
|
-
|
|
506
|
-
2. Add a [non-eval PR for JSONPath](https://github.com/s3u/JSONPath/pull/4).
|
|
507
|
-
The OR condition (outside of filters) is another important feature as
|
|
508
|
-
would be schema-aware path results.
|
|
509
|
-
|
|
510
|
-
3. Allow hybrid JSON/[Jamilih](https://github.com/brettz9/jamilih) or
|
|
511
|
-
JSON/(X)HTML/XML so that one can add
|
|
512
|
-
XPath or query into HTML in a relevant manner
|
|
513
|
-
|
|
514
|
-
4. Support pull parsing/streaming? Pass `done()` function to templates to
|
|
515
|
-
signal completion?
|
|
516
|
-
|
|
517
|
-
5. Support Promise API in addition to callbacks (reconcile with
|
|
518
|
-
current chaining; see also XQuery FLWOR to-do)
|
|
519
|
-
|
|
520
|
-
6. Add [XQuery Functions](https://code.google.com/p/jsxqueryparser/source/browse/trunk/jsxqueryparser/XQueryParser.js#1768)
|
|
521
|
-
(also supporting DOM and JSON where possible) as plug-in (also any
|
|
522
|
-
missing from XSLT/XQuery 3.0). Also add, if not present among these
|
|
523
|
-
functions (or in XQuery), add equivalents to XSLT's
|
|
524
|
-
`document()` and `unparsed-text()` for allowing non-JSON file
|
|
525
|
-
retrieval (as well as variables/parameters) and also methods for
|
|
526
|
-
iterating or retrieving IndexedDB, `localStorage`, and cookies
|
|
527
|
-
(names, keys and values).
|
|
528
|
-
|
|
529
|
-
7. Add `outputType` which uses a DOM joiner but allows specialized
|
|
530
|
-
serialized output (e.g., pretty-printed HTML) so the users
|
|
531
|
-
don't need to build it themselves (likewise with stringified
|
|
532
|
-
JSON output).
|
|
533
|
-
|
|
534
|
-
8. See code for other possible to-dos
|
|
463
|
+
See [TO-DO](./docs/TO.DO.md).
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo: Using valueOf() to access parameters in callTemplate
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates the new feature where parameters passed via callTemplate
|
|
5
|
+
* can be accessed within the template using valueOf({select: '$paramName'})
|
|
6
|
+
* instead of having to receive them as function parameters.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-console, no-new -- Demo file */
|
|
10
|
+
|
|
11
|
+
import JTLT from '../src/index-node.js';
|
|
12
|
+
|
|
13
|
+
console.log('=== Demo 1: Named parameters ===');
|
|
14
|
+
new JTLT({
|
|
15
|
+
data: {
|
|
16
|
+
users: [
|
|
17
|
+
{name: 'Alice', role: 'Admin'},
|
|
18
|
+
{name: 'Bob', role: 'User'}
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
outputType: 'string',
|
|
22
|
+
templates: [
|
|
23
|
+
{
|
|
24
|
+
path: '$',
|
|
25
|
+
template () {
|
|
26
|
+
this.forEach('$.users[*]', function (user) {
|
|
27
|
+
this.callTemplate({
|
|
28
|
+
name: 'formatUser',
|
|
29
|
+
withParam: [
|
|
30
|
+
{name: 'userName', value: user.name},
|
|
31
|
+
{name: 'userRole', value: user.role},
|
|
32
|
+
{name: 'prefix', value: '> '}
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'formatUser',
|
|
40
|
+
template () {
|
|
41
|
+
// Access parameters using valueOf with $paramName
|
|
42
|
+
this.valueOf({select: '$prefix'});
|
|
43
|
+
this.valueOf({select: '$userName'});
|
|
44
|
+
this.string(' (');
|
|
45
|
+
this.valueOf({select: '$userRole'});
|
|
46
|
+
this.string(')\n');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
success (result) {
|
|
51
|
+
console.log(result);
|
|
52
|
+
console.log('\n');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log('=== Demo 2: Indexed parameters (no names) ===');
|
|
57
|
+
new JTLT({
|
|
58
|
+
data: {value: 'Test'},
|
|
59
|
+
outputType: 'string',
|
|
60
|
+
templates: [
|
|
61
|
+
{
|
|
62
|
+
path: '$',
|
|
63
|
+
template () {
|
|
64
|
+
this.callTemplate({
|
|
65
|
+
name: 'format',
|
|
66
|
+
withParam: [
|
|
67
|
+
{value: 'First param'},
|
|
68
|
+
{value: 'Second param'},
|
|
69
|
+
{select: '$.value'}
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'format',
|
|
76
|
+
template () {
|
|
77
|
+
// Access by index when name not provided
|
|
78
|
+
this.string('Param 0: ');
|
|
79
|
+
this.valueOf({select: '$0'});
|
|
80
|
+
this.string('\nParam 1: ');
|
|
81
|
+
this.valueOf({select: '$1'});
|
|
82
|
+
this.string('\nParam 2: ');
|
|
83
|
+
this.valueOf({select: '$2'});
|
|
84
|
+
this.string('\n');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
success (result) {
|
|
89
|
+
console.log(result);
|
|
90
|
+
console.log('\n');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log('=== Demo 3: Nested callTemplate ===');
|
|
95
|
+
new JTLT({
|
|
96
|
+
data: {company: 'ACME Corp'},
|
|
97
|
+
outputType: 'string',
|
|
98
|
+
templates: [
|
|
99
|
+
{
|
|
100
|
+
path: '$',
|
|
101
|
+
template () {
|
|
102
|
+
this.callTemplate({
|
|
103
|
+
name: 'outer',
|
|
104
|
+
withParam: [
|
|
105
|
+
{name: 'company', select: '$.company'}
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'outer',
|
|
112
|
+
template () {
|
|
113
|
+
this.string('Company: ');
|
|
114
|
+
this.valueOf({select: '$company'});
|
|
115
|
+
this.string('\n');
|
|
116
|
+
|
|
117
|
+
// Call another template from within
|
|
118
|
+
/** @type {any} */ (this).callTemplate({
|
|
119
|
+
name: 'inner',
|
|
120
|
+
withParam: [
|
|
121
|
+
{name: 'message', value: 'Nested template call'}
|
|
122
|
+
]
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'inner',
|
|
128
|
+
template () {
|
|
129
|
+
this.string(' Message: ');
|
|
130
|
+
this.valueOf({select: '$message'});
|
|
131
|
+
this.string('\n');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
success (result) {
|
|
136
|
+
console.log(result);
|
|
137
|
+
}
|
|
138
|
+
});
|
package/demo/index.html
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>JTLT Demo</title>
|
|
6
|
+
<link rel="icon" href="data:image/png;base64,iVBORw0KGgo=" />
|
|
7
|
+
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{
|
|
10
|
+
"imports": {
|
|
11
|
+
"mocha": "../node_modules/mocha/mocha.js",
|
|
12
|
+
"chai": "../node_modules/chai/index.js",
|
|
13
|
+
"simple-get-json": "../node_modules/simple-get-json/dist/index-es.js",
|
|
14
|
+
"jhtml": "../node_modules/jhtml/src/jhtml-browser.js",
|
|
15
|
+
"jamilih": "../node_modules/jamilih/dist/jml.mjs",
|
|
16
|
+
"jsonpath-plus" :"../node_modules/jsonpath-plus/dist/index-browser-esm.js",
|
|
17
|
+
"xpath2.js": "./xpath2-placeholder.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
<script src="../node_modules/mocha/mocha.js"></script>
|
|
22
|
+
<script>
|
|
23
|
+
/* globals mocha -- Needs ESM */
|
|
24
|
+
mocha.setup('bdd');
|
|
25
|
+
</script>
|
|
26
|
+
<script type="module" src="index.js"></script>
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<div id="mocha"></div>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
package/demo/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* globals mocha, describe, it -- Should be ESM */
|
|
2
|
+
import {expect} from 'chai';
|
|
3
|
+
|
|
4
|
+
import {jtlt} from '../src/index-browser.js';
|
|
5
|
+
|
|
6
|
+
describe('jtlt', () => {
|
|
7
|
+
it('performs a string transformation', async () => {
|
|
8
|
+
const result = await jtlt({
|
|
9
|
+
data: new DOMParser().parseFromString(
|
|
10
|
+
`<div type="questions-answers">
|
|
11
|
+
<p n="1">Some text</p>
|
|
12
|
+
<p n="2">More text</p>
|
|
13
|
+
</div>`,
|
|
14
|
+
'text/xml'
|
|
15
|
+
),
|
|
16
|
+
engineType: 'xpath',
|
|
17
|
+
outputType: 'string',
|
|
18
|
+
templates: [{
|
|
19
|
+
path: '//*[@type="questions-answers"]/p',
|
|
20
|
+
template (p) {
|
|
21
|
+
this.valueOf('@n');
|
|
22
|
+
this.valueOf('./text()');
|
|
23
|
+
}
|
|
24
|
+
}]
|
|
25
|
+
});
|
|
26
|
+
expect(result).to.equal('1Some text2More text');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
mocha.run();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -1,4 +1,76 @@
|
|
|
1
1
|
export default AbstractJoiningTransformer;
|
|
2
|
+
export type BaseTransformerConfig = {
|
|
3
|
+
requireSameChildren?: boolean;
|
|
4
|
+
JHTMLForJSON?: boolean;
|
|
5
|
+
mode?: "JSON" | "JavaScript";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* When exposeDocuments is true, get() returns an array of XMLDocument
|
|
9
|
+
* objects (one per root element) instead of a DocumentFragment.
|
|
10
|
+
*/
|
|
11
|
+
export type DOMJoiningTransformerConfig = BaseTransformerConfig & {
|
|
12
|
+
document: Document;
|
|
13
|
+
exposeDocuments?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type JSONJoiningTransformerConfig = {
|
|
16
|
+
requireSameChildren?: boolean | undefined;
|
|
17
|
+
unwrapSingleResult?: boolean | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* - When true, get() returns an array
|
|
20
|
+
* of document wrapper objects (one per root element) instead of the raw array.
|
|
21
|
+
*/
|
|
22
|
+
exposeDocuments?: boolean | undefined;
|
|
23
|
+
mode?: "JSON" | "JavaScript" | undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* When exposeDocuments is true, get() returns an array of document
|
|
27
|
+
* strings (one per root element) instead of a single concatenated string.
|
|
28
|
+
*/
|
|
29
|
+
export type StringJoiningTransformerConfig = BaseTransformerConfig & {
|
|
30
|
+
xmlElements?: boolean;
|
|
31
|
+
preEscapedAttributes?: boolean;
|
|
32
|
+
exposeDocuments?: boolean;
|
|
33
|
+
};
|
|
34
|
+
export type JoiningTransformerConfig<T> = T extends "string" ? StringJoiningTransformerConfig : T extends "dom" ? DOMJoiningTransformerConfig : T extends "json" ? JSONJoiningTransformerConfig : never;
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {{
|
|
37
|
+
* requireSameChildren?: boolean,
|
|
38
|
+
* JHTMLForJSON?: boolean,
|
|
39
|
+
* mode?: "JSON"|"JavaScript"
|
|
40
|
+
* }} BaseTransformerConfig
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {BaseTransformerConfig & {
|
|
44
|
+
* document: Document,
|
|
45
|
+
* exposeDocuments?: boolean
|
|
46
|
+
* }} DOMJoiningTransformerConfig
|
|
47
|
+
* When exposeDocuments is true, get() returns an array of XMLDocument
|
|
48
|
+
* objects (one per root element) instead of a DocumentFragment.
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* @typedef {object} JSONJoiningTransformerConfig
|
|
52
|
+
* @property {boolean} [requireSameChildren]
|
|
53
|
+
* @property {boolean} [unwrapSingleResult]
|
|
54
|
+
* @property {boolean} [exposeDocuments] - When true, get() returns an array
|
|
55
|
+
* of document wrapper objects (one per root element) instead of the raw array.
|
|
56
|
+
* @property {"JSON"|"JavaScript"} [mode]
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {BaseTransformerConfig & {
|
|
60
|
+
* xmlElements?: boolean,
|
|
61
|
+
* preEscapedAttributes?: boolean,
|
|
62
|
+
* exposeDocuments?: boolean
|
|
63
|
+
* }} StringJoiningTransformerConfig
|
|
64
|
+
* When exposeDocuments is true, get() returns an array of document
|
|
65
|
+
* strings (one per root element) instead of a single concatenated string.
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* @template T
|
|
69
|
+
* @typedef {T extends "string" ? StringJoiningTransformerConfig :
|
|
70
|
+
* T extends "dom" ? DOMJoiningTransformerConfig :
|
|
71
|
+
* T extends "json" ? JSONJoiningTransformerConfig : never
|
|
72
|
+
* } JoiningTransformerConfig
|
|
73
|
+
*/
|
|
2
74
|
/**
|
|
3
75
|
* Base class for joining transformers.
|
|
4
76
|
*
|
|
@@ -13,18 +85,19 @@ export default AbstractJoiningTransformer;
|
|
|
13
85
|
* based on the current state.
|
|
14
86
|
* - get(): returns the accumulated result.
|
|
15
87
|
* - config(): temporarily tweak a config flag for the duration of a callback.
|
|
88
|
+
* @template T
|
|
16
89
|
*/
|
|
17
|
-
declare class AbstractJoiningTransformer {
|
|
90
|
+
declare class AbstractJoiningTransformer<T> {
|
|
18
91
|
/**
|
|
19
|
-
* @param {
|
|
92
|
+
* @param {JoiningTransformerConfig<T>} [cfg] - Configuration object
|
|
20
93
|
*/
|
|
21
|
-
constructor(cfg?:
|
|
94
|
+
constructor(cfg?: JoiningTransformerConfig<T>);
|
|
95
|
+
_cfg: JoiningTransformerConfig<T>;
|
|
22
96
|
/**
|
|
23
|
-
* @param {
|
|
97
|
+
* @param {JoiningTransformerConfig<T>} cfg - Configuration object
|
|
24
98
|
* @returns {void}
|
|
25
99
|
*/
|
|
26
|
-
setConfig(cfg
|
|
27
|
-
_cfg: any;
|
|
100
|
+
setConfig(cfg: JoiningTransformerConfig<T>): void;
|
|
28
101
|
/**
|
|
29
102
|
* @param {string} type - Type name
|
|
30
103
|
* @param {string} embedType - Embed type name
|
|
@@ -33,10 +106,11 @@ declare class AbstractJoiningTransformer {
|
|
|
33
106
|
_requireSameChildren(type: string, embedType: string): void;
|
|
34
107
|
/**
|
|
35
108
|
* @param {string} prop - Configuration property name
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
109
|
+
* @param {any} val - Configuration property value
|
|
110
|
+
* @param {(this: AbstractJoiningTransformer<T>) => void} [cb]
|
|
111
|
+
* Optional callback invoked with this instance
|
|
38
112
|
* @returns {void}
|
|
39
113
|
*/
|
|
40
|
-
config(prop: string, val: any, cb?:
|
|
114
|
+
config(prop: string, val: any, cb?: (this: AbstractJoiningTransformer<T>) => void): void;
|
|
41
115
|
}
|
|
42
116
|
//# sourceMappingURL=AbstractJoiningTransformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractJoiningTransformer.d.ts","sourceRoot":"","sources":["../src/AbstractJoiningTransformer.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"AbstractJoiningTransformer.d.ts","sourceRoot":"","sources":["../src/AbstractJoiningTransformer.js"],"names":[],"mappings":";oCAKa;IACR,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,GAAC,YAAY,CAAA;CAC3B;;;;;0CAIS,qBAAqB,GAAG;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;;;;;;;;;;;;;;;6CAaS,qBAAqB,GAAG;IAChC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;qCAKS,CAAC,IACD,CAAC,SAAS,QAAQ,GAAG,8BAA8B,GAC3D,CAAC,SAAS,KAAK,GAAG,2BAA2B,GAC7C,CAAC,SAAS,MAAM,GAAG,4BAA4B,GAAG,KAAK;AArC5D;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH;;;;;;;GAOG;AACH;;;;;;;;GAQG;AACH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,yCAFa,CAAC;IAGZ;;OAEG;IACH,kBAFW,wBAAwB,CAAC,CAAC,CAAC,EAKrC;IADC,kCAAkE;IAGpE;;;OAGG;IACH,eAHW,wBAAwB,CAAC,CAAC,CAAC,GACzB,IAAI,CAIhB;IAED;;;;OAIG;IACH,2BAJW,MAAM,aACN,MAAM,GACJ,IAAI,CAUhB;IAED;;;;;;OAMG;IACH,aANW,MAAM,OACN,GAAG,OACH,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC,CAAC,KAAK,IAAI,GAE3C,IAAI,CAUhB;CACF"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export default DOMJoiningTransformer;
|
|
2
|
+
export type SimpleCallback = (this: DOMJoiningTransformer) => void;
|
|
3
|
+
/**
|
|
4
|
+
* @callback SimpleCallback
|
|
5
|
+
* @this {DOMJoiningTransformer}
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*/
|
|
2
8
|
/**
|
|
3
9
|
* Joining transformer that accumulates into a DOM tree.
|
|
4
10
|
*
|
|
@@ -6,17 +12,24 @@ export default DOMJoiningTransformer;
|
|
|
6
12
|
* It expects templates to build DOM nodes explicitly (e.g., via element(),
|
|
7
13
|
* attribute(), and text()), though string/number/boolean will append text
|
|
8
14
|
* nodes for convenience.
|
|
15
|
+
* @extends {AbstractJoiningTransformer<"dom">}
|
|
9
16
|
*/
|
|
10
|
-
declare class DOMJoiningTransformer extends AbstractJoiningTransformer {
|
|
17
|
+
declare class DOMJoiningTransformer extends AbstractJoiningTransformer<"dom"> {
|
|
11
18
|
/**
|
|
12
19
|
* @param {DocumentFragment|Element} o - Initial DOM node
|
|
13
|
-
* @param {
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
constructor(o: DocumentFragment | Element, cfg:
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
+
* @param {import('./AbstractJoiningTransformer.js').
|
|
21
|
+
* DOMJoiningTransformerConfig} cfg - Configuration object
|
|
22
|
+
*/
|
|
23
|
+
constructor(o: DocumentFragment | Element, cfg: import("./AbstractJoiningTransformer.js").DOMJoiningTransformerConfig);
|
|
24
|
+
_dom: Element | DocumentFragment;
|
|
25
|
+
/** @type {XMLDocument[]} */
|
|
26
|
+
_docs: XMLDocument[];
|
|
27
|
+
/** @type {Array<{href: string, document: XMLDocument, format?: string}>} */
|
|
28
|
+
_resultDocuments: Array<{
|
|
29
|
+
href: string;
|
|
30
|
+
document: XMLDocument;
|
|
31
|
+
format?: string;
|
|
32
|
+
}>;
|
|
20
33
|
/**
|
|
21
34
|
* @param {Node} item
|
|
22
35
|
* @returns {void}
|
|
@@ -28,35 +41,36 @@ declare class DOMJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
28
41
|
*/
|
|
29
42
|
append(item: string | Node): void;
|
|
30
43
|
/**
|
|
31
|
-
* @returns {DocumentFragment|Element}
|
|
44
|
+
* @returns {DocumentFragment|Element|XMLDocument[]}
|
|
32
45
|
*/
|
|
33
|
-
get(): DocumentFragment | Element;
|
|
46
|
+
get(): DocumentFragment | Element | XMLDocument[];
|
|
34
47
|
/**
|
|
35
48
|
* @param {string} prop - Property name
|
|
36
|
-
* @param {
|
|
49
|
+
* @param {any} val - Property value
|
|
37
50
|
* @returns {void}
|
|
38
51
|
*/
|
|
39
52
|
propValue(prop: string, val: any): void;
|
|
40
53
|
/**
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {
|
|
54
|
+
* @param {Record<string, unknown>} obj - Object to serialize
|
|
55
|
+
* @param {(this: DOMJoiningTransformer) => void} [cb] - Callback function.
|
|
43
56
|
* @param {any[]} [usePropertySets] - Property sets to use
|
|
44
|
-
* @param {
|
|
57
|
+
* @param {Record<string, unknown>} [propSets] - Additional property sets
|
|
45
58
|
* @returns {DOMJoiningTransformer}
|
|
46
59
|
*/
|
|
47
|
-
object(obj:
|
|
60
|
+
object(obj: Record<string, unknown>, cb?: (this: DOMJoiningTransformer) => void, usePropertySets?: any[], propSets?: Record<string, unknown>): DOMJoiningTransformer;
|
|
48
61
|
/**
|
|
49
62
|
* @param {any[]|Element} arr
|
|
50
|
-
* @param {
|
|
63
|
+
* @param {(this: DOMJoiningTransformer) => void} [cb] - Callback function
|
|
51
64
|
* @returns {DOMJoiningTransformer}
|
|
52
65
|
*/
|
|
53
|
-
array(arr: any[] | Element, cb?:
|
|
66
|
+
array(arr: any[] | Element, cb?: (this: DOMJoiningTransformer) => void): DOMJoiningTransformer;
|
|
54
67
|
/**
|
|
55
68
|
* @param {string} str - String value
|
|
56
|
-
* @param {
|
|
69
|
+
* @param {(this: DOMJoiningTransformer) => void} [cb] - Callback
|
|
70
|
+
* function (unused)
|
|
57
71
|
* @returns {DOMJoiningTransformer}
|
|
58
72
|
*/
|
|
59
|
-
string(str: string, cb:
|
|
73
|
+
string(str: string, cb?: (this: DOMJoiningTransformer) => void): DOMJoiningTransformer;
|
|
60
74
|
/**
|
|
61
75
|
* @param {number} num - Number value
|
|
62
76
|
* @returns {DOMJoiningTransformer}
|
|
@@ -81,17 +95,25 @@ declare class DOMJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
81
95
|
*/
|
|
82
96
|
nonfiniteNumber(num: number): DOMJoiningTransformer;
|
|
83
97
|
/**
|
|
84
|
-
* @param {
|
|
98
|
+
* @param {(...args: any[]) => any} func - Function to stringify
|
|
99
|
+
* @returns {DOMJoiningTransformer}
|
|
100
|
+
*/
|
|
101
|
+
function(func: (...args: any[]) => any): DOMJoiningTransformer;
|
|
102
|
+
/**
|
|
103
|
+
* @param {import('./StringJoiningTransformer.js').OutputConfig} cfg
|
|
85
104
|
* @returns {DOMJoiningTransformer}
|
|
86
105
|
*/
|
|
87
|
-
|
|
106
|
+
output(cfg: import("./StringJoiningTransformer.js").OutputConfig): DOMJoiningTransformer;
|
|
107
|
+
_outputConfig: any;
|
|
108
|
+
mediaType: string | undefined;
|
|
88
109
|
/**
|
|
89
|
-
* @param {string} elName - Element name
|
|
90
|
-
* @param {
|
|
91
|
-
* @param {
|
|
110
|
+
* @param {Element|string} elName - Element name
|
|
111
|
+
* @param {Record<string, string>} [atts] - Attributes object
|
|
112
|
+
* @param {(this: DOMJoiningTransformer) => void} [cb] - Callback function
|
|
92
113
|
* @returns {DOMJoiningTransformer}
|
|
93
114
|
*/
|
|
94
|
-
element(elName: string, atts?:
|
|
115
|
+
element(elName: Element | string, atts?: Record<string, string>, cb?: (this: DOMJoiningTransformer) => void): DOMJoiningTransformer;
|
|
116
|
+
root: any;
|
|
95
117
|
/**
|
|
96
118
|
* @param {string} name
|
|
97
119
|
* @param {string} val
|
|
@@ -103,11 +125,49 @@ declare class DOMJoiningTransformer extends AbstractJoiningTransformer {
|
|
|
103
125
|
* @returns {DOMJoiningTransformer}
|
|
104
126
|
*/
|
|
105
127
|
text(txt: string): DOMJoiningTransformer;
|
|
128
|
+
/**
|
|
129
|
+
* @param {string} text
|
|
130
|
+
* @returns {DOMJoiningTransformer}}
|
|
131
|
+
*/
|
|
132
|
+
comment(text: string): DOMJoiningTransformer;
|
|
133
|
+
/**
|
|
134
|
+
* @param {string} target
|
|
135
|
+
* @param {string} data
|
|
136
|
+
* @returns {DOMJoiningTransformer}}
|
|
137
|
+
*/
|
|
138
|
+
processingInstruction(target: string, data: string): DOMJoiningTransformer;
|
|
106
139
|
/**
|
|
107
140
|
* @param {string} str
|
|
108
141
|
* @returns {DOMJoiningTransformer}
|
|
109
142
|
*/
|
|
110
143
|
plainText(str: string): DOMJoiningTransformer;
|
|
144
|
+
/**
|
|
145
|
+
* Creates a new XML document and executes a callback in its context.
|
|
146
|
+
* Similar to XSLT's xsl:document, this allows templates to generate
|
|
147
|
+
* multiple output documents. The created document is pushed to this._docs
|
|
148
|
+
* and will be included in the result when exposeDocuments is true.
|
|
149
|
+
*
|
|
150
|
+
* @param {(this: DOMJoiningTransformer) => void} cb
|
|
151
|
+
* Callback that builds the document content
|
|
152
|
+
* @param {import('./StringJoiningTransformer.js').OutputConfig} [cfg]
|
|
153
|
+
* Output configuration for the document (encoding, doctype, etc.)
|
|
154
|
+
* @returns {DOMJoiningTransformer}
|
|
155
|
+
*/
|
|
156
|
+
document(cb: (this: DOMJoiningTransformer) => void, cfg?: import("./StringJoiningTransformer.js").OutputConfig): DOMJoiningTransformer;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a new result document with metadata (href, format).
|
|
159
|
+
* Similar to XSLT's xsl:result-document, this allows templates to generate
|
|
160
|
+
* multiple output documents with associated metadata like URIs. The created
|
|
161
|
+
* document is stored in this._resultDocuments with the provided href.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} href - URI/path for the result document
|
|
164
|
+
* @param {(this: DOMJoiningTransformer) => void} cb
|
|
165
|
+
* Callback that builds the document content
|
|
166
|
+
* @param {import('./StringJoiningTransformer.js').OutputConfig} [cfg]
|
|
167
|
+
* Output configuration for the document (encoding, doctype, format, etc.)
|
|
168
|
+
* @returns {DOMJoiningTransformer}
|
|
169
|
+
*/
|
|
170
|
+
resultDocument(href: string, cb: (this: DOMJoiningTransformer) => void, cfg?: import("./StringJoiningTransformer.js").OutputConfig): DOMJoiningTransformer;
|
|
111
171
|
}
|
|
112
172
|
import AbstractJoiningTransformer from './AbstractJoiningTransformer.js';
|
|
113
173
|
//# sourceMappingURL=DOMJoiningTransformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOMJoiningTransformer.d.ts","sourceRoot":"","sources":["../src/DOMJoiningTransformer.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"DOMJoiningTransformer.d.ts","sourceRoot":"","sources":["../src/DOMJoiningTransformer.js"],"names":[],"mappings":";8DAMa,IAAI;AAHjB;;;;GAIG;AAEH;;;;;;;;GAQG;AACH;IACE;;;;OAIG;IACH,eAJW,gBAAgB,GAAC,OAAO,OACxB,OAAO,iCAAiC,EAC9C,2BAA2B,EAS/B;IALC,iCAAsD;IACtD,4BAA4B;IAC5B,OADW,WAAW,EAAE,CACT;IACf,4EAA4E;IAC5E,kBADW,KAAK,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,WAAW,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC,CAC9C;IAG5B;;;OAGG;IACH,gBAHW,IAAI,GACF,IAAI,CAIhB;IAED;;;OAGG;IACH,aAHW,MAAM,GAAC,IAAI,GACT,IAAI,CAIhB;IAED;;OAEG;IACH,OAFa,gBAAgB,GAAC,OAAO,GAAC,WAAW,EAAE,CAOlD;IAED;;;;OAIG;IACH,gBAJW,MAAM,OACN,GAAG,GACD,IAAI,CAKhB;IAED;;;;;;OAMG;IACH,YANW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OACvB,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,oBACrC,GAAG,EAAE,aACL,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrB,qBAAqB,CAYjC;IAED;;;;OAIG;IACH,WAJW,GAAG,EAAE,GAAC,OAAO,OACb,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,GACnC,qBAAqB,CAWjC;IAED;;;;;OAKG;IACH,YALW,MAAM,OACN,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,GAEnC,qBAAqB,CAMjC;IAED;;;OAGG;IACH,YAHW,MAAM,GACJ,qBAAqB,CAKjC;IAED;;;OAGG;IACH,cAHW,OAAO,GACL,qBAAqB,CAKjC;IAED;;OAEG;IACH,QAFa,qBAAqB,CAKjC;IAED;;OAEG;IACH,aAFa,qBAAqB,CAUjC;IAED;;;OAGG;IACH,qBAHW,MAAM,GACJ,qBAAqB,CAUjC;IAED;;;OAGG;IACH,eAHW,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GACrB,qBAAqB,CAUjC;IAED;;;OAGG;IACH,YAHW,OAAO,+BAA+B,EAAE,YAAY,GAClD,qBAAqB,CAUjC;IALC,mBAAwB;IAGxB,8BAA8B;IAIhC;;;;;OAKG;IACH,gBALW,OAAO,GAAC,MAAM,SACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OACtB,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,GACnC,qBAAqB,CAqHjC;IA3GG,UAAkB;IA6GtB;;;;OAIG;IACH,gBAJW,MAAM,OACN,MAAM,GACJ,qBAAqB,CASjC;IAED;;;OAGG;IACH,UAHW,MAAM,GACJ,qBAAqB,CAKjC;IAED;;;OAGG;IACH,cAHW,MAAM,GACJ,qBAAqB,CAWjC;IAED;;;;OAIG;IACH,8BAJW,MAAM,QACN,MAAM,GACJ,qBAAqB,CAcjC;IAED;;;OAGG;IACH,eAHW,MAAM,GACJ,qBAAqB,CAKjC;IAED;;;;;;;;;;;OAWG;IACH,aANW,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,QAErC,OAAO,+BAA+B,EAAE,YAAY,GAElD,qBAAqB,CA4BjC;IAED;;;;;;;;;;;;OAYG;IACH,qBAPW,MAAM,MACN,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,QAErC,OAAO,+BAA+B,EAAE,YAAY,GAElD,qBAAqB,CA2CjC;CACF;uCAhesC,iCAAiC"}
|