jtlt 0.12.0 → 0.14.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.
Files changed (68) hide show
  1. package/CHANGES.md +15 -0
  2. package/README.md +100 -82
  3. package/demo/calltemplate-params-demo.js +29 -34
  4. package/demo/codemirror.esm.js +140 -70
  5. package/demo/codemirror.js +9 -5
  6. package/demo/index.js +2 -1
  7. package/demo/vendor/fontoxpath/dist/fontoxpath.esm.js +508 -499
  8. package/demo/vendor/jamilih/dist/jml.mjs +516 -225
  9. package/demo/vendor/jhtml/src/SAJJ/SAJJ.ObjectArrayDelegator.js +17 -17
  10. package/demo/vendor/jhtml/src/SAJJ/SAJJ.js +60 -61
  11. package/demo/vendor/jhtml/src/jhtml-browser.js +1 -0
  12. package/demo/vendor/jhtml/src/jhtml-node.js +1 -0
  13. package/demo/vendor/jhtml/src/jhtml.js +18 -15
  14. package/demo/vendor/jsonpath-plus/dist/index-browser-esm.js +11 -5
  15. package/dist/AbstractJoiningTransformer.d.ts +17 -25
  16. package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
  17. package/dist/DOMJoiningTransformer.d.ts +502 -19
  18. package/dist/DOMJoiningTransformer.d.ts.map +1 -1
  19. package/dist/JSONJoiningTransformer.d.ts +41 -25
  20. package/dist/JSONJoiningTransformer.d.ts.map +1 -1
  21. package/dist/JSONPathTransformer.d.ts +30 -29
  22. package/dist/JSONPathTransformer.d.ts.map +1 -1
  23. package/dist/JSONPathTransformerContext.d.ts +152 -99
  24. package/dist/JSONPathTransformerContext.d.ts.map +1 -1
  25. package/dist/StringJoiningTransformer.d.ts +42 -28
  26. package/dist/StringJoiningTransformer.d.ts.map +1 -1
  27. package/dist/XPathTransformer.d.ts +20 -13
  28. package/dist/XPathTransformer.d.ts.map +1 -1
  29. package/dist/XPathTransformerContext.d.ts +92 -53
  30. package/dist/XPathTransformerContext.d.ts.map +1 -1
  31. package/dist/XSLTStyleJSONPathResolver.d.ts +1 -1
  32. package/dist/XSLTStyleJSONPathResolver.d.ts.map +1 -1
  33. package/dist/index-browser.d.ts +2 -2
  34. package/dist/index-browser.d.ts.map +1 -1
  35. package/dist/index-node.d.ts +2 -2
  36. package/dist/index-node.d.ts.map +1 -1
  37. package/dist/index.d.ts +224 -171
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/indexedDB.d.ts +107 -0
  40. package/dist/indexedDB.d.ts.map +1 -0
  41. package/dist/maybeAsync.d.ts +15 -0
  42. package/dist/maybeAsync.d.ts.map +1 -0
  43. package/docs/API.expanded.md +74 -22
  44. package/docs/API.md +34 -4
  45. package/docs/TO-DO.md +5 -3
  46. package/eslint.config.js +28 -4
  47. package/package.json +25 -22
  48. package/pnpm-workspace.yaml +41 -4
  49. package/rollup.config.js +42 -0
  50. package/src/AbstractJoiningTransformer.js +11 -4
  51. package/src/DOMJoiningTransformer.js +56 -27
  52. package/src/JSONJoiningTransformer.js +64 -44
  53. package/src/JSONPathTransformer.js +124 -85
  54. package/src/JSONPathTransformerContext.js +252 -70
  55. package/src/StringJoiningTransformer.js +48 -23
  56. package/src/XPathTransformer.js +50 -14
  57. package/src/XPathTransformerContext.js +309 -139
  58. package/src/index-browser.js +1 -0
  59. package/src/index-node.js +2 -0
  60. package/src/index.js +206 -72
  61. package/src/indexedDB.js +530 -0
  62. package/src/maybeAsync.js +44 -0
  63. package/test.html +17 -0
  64. package/test.js +45 -0
  65. package/tsconfig-prod.json +1 -0
  66. package/tsconfig.json +3 -2
  67. package/dist/types.d.ts +0 -204
  68. package/dist/types.d.ts.map +0 -1
package/CHANGES.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # jtlt CHANGES
2
2
 
3
+ ## 0.14.0
4
+
5
+ - feat: indexedDB JSONPath and XPath support
6
+ - feat: async templates are awaited by default; new off-by-default `sync`
7
+ option throws instead (replaces `async`/`syncOnly`)
8
+ - fix: `getKey()` resolves its `match` against the document root, so it now
9
+ works inside `forEach()`/`applyTemplates()` callbacks
10
+ - fix(types): more precise typing (any -> unknown)
11
+ - docs: lead with the `jtlt()` function; correct examples
12
+
13
+ ## 0.13.0
14
+
15
+ - fix(types): more precise typing
16
+ - chore: update deps and devDeps
17
+
3
18
  ## 0.12.0
4
19
 
5
20
  - feat: allow `sequence` for this.function
package/README.md CHANGED
@@ -8,8 +8,6 @@ As with XSLT, allows for declarative, linear declaration of
8
8
  (recursive) templates and can be transformed into different
9
9
  formats (e.g., strings, JSON, or DOM objects).
10
10
 
11
- ***Beta state!!!***
12
-
13
11
  See the [Demo](https://brettz9.github.io/jtlt/demo/).
14
12
 
15
13
  ## Credits
@@ -29,9 +27,56 @@ See the [test file](./test/browser/index.html).
29
27
 
30
28
  ## Basic usage
31
29
 
32
- ### Node
30
+ The quickest way to run a transform is the **`jtlt()`** function. Give it a
31
+ config object; it runs the transform and returns a `Promise` that resolves to
32
+ the result:
33
+
34
+ ```js
35
+ import {jtlt} from 'jtlt';
36
+
37
+ const data = {title: 'Hello', items: ['a', 'b']};
38
+
39
+ const templates = [
40
+ {path: '$', template () {
41
+ this.applyTemplates('$.title');
42
+ this.applyTemplates('$.items[*]');
43
+ }},
44
+ {path: '$.title', template (v) {
45
+ this.element('h1', {}, [], () => this.text(v));
46
+ }},
47
+ {path: '$.items[*]', template (v) {
48
+ this.element('li', {}, [], () => this.text(v));
49
+ }}
50
+ ];
51
+
52
+ const out = await jtlt({data, templates, outputType: 'string'});
53
+ // -> <h1>Hello</h1><li>a</li><li>b</li>
54
+ ```
55
+
56
+ Templates may be `async` (for example to `await this.indexedDB(...)`);
57
+ `jtlt()` awaits them automatically. Pass `sync: true` to forbid asynchronous
58
+ templates (a template that then returns a Promise throws).
59
+
60
+ The same call works in Node and the browser (in the browser you must also
61
+ load the dependencies — see the [test file](./test/browser/index.html)). For
62
+ XML/HTML sources, add `engineType: 'xpath'` — see
63
+ [Quick start (XML source with XPath)](#quick-start-xml-source-with-xpath).
64
+
65
+ ### `jtlt()` vs `JTLT.create()`
66
+
67
+ `jtlt()` is a thin, Promise-returning wrapper around the lower-level
68
+ `JTLT` class. Prefer `jtlt()`. Reach for `JTLT.create()` /
69
+ `new JTLT()` only when you need the instance itself, `autostart: false`, or
70
+ to drive `.transform(mode)` yourself.
33
71
 
34
- ### Browser
72
+ | | `jtlt(config)` | `JTLT.create(config)` |
73
+ | --- | --- | --- |
74
+ | Returns | a `Promise` of the result | a `JTLT` instance |
75
+ | Result delivery | the resolved value | a required `success` callback (also returned by `.transform()`) |
76
+ | Async templates | awaited automatically | awaited automatically; `.transform()` returns a Promise |
77
+
78
+ Anywhere below that shows `JTLT.create({…}).transform(mode)` can instead be
79
+ written `await jtlt({…, mode})`.
35
80
 
36
81
  ## API
37
82
 
@@ -39,16 +84,20 @@ See the [docs](docs/API.md). A high‑level overview is below.
39
84
 
40
85
  ## API overview
41
86
 
42
- JTLT has two layers:
87
+ Run a transform with the **`jtlt(config)`** function (Promise-returning,
88
+ recommended) or the lower-level **`JTLT`** class (`JTLT.create(config)` /
89
+ `new JTLT(config)`, which delivers the result through a required `success`
90
+ callback). Under the hood JTLT has two layers:
43
91
 
44
92
  - Engine (template application):
45
93
  - JSONPathTransformer: Applies templates to JSON by matching JSONPath selectors (and optional modes), resolving priority, and invoking the winning template. Falls back to built‑in default rules when no user template matches.
46
94
  - JSONPathTransformerContext: The execution context passed to templates. It mirrors the joiner API (e.g., string(), object(), array()) so templates can emit results. It also provides helpers like applyTemplates(), callTemplate(), valueOf(), variable(), and forEach().
47
95
  - XPathTransformer (experimental): Applies templates to
48
96
  XML/HTML DOM by matching XPath selectors (and optional modes).
49
- Supports three evaluation modes: version 1 (native
50
- XPathEvaluator), version 2 (via xpath2.js), and version 3 (via fontoxpath).
51
- Falls back to built‑in default rules when no template matches.
97
+ Supports three evaluation modes: version `1` (native
98
+ XPathEvaluator), version `2` (via xpath2.js), and version `3.1` (via
99
+ fontoxpath). Falls back to built‑in default rules when no template
100
+ matches.
52
101
  - XPathTransformerContext (experimental): Execution context for
53
102
  XPath. Offers get(), forEach(), valueOf(), variable(), key()
54
103
  and the same joiner helpers as the JSONPath context.
@@ -69,16 +118,16 @@ JTLT has two layers:
69
118
 
70
119
  ### Common joiner methods
71
120
 
72
- - append(value): Central sink. Based on context, concatenates to string, pushes to array, or assigns to an object property.
73
- - get(): Return the accumulated result.
74
- - object(obj?, cb?, usePropertySets?, propSets?): Enter object context; optionally seed from an object or build via cb.
75
- - array(arr?, cb?): Enter array context; optionally seed from an array or build via cb.
76
- - string(str, cb?): Emit a string value (no HTML escaping). In String joiner, optional cb lets you compose nested fragments before emitting.
77
- - number(num), boolean(bool), null(), undefined() (JS mode only), nonfiniteNumber(NaN|Infinity), function(fn) (JS mode only): Emit primitives/functions.
78
- - element(name, attrs?, children?, cb?): Build elements (String and DOM joiners). In String joiner, uses Jamilih under the hood to serialize; in DOM joiner, creates Elements.
79
- - attribute(name, value, avoidEscape?): Add attributes to the most recently opened element (String joiner) or to the current Element (DOM joiner).
80
- - text(txt): Emit text content. In String joiner, escapes & and <, and closes an open start tag if needed.
81
- - plainText(str): Raw, no‑escape append that bypasses context routing in the String joiner (always writes to top‑level buffer). In DOM/JSON joiners, it maps to text()/string() respectively.
121
+ - `append(value)`: Central sink. Based on context, concatenates to string, pushes to array, or assigns to an object property.
122
+ - `get()`: Return the accumulated result.
123
+ - `object(obj?, cb?, usePropertySets?, propSets?)`: Enter object context; optionally seed from an object or build via cb.
124
+ - `array(arr?, cb?)`: Enter array context; optionally seed from an array or build via cb.
125
+ - `string(str, cb?)`: Emit a string value (no HTML escaping). In String joiner, optional cb lets you compose nested fragments before emitting.
126
+ - `number(num), boolean(bool), null(), undefined()` (JS mode only), `nonfiniteNumber(NaN|Infinity), function(fn)` (JS mode only): Emit primitives/functions.
127
+ - `element(name, attrs?, children?, cb?)`: Build elements (String and DOM joiners). In String joiner, uses Jamilih under the hood to serialize; in DOM joiner, creates Elements.
128
+ - `attribute(name, value, avoidEscape?)`: Add attributes to the most recently opened element (String joiner) or to the current Element (DOM joiner).
129
+ - `text(txt)`: Emit text content. In String joiner, escapes & and <, and closes an open start tag if needed.
130
+ - `plainText(str)`: Raw, no‑escape append that bypasses context routing in the String joiner (always writes to top‑level buffer). In DOM/JSON joiners, it maps to text()/string() respectively.
82
131
 
83
132
  ### string() vs text() vs plainText() (String joiner)
84
133
 
@@ -95,56 +144,32 @@ Provide joiningConfig when constructing JTLT:
95
144
  - joiningConfig.xmlElements: Switch element() to XML serialization mode in the String joiner.
96
145
  - joiningConfig.preEscapedAttributes: Skip escaping attribute values in the String joiner.
97
146
 
98
- ## Quick start (JSON source)
99
-
100
- ```js
101
- import {jtlt} from 'jtlt';
102
-
103
- const data = {title: 'Hello', items: ['a', 'b']};
104
-
105
- const templates = [
106
- {path: '$', template () {
107
- this.applyTemplates();
108
- }},
109
- {path: '$.title', template (v) {
110
- this.string('<h1>', () => this.text(v));
111
- this.string('</h1>');
112
- }},
113
- {path: '$.items[*]', template (v) {
114
- this.element('li', {}, [], () => this.text(v));
115
- }}
116
- ];
117
-
118
- const out = await jtlt({data, templates, outputType: 'string'});
119
-
120
- console.log(out);
121
- ```
122
-
123
- Notes:
147
+ ## Notes on the basic example
124
148
 
125
149
  - Modes let you organize multiple passes or output targets.
126
- - You can also call templates by name via this.callTemplate('name').
127
- - For DOM output, use outputType: 'dom'. For JSON output, use 'json'.
150
+ - You can also call templates by name via `this.callTemplate('name')`.
151
+ - For DOM output, use `outputType: 'dom'`. For JSON output, use `'json'`
152
+ (the default is `'string'`).
128
153
 
129
- ### Quick start (XML source with XPath)
154
+ ## Quick start (XML source with XPath)
130
155
 
131
156
  You can run templates against XML/HTML using XPath instead of JSONPath.
132
157
 
133
158
  - `data` should be a Document or Element (e.g., from `DOMParser` with
134
159
  `text/xml`).
135
- - `xpathVersion`: `1` uses native XPath (browser like). `2` uses
136
- `xpath2.js` for XPath 2.0‑style evaluation. and `3.1` uses `fontoxpath`
137
- for XPath 3.1.
160
+ - `xpathVersion`: `1` uses native XPath (browserlike). `2` uses
161
+ `xpath2.js` for XPath 2.0‑style evaluation. `3.1` uses `fontoxpath` for
162
+ XPath 3.1. Default is `1`.
138
163
  - In version 2, some functions may be missing; prefer simple path
139
164
  expressions. Use version 1 for standard XPath 1.0 function support.
140
165
 
141
- Example (string output) using the JTLT facade with XPath:
166
+ Example (string output) with `jtlt()` and the XPath engine:
142
167
 
143
168
  ```js
144
169
  import {JSDOM} from 'jsdom';
145
170
  import {jtlt} from 'jtlt';
146
171
 
147
- const {window} = new JSDOM('<!doctype><html><body></body></html>');
172
+ const {window} = new JSDOM('<!doctype html><html><body></body></html>');
148
173
  const parser = new window.DOMParser();
149
174
  const doc = parser.parseFromString(
150
175
  '<root><item>a</item><item>b</item></root>', 'text/xml'
@@ -160,8 +185,7 @@ const templates = [
160
185
  {
161
186
  path: '//item',
162
187
  template (n) {
163
- this.string('<li>', () => this.text(n.textContent));
164
- this.string('</li>');
188
+ this.element('li', {}, [], () => this.text(n.textContent));
165
189
  }
166
190
  }
167
191
  ];
@@ -171,8 +195,7 @@ const out = await jtlt({
171
195
  templates,
172
196
  outputType: 'string',
173
197
  engineType: 'xpath',
174
- xpathVersion: 1, // or 2
175
- success: (res) => res
198
+ xpathVersion: 1 // or 2, or 3.1
176
199
  });
177
200
  // -> <li>a</li><li>b</li>
178
201
  ```
@@ -182,15 +205,14 @@ const out = await jtlt({
182
205
  If you just want to run a single, non-recursive query (similar to an XQuery "for … where … return …"), you can skip defining templates and use `forQuery` to seed a root function that iterates a JSONPath and emits results.
183
206
 
184
207
  - `forQuery` takes the same arguments you’d pass to `this.forEach(select, cb)`: an absolute JSONPath selector and a callback invoked for each match.
185
- - You can set variables via `this.variable(name, select)` and use plain JavaScript `if` for conditions (there is no dedicated `this.if`).
208
+ - The callback runs once per match with `this` bound to that match, so use plain JavaScript `if` for conditions (there is no dedicated `this.if`).
186
209
 
187
- Example: collect item names whose price meets a threshold, using a variable sourced from the root.
210
+ Example: collect item names whose price is at least 10.
188
211
 
189
212
  ```js
190
- import JTLT from 'jtlt';
213
+ import {jtlt} from 'jtlt';
191
214
 
192
215
  const data = {
193
- threshold: 10,
194
216
  items: [
195
217
  {name: 'A', price: 8},
196
218
  {name: 'B', price: 12},
@@ -198,37 +220,29 @@ const data = {
198
220
  ]
199
221
  };
200
222
 
201
- const jtlt = new JTLT({
223
+ const result = await jtlt({
202
224
  data,
203
225
  outputType: 'json', // Top-level result will be a JSON array
204
226
  // forQuery mirrors: this.forEach(select, cb)
205
227
  forQuery: [
206
228
  '$.items[*]',
207
229
  function (item) {
208
- // Set a reusable variable from the root context
209
- this.variable('threshold', '$.threshold');
210
- const {threshold} = this.vars;
211
-
212
230
  // Use normal JS conditionals (no this.if helper)
213
- if (item.price >= threshold) {
231
+ if (item.price >= 10) {
214
232
  // In JSON output mode, appending a string pushes into
215
233
  // the top-level array
216
234
  this.string(item.name);
217
235
  }
218
236
  }
219
- ],
220
- // success receives the final result; return it for convenience
221
- success: (out) => out
237
+ ]
222
238
  });
223
-
224
- const result = jtlt.transform();
225
239
  // result => ['B', 'C']
226
240
  ```
227
241
 
228
242
  Tips:
229
243
 
230
244
  - For string output, set `outputType: 'string'` and emit with `this.text()`/`this.string()` in the callback.
231
- - `this.variable(name, select)` evaluates the JSONPath against the current context (root for `forQuery`), storing it in `this.vars[name]`.
245
+ - `forQuery`'s callback context is the matched item, not the root to use a value from the root (e.g. a `threshold`), use a root template instead: `this.variable('threshold', '$.threshold')` then `this.forEach('$.items[*]', cb)` (see the FLWOR example below).
232
246
  - If you need multiple passes or richer logic, switch to named templates and modes.
233
247
 
234
248
  ## FLWOR-style (XQuery) example
@@ -238,7 +252,7 @@ You can express the essentials of a FLWOR expression (For, Let, Where, Order by,
238
252
  Scenario: list book titles whose price is at/above a threshold, ordered by price descending and then title ascending.
239
253
 
240
254
  ```js
241
- import JTLT from 'jtlt';
255
+ import {jtlt} from 'jtlt';
242
256
 
243
257
  const data = {
244
258
  threshold: 10,
@@ -274,8 +288,7 @@ const templates = [
274
288
  }}
275
289
  ];
276
290
 
277
- const out = new JTLT({data, templates, outputType: 'string'}).
278
- transform('html');
291
+ const out = await jtlt({data, templates, outputType: 'string', mode: 'html'});
279
292
 
280
293
  // -> <ul><li>Brave New</li><li>Cobalt</li><li>Delta</li></ul>
281
294
  console.log(out);
@@ -297,7 +310,7 @@ You can model a join across two arrays (e.g., orders ↔ customers) using two `f
297
310
  Example: render an HTML list of orders annotated with customer names.
298
311
 
299
312
  ```js
300
- import JTLT from 'jtlt';
313
+ import {jtlt} from 'jtlt';
301
314
 
302
315
  const data = {
303
316
  customers: [
@@ -333,8 +346,11 @@ const templates = [
333
346
  }}
334
347
  ];
335
348
 
336
- const out = new JTLT({data, templates, outputType: 'string'}).transform('html');
337
- // -> <ul><li>Bob Keyboard</li><li>Alice — Mouse</li></ul>
349
+ const out = await jtlt({
350
+ data, templates, outputType: 'string', mode: 'html'
351
+ });
352
+ // sorted by date ascending:
353
+ // -> <ul><li>Alice — Mouse</li><li>Bob — Keyboard</li></ul>
338
354
  console.log(out);
339
355
  ```
340
356
 
@@ -350,7 +366,7 @@ Notes:
350
366
  Define an index once, then perform O(1) lookups from another sequence when rendering. If no match is found, `getKey()` returns the current context (`this`) as a sentinel; check for that to skip safely.
351
367
 
352
368
  ```js
353
- import JTLT from 'jtlt';
369
+ import {jtlt} from 'jtlt';
354
370
 
355
371
  const data = {
356
372
  customers: [
@@ -381,7 +397,9 @@ const templates = [
381
397
  }}
382
398
  ];
383
399
 
384
- const out = new JTLT({data, templates, outputType: 'string'}).transform('html');
400
+ const out = await jtlt({
401
+ data, templates, outputType: 'string', mode: 'html'
402
+ });
385
403
  // -> <ul><li>Bob: Keyboard</li></ul>
386
404
  console.log(out);
387
405
  ```
@@ -412,7 +430,7 @@ Differences / current limitations:
412
430
  allow a particuluar subset of JavaScript.
413
431
  - Stylesheet composition/precedence: no `xsl:import`/`xsl:include` equivalents; only basic priority and modes.
414
432
  - Schema awareness: no type-aware processing (a major XSLT/XQuery feature).
415
- - Multi-output (`xsl:result-document`): not built-in; pick one output type per transform.
433
+ - One output type per transform, though `document()` / `resultDocument()` can emit several documents of that type within a run.
416
434
 
417
435
  ## Differences between an exact equivalence with XSLT
418
436
 
@@ -426,4 +444,4 @@ from XSLT):
426
444
 
427
445
  ## To-dos
428
446
 
429
- See [TO-DO](./docs/TO.DO.md).
447
+ See [TO-DO](./docs/TO-DO.md).
@@ -1,17 +1,17 @@
1
1
  /**
2
2
  * Demo: Using valueOf() to access parameters in callTemplate
3
3
  *
4
- * This demonstrates the new feature where parameters passed via callTemplate
4
+ * This demonstrates the feature where parameters passed via callTemplate
5
5
  * can be accessed within the template using valueOf({select: '$paramName'})
6
6
  * instead of having to receive them as function parameters.
7
7
  */
8
8
 
9
- /* eslint-disable no-console, no-new -- Demo file */
9
+ /* eslint-disable no-console -- Demo file */
10
10
 
11
- import JTLT from '../src/index-node.js';
11
+ import {jtlt} from '../src/index-node.js';
12
12
 
13
13
  console.log('=== Demo 1: Named parameters ===');
14
- new JTLT({
14
+ console.log(await jtlt({
15
15
  data: {
16
16
  users: [
17
17
  {name: 'Alice', role: 'Admin'},
@@ -23,16 +23,20 @@ new JTLT({
23
23
  {
24
24
  path: '$',
25
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
- });
26
+ this.forEach(
27
+ '$.users[*]',
28
+ function (usr) {
29
+ const user = /** @type {{name: string, role: string}} */ (usr);
30
+ this.callTemplate({
31
+ name: 'formatUser',
32
+ withParam: [
33
+ {name: 'userName', value: user.name},
34
+ {name: 'userRole', value: user.role},
35
+ {name: 'prefix', value: '> '}
36
+ ]
37
+ });
38
+ }
39
+ );
36
40
  }
37
41
  },
38
42
  {
@@ -46,15 +50,12 @@ new JTLT({
46
50
  this.string(')\n');
47
51
  }
48
52
  }
49
- ],
50
- success (result) {
51
- console.log(result);
52
- console.log('\n');
53
- }
54
- });
53
+ ]
54
+ }));
55
+ console.log('\n');
55
56
 
56
57
  console.log('=== Demo 2: Indexed parameters (no names) ===');
57
- new JTLT({
58
+ console.log(await jtlt({
58
59
  data: {value: 'Test'},
59
60
  outputType: 'string',
60
61
  templates: [
@@ -84,15 +85,12 @@ new JTLT({
84
85
  this.string('\n');
85
86
  }
86
87
  }
87
- ],
88
- success (result) {
89
- console.log(result);
90
- console.log('\n');
91
- }
92
- });
88
+ ]
89
+ }));
90
+ console.log('\n');
93
91
 
94
92
  console.log('=== Demo 3: Nested callTemplate ===');
95
- new JTLT({
93
+ console.log(await jtlt({
96
94
  data: {company: 'ACME Corp'},
97
95
  outputType: 'string',
98
96
  templates: [
@@ -115,7 +113,7 @@ new JTLT({
115
113
  this.string('\n');
116
114
 
117
115
  // Call another template from within
118
- /** @type {any} */ (this).callTemplate({
116
+ this.callTemplate({
119
117
  name: 'inner',
120
118
  withParam: [
121
119
  {name: 'message', value: 'Nested template call'}
@@ -131,8 +129,5 @@ new JTLT({
131
129
  this.string('\n');
132
130
  }
133
131
  }
134
- ],
135
- success (result) {
136
- console.log(result);
137
- }
138
- });
132
+ ]
133
+ }));