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.
Files changed (50) hide show
  1. package/CHANGES.md +18 -0
  2. package/README.md +16 -87
  3. package/demo/calltemplate-params-demo.js +138 -0
  4. package/demo/index.html +31 -0
  5. package/demo/index.js +30 -0
  6. package/demo/xpath2-placeholder.js +1 -0
  7. package/dist/AbstractJoiningTransformer.d.ts +83 -9
  8. package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
  9. package/dist/DOMJoiningTransformer.d.ts +85 -25
  10. package/dist/DOMJoiningTransformer.d.ts.map +1 -1
  11. package/dist/JSONJoiningTransformer.d.ts +159 -51
  12. package/dist/JSONJoiningTransformer.d.ts.map +1 -1
  13. package/dist/JSONPathTransformer.d.ts +37 -38
  14. package/dist/JSONPathTransformer.d.ts.map +1 -1
  15. package/dist/JSONPathTransformerContext.d.ts +247 -121
  16. package/dist/JSONPathTransformerContext.d.ts.map +1 -1
  17. package/dist/StringJoiningTransformer.d.ts +132 -41
  18. package/dist/StringJoiningTransformer.d.ts.map +1 -1
  19. package/dist/XPathTransformer.d.ts +35 -20
  20. package/dist/XPathTransformer.d.ts.map +1 -1
  21. package/dist/XPathTransformerContext.d.ts +191 -99
  22. package/dist/XPathTransformerContext.d.ts.map +1 -1
  23. package/dist/index-browser.d.ts +4 -0
  24. package/dist/index-browser.d.ts.map +1 -0
  25. package/dist/index-node.d.ts +4 -0
  26. package/dist/index-node.d.ts.map +1 -0
  27. package/dist/index.d.ts +330 -57
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/types.d.ts +204 -0
  30. package/dist/types.d.ts.map +1 -0
  31. package/docs/API.expanded.md +167 -2
  32. package/docs/API.md +91 -1
  33. package/docs/TO-DO.md +144 -0
  34. package/docs/calltemplate-params.md +251 -0
  35. package/eslint.config.js +9 -5
  36. package/package.json +13 -7
  37. package/pnpm-workspace.yaml +1 -0
  38. package/src/AbstractJoiningTransformer.js +54 -15
  39. package/src/DOMJoiningTransformer.js +275 -28
  40. package/src/JSONJoiningTransformer.js +351 -70
  41. package/src/JSONPathTransformer.js +48 -30
  42. package/src/JSONPathTransformerContext.js +308 -104
  43. package/src/StringJoiningTransformer.js +311 -57
  44. package/src/XPathTransformer.js +27 -12
  45. package/src/XPathTransformerContext.js +467 -89
  46. package/src/index-browser.js +5 -0
  47. package/src/index-node.js +7 -0
  48. package/src/index.js +498 -97
  49. package/typings/xpath2-js.d.ts +40 -1
  50. package/src/types/xpath2-js.d.ts +0 -2
@@ -1,4 +1,53 @@
1
1
  export default JSONJoiningTransformer;
2
+ export type ObjectCallback = (this: JSONJoiningTransformer, obj: Record<string, unknown>) => void;
3
+ export type ArrayCallback = (this: JSONJoiningTransformer, arr: any[]) => void;
4
+ export type SimpleCallback<T = "json"> = (this: T extends "json" ? JSONJoiningTransformer : T extends "string" ? import("./StringJoiningTransformer.js").default : import("./DOMJoiningTransformer.js").default) => void;
5
+ /**
6
+ * Attributes object for element() allowing standard string attributes
7
+ * plus special helpers: dataset (object) and $a (ordered attribute array).
8
+ */
9
+ export type ElementAttributes = Record<string, unknown> & {
10
+ dataset?: Record<string, string>;
11
+ $a?: Array<[string, string]>;
12
+ };
13
+ export type ElementInfo = {
14
+ attsObj: Record<string, unknown>;
15
+ jmlChildren: unknown[];
16
+ };
17
+ /**
18
+ * @callback ObjectCallback
19
+ * @this {JSONJoiningTransformer}
20
+ * @param {Record<string, unknown>} obj
21
+ * @returns {void}
22
+ */
23
+ /**
24
+ * @callback ArrayCallback
25
+ * @this {JSONJoiningTransformer}
26
+ * @param {any[]} arr
27
+ * @returns {void}
28
+ */
29
+ /**
30
+ * @template [T = "json"]
31
+ * @callback SimpleCallback
32
+ * @this {T extends "json" ? JSONJoiningTransformer :
33
+ * T extends "string" ? import('./StringJoiningTransformer.js').default
34
+ * : import('./DOMJoiningTransformer.js').default}
35
+ * @returns {void}
36
+ */
37
+ /**
38
+ * Attributes object for element() allowing standard string attributes
39
+ * plus special helpers: dataset (object) and $a (ordered attribute array).
40
+ * @typedef {Record<string, unknown> & {
41
+ * dataset?: Record<string, string>,
42
+ * $a?: Array<[string, string]>
43
+ * }} ElementAttributes
44
+ */
45
+ /**
46
+ * @typedef {{
47
+ * attsObj: Record<string, unknown>,
48
+ * jmlChildren: unknown[]
49
+ * }} ElementInfo
50
+ */
2
51
  /**
3
52
  * JSON-based joining transformer for building JSON/JavaScript objects.
4
53
  *
@@ -6,33 +55,42 @@ export default JSONJoiningTransformer;
6
55
  * append() will push to arrays or shallow-merge into objects; string/number/
7
56
  * boolean/null add primitives accordingly. It does not perform HTML escaping
8
57
  * or string serialization; it builds real JS values.
58
+ * @extends {AbstractJoiningTransformer<"json">}
9
59
  */
10
- declare class JSONJoiningTransformer extends AbstractJoiningTransformer {
60
+ declare class JSONJoiningTransformer extends AbstractJoiningTransformer<"json"> {
11
61
  /**
12
- * @param {any[]|object} [o] - Initial object or array
13
- * @param {object} [cfg] - Configuration object
62
+ * @param {any[]|Record<string, unknown>} [o] - Initial object or array
63
+ * @param {import('./AbstractJoiningTransformer.js').
64
+ * JSONJoiningTransformerConfig} [cfg] - Configuration object
14
65
  */
15
- constructor(o?: any[] | object, cfg?: object);
16
- /** @type {any[]|object} */
17
- _obj: any[] | object;
66
+ constructor(o?: any[] | Record<string, unknown>, cfg?: import("./AbstractJoiningTransformer.js").JSONJoiningTransformerConfig);
67
+ /** @type {any[]|Record<string, unknown>} */
68
+ _obj: any[] | Record<string, unknown>;
18
69
  /** @type {boolean | undefined} */
19
70
  _objPropState: boolean | undefined;
20
71
  /** @type {boolean | undefined} */
21
72
  _arrItemState: boolean | undefined;
22
- /** @type {{attsObj: Record<string, any>, jmlChildren: any[]}[]} */
23
- _elementStack: {
24
- attsObj: Record<string, any>;
25
- jmlChildren: any[];
26
- }[];
73
+ /** @type {ElementInfo[]} */
74
+ _elementStack: ElementInfo[];
75
+ /** @type {Record<string, unknown>} */
76
+ propertySets: Record<string, unknown>;
77
+ /** @type {any[]} */
78
+ _docs: any[];
79
+ /** @type {Array<{href: string, document: any, format?: string}>} */
80
+ _resultDocuments: Array<{
81
+ href: string;
82
+ document: any;
83
+ format?: string;
84
+ }>;
27
85
  /**
28
86
  * Directly appends an item to the internal array without checks.
29
- * @param {*} item - Item to append
87
+ * @param {any} item - Item to append
30
88
  * @returns {void}
31
89
  */
32
90
  rawAppend(item: any): void;
33
91
  /**
34
92
  * Appends an item to the current object or array.
35
- * @param {*} item - Item to append
93
+ * @param {any} item - Item to append
36
94
  * @returns {JSONJoiningTransformer}
37
95
  */
38
96
  append(item: any): JSONJoiningTransformer;
@@ -40,45 +98,40 @@ declare class JSONJoiningTransformer extends AbstractJoiningTransformer {
40
98
  * Gets the current object or array. If unwrapSingleResult config option is
41
99
  * enabled and the root array contains exactly one element, returns that
42
100
  * element directly (unwrapped).
43
- * @returns {any[]|object|any}
101
+ * @returns {any[]|Record<string, unknown>|any}
44
102
  */
45
- get(): any[] | object | any;
103
+ get(): any[] | Record<string, unknown> | any;
46
104
  /**
47
105
  * Sets a property value on the current object.
48
106
  * @param {string} prop - Property name
49
- * @param {*} val - Property value
107
+ * @param {any} val - Property value
50
108
  * @returns {void}
51
109
  */
52
110
  propValue(prop: string, val: any): void;
53
111
  /**
54
- * @param {object|Function} [objOrCb] - Seed object to start with, or
55
- * callback if no seed provided
56
- * @param {Function|any[]} [cbOrUsePropertySets] - Callback to be executed
57
- * on this transformer but with a context nested within the newly created
58
- * object, or array of property set names if first arg was an object
59
- * @param {any[]|object} [usePropertySetsOrPropSets] - Array of string
60
- * property set names to copy onto the new object, or propSets if second
61
- * arg was a callback
62
- * @param {object} [propSets] - An object of key-value pairs to copy onto
63
- * the new object
112
+ * @param {Record<string, unknown>|ObjectCallback} [objOrCb]
113
+ * Seed object or callback.
114
+ * @param {ObjectCallback|any[]} [cbOrUsePropertySets] Callback or sets.
115
+ * @param {any[]|Record<string, unknown>} [usePropertySetsOrPropSets]
116
+ * Sets or prop sets.
117
+ * @param {Record<string, unknown>} [propSets] Key-value pairs to add.
64
118
  * @returns {JSONJoiningTransformer}
65
119
  */
66
- object(objOrCb?: object | Function, cbOrUsePropertySets?: Function | any[], usePropertySetsOrPropSets?: any[] | object, propSets?: object): JSONJoiningTransformer;
120
+ object(objOrCb?: Record<string, unknown> | ObjectCallback, cbOrUsePropertySets?: ObjectCallback | any[], usePropertySetsOrPropSets?: any[] | Record<string, unknown>, propSets?: Record<string, unknown>): JSONJoiningTransformer;
67
121
  /**
68
122
  * Creates a new array and executes a callback in its context.
69
- * @param {any[]|Function} [arrOrCb] - Seed array to start with, or callback
70
- * if no seed provided
71
- * @param {Function} [cb] - Callback function (if first arg was a seed array)
123
+ * @param {any[]|ArrayCallback} [arrOrCb] Seed array or callback.
124
+ * @param {ArrayCallback} [cb] Callback when first arg was array.
72
125
  * @returns {JSONJoiningTransformer}
73
126
  */
74
- array(arrOrCb?: any[] | Function, cb?: Function): JSONJoiningTransformer;
127
+ array(arrOrCb?: any[] | ArrayCallback, cb?: ArrayCallback): JSONJoiningTransformer;
75
128
  /**
76
129
  * Appends a string value.
77
- * @param {string} str - String value
78
- * @param {Function} [cb] - Callback function (unused)
130
+ * @param {string} str String value.
131
+ * @param {SimpleCallback} [cb] Unused callback.
79
132
  * @returns {JSONJoiningTransformer}
80
133
  */
81
- string(str: string, cb?: Function): JSONJoiningTransformer;
134
+ string(str: string, cb?: SimpleCallback): JSONJoiningTransformer;
82
135
  /**
83
136
  * Appends a number value.
84
137
  * @param {number} num - Number value
@@ -109,31 +162,58 @@ declare class JSONJoiningTransformer extends AbstractJoiningTransformer {
109
162
  nonfiniteNumber(num: number): JSONJoiningTransformer;
110
163
  /**
111
164
  * Appends a function value (JavaScript mode only).
112
- * @param {Function} func - Function to append
165
+ * @param {(...args: any[]) => any} func Function to append.
113
166
  * @returns {JSONJoiningTransformer}
114
167
  */
115
- function(func: Function): JSONJoiningTransformer;
168
+ function(func: (...args: any[]) => any): JSONJoiningTransformer;
116
169
  /**
117
- * Build a Jamilih-style element JSON array and append to current container.
118
- * Result form: ['tag', {attr: 'val'}, child1, child2, ...]
119
- * Helpers: dataset -> data-*; $a -> ordered attributes.
120
- * Supported signatures mirror StringJoiningTransformer.element.
121
- * @param {string|Element|object} elName - Element name or Element-like
122
- * @param {object|any[]|Function} [atts] - Attributes object or children or cb
123
- * @param {any[]|Function} [childNodes] - Child nodes array or callback
124
- * @param {Function} [cb] - Callback for building children/attributes
170
+ * @param {import('./StringJoiningTransformer.js').OutputConfig} cfg
125
171
  * @returns {JSONJoiningTransformer}
126
172
  */
127
- element(elName: string | Element | object, atts?: object | any[] | Function, childNodes?: any[] | Function, cb?: Function): JSONJoiningTransformer;
173
+ output(cfg: import("./StringJoiningTransformer.js").OutputConfig): JSONJoiningTransformer;
174
+ _outputConfig: any;
175
+ mediaType: string | undefined;
176
+ /**
177
+ * Build a Jamilih-style element JSON array and append to current container.
178
+ * Result form: ['tag', {attr: 'val'}, child1, child2, ...]
179
+ * Helpers: dataset -> data-*; $a -> ordered attributes.
180
+ * Supported signatures mirror StringJoiningTransformer.element.
181
+ * @param {string|Element} elName Element name or Element-like.
182
+ * @param {ElementAttributes|any[]|SimpleCallback} [atts]
183
+ * Attrs, children, or cb.
184
+ * @param {any[]|SimpleCallback} [childNodes] Children or cb.
185
+ * @param {SimpleCallback} [cb] Builder callback.
186
+ * @returns {JSONJoiningTransformer}
187
+ */
188
+ element(elName: string | Element, atts?: ElementAttributes | any[] | SimpleCallback, childNodes?: any[] | SimpleCallback, cb?: SimpleCallback): JSONJoiningTransformer;
189
+ root: any;
128
190
  /**
129
191
  * Adds/updates an attribute for the most recently open element built via
130
192
  * a callback-driven element(). When not in an element callback context,
131
193
  * throws. Supports the same dataset/$a helpers as string joiner.
132
194
  * @param {string} name - Attribute name (or helper: dataset, $a)
133
- * @param {string|object|any[]} val - Attribute value or helper object
195
+ * @param {string|Record<string, unknown>|unknown[]} val
196
+ * Attribute value or helper object
197
+ * @returns {JSONJoiningTransformer}
198
+ */
199
+ attribute(name: string, val: string | Record<string, unknown> | unknown[]): JSONJoiningTransformer;
200
+ /**
201
+ * Adds a comment node (string) as a child within the current
202
+ * element() callback context. Outside of an element callback,
203
+ * simply appends the comment to the current array/object like string().
204
+ * @param {string} txt - Comment content
205
+ * @returns {JSONJoiningTransformer}
206
+ */
207
+ comment(txt: string): JSONJoiningTransformer;
208
+ /**
209
+ * Adds a comment node (string) as a child within the current
210
+ * element() callback context. Outside of an element callback,
211
+ * simply appends the comment to the current array/object like string().
212
+ * @param {string} target - processing instruction content
213
+ * @param {string} data - processing instruction content
134
214
  * @returns {JSONJoiningTransformer}
135
215
  */
136
- attribute(name: string, val: string | object | any[]): JSONJoiningTransformer;
216
+ processingInstruction(target: string, data: string): JSONJoiningTransformer;
137
217
  /**
138
218
  * Adds a text node (string) as a child within the current element() callback
139
219
  * context. Outside of an element callback, simply appends the text to the
@@ -149,12 +229,40 @@ declare class JSONJoiningTransformer extends AbstractJoiningTransformer {
149
229
  */
150
230
  plainText(str: string): JSONJoiningTransformer;
151
231
  /**
152
- * Helper method to use property sets (to be implemented).
153
- * @param {object} obj - Object to apply property set to
232
+ * Creates a new JSON document and executes a callback in its context.
233
+ * Similar to XSLT's xsl:document, this allows templates to generate
234
+ * multiple output documents. The created document is pushed to this._docs
235
+ * and will be included in the result when exposeDocuments is true.
236
+ *
237
+ * @param {(this: JSONJoiningTransformer) => void} cb
238
+ * Callback that builds the document content
239
+ * @param {import('./StringJoiningTransformer.js').OutputConfig} [cfg]
240
+ * Output configuration for the document (encoding, doctype, etc.)
241
+ * @returns {JSONJoiningTransformer}
242
+ */
243
+ document(cb: (this: JSONJoiningTransformer) => void, cfg?: import("./StringJoiningTransformer.js").OutputConfig): JSONJoiningTransformer;
244
+ /**
245
+ * Creates a new result document with metadata (href, format).
246
+ * Similar to XSLT's xsl:result-document, this allows templates to generate
247
+ * multiple output documents with associated metadata like URIs. The created
248
+ * document is stored in this._resultDocuments with the provided href.
249
+ *
250
+ * @param {string} href - URI/path for the result document
251
+ * @param {(this: JSONJoiningTransformer) => void} cb
252
+ * Callback that builds the document content
253
+ * @param {import('./StringJoiningTransformer.js').OutputConfig} [cfg]
254
+ * Output configuration for the document (encoding, doctype, format, etc.)
255
+ * @returns {JSONJoiningTransformer}
256
+ */
257
+ resultDocument(href: string, cb: (this: JSONJoiningTransformer) => void, cfg?: import("./StringJoiningTransformer.js").OutputConfig): JSONJoiningTransformer;
258
+ /**
259
+ * Helper method to use property sets.
260
+ * @param {Record<string, unknown>} obj - Object to which to apply
261
+ * property set
154
262
  * @param {string} psName - Property set name
155
- * @returns {object}
263
+ * @returns {Record<string, unknown>}
156
264
  */
157
- _usePropertySets(obj: object, psName: string): object;
265
+ _usePropertySets(obj: Record<string, unknown>, psName: string): Record<string, unknown>;
158
266
  }
159
267
  import AbstractJoiningTransformer from './AbstractJoiningTransformer.js';
160
268
  //# sourceMappingURL=JSONJoiningTransformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"JSONJoiningTransformer.d.ts","sourceRoot":"","sources":["../src/JSONJoiningTransformer.js"],"names":[],"mappings":";AAYA;;;;;;;GAOG;AACH;IACE;;;OAGG;IACH,gBAHW,GAAG,EAAE,GAAC,MAAM,QACZ,MAAM,EAYhB;IARC,2BAA2B;IAC3B,MADW,GAAG,EAAE,GAAC,MAAM,CACJ;IACnB,kCAAkC;IAClC,eADW,OAAO,GAAG,SAAS,CACA;IAC9B,kCAAkC;IAClC,eADW,OAAO,GAAG,SAAS,CACA;IAC9B,mEAAmE;IACnE,eADW;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,WAAW,EAAE,GAAG,EAAE,CAAA;KAAC,EAAE,CACxC;IAGzB;;;;OAIG;IACH,gBAHW,GAAC,GACC,IAAI,CAIhB;IAED;;;;OAIG;IACH,aAHW,GAAC,GACC,sBAAsB,CAalC;IAED;;;;;OAKG;IACH,OAFa,GAAG,EAAE,GAAC,MAAM,GAAC,GAAG,CAS5B;IAED;;;;;OAKG;IACH,gBAJW,MAAM,OACN,GAAC,GACC,IAAI,CAShB;IAGD;;;;;;;;;;;;OAYG;IACH,iBAZW,MAAM,WAAS,wBAEf,WAAS,GAAG,EAAE,8BAGd,GAAG,EAAE,GAAC,MAAM,aAGZ,MAAM,GAEJ,sBAAsB,CAsDlC;IAED;;;;;;OAMG;IACH,gBALW,GAAG,EAAE,WAAS,kBAGZ,sBAAsB,CA+BlC;IAED;;;;;OAKG;IACH,YAJW,MAAM,kBAEJ,sBAAsB,CAMlC;IAED;;;;OAIG;IACH,YAHW,MAAM,GACJ,sBAAsB,CAKlC;IAED;;;;OAIG;IACH,cAHW,OAAO,GACL,sBAAsB,CAKlC;IAED;;;OAGG;IACH,QAFa,sBAAsB,CAKlC;IAED;;;OAGG;IACH,aAFa,sBAAsB,CAUlC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACJ,sBAAsB,CAUlC;IAED;;;;OAIG;IACH,0BAFa,sBAAsB,CAUlC;IAED;;;;;;;;;;OAUG;IACH,gBANW,MAAM,GAAC,OAAO,GAAC,MAAM,SACrB,MAAM,GAAC,GAAG,EAAE,WAAS,eACrB,GAAG,EAAE,WAAS,kBAEZ,sBAAsB,CA2FlC;IAED;;;;;;;OAOG;IACH,gBAJW,MAAM,OACN,MAAM,GAAC,MAAM,GAAC,GAAG,EAAE,GACjB,sBAAsB,CA8BlC;IAED;;;;;;OAMG;IACH,UAHW,MAAM,GACJ,sBAAsB,CAWlC;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,sBAAsB,CAKlC;IAED;;;;;OAKG;IACH,sBAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAUlB;CACF;uCApdsC,iCAAiC"}
1
+ {"version":3,"file":"JSONJoiningTransformer.d.ts","sourceRoot":"","sources":["../src/JSONJoiningTransformer.js"],"names":[],"mappings":";iEAeW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACrB,IAAI;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AAC,OAAO,EAAE,GAEtC,sBAAsB,CA+BlC;IAED;;;;;;OAMG;IACH,aAHW,MAAM,GACJ,sBAAsB,CAWlC;IAED;;;;;;;OAOG;IACH,8BAJW,MAAM,QACN,MAAM,GACJ,sBAAsB,CAWlC;IAED;;;;;;OAMG;IACH,UAHW,MAAM,GACJ,sBAAsB,CAWlC;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,sBAAsB,CAKlC;IAED;;;;;;;;;;;OAWG;IACH,aANW,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,QAEtC,OAAO,+BAA+B,EAAE,YAAY,GAElD,sBAAsB,CA4BlC;IAED;;;;;;;;;;;;OAYG;IACH,qBAPW,MAAM,MACN,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,QAEtC,OAAO,+BAA+B,EAAE,YAAY,GAElD,sBAAsB,CAqFlC;IAED;;;;;;OAMG;IACH,sBALW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UAEvB,MAAM,GACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQnC;CACF;uCA7uBsC,iCAAiC"}
@@ -6,8 +6,9 @@ export default JSONPathTransformer;
6
6
  * optional `mode`), sorts by priority, and invokes the winning template.
7
7
  * If no template matches, built-in default rules emulate XSLT-like behavior
8
8
  * for objects, arrays, scalars, etc.
9
+ * @template T
9
10
  */
10
- declare class JSONPathTransformer {
11
+ declare class JSONPathTransformer<T> {
11
12
  /**
12
13
  * @param {string} select - JSONPath selector
13
14
  * @returns {string} Absolute JSONPath
@@ -16,80 +17,78 @@ declare class JSONPathTransformer {
16
17
  static DefaultTemplateRules: {
17
18
  transformRoot: {
18
19
  /**
19
- * @param {*} value - Value
20
- * @param {{mode: string}} cfg - Configuration
20
+ * @template U
21
+ * @this {JSONPathTransformerContext<U>}
22
+ * @param {any} value - Value
23
+ * @param {{mode?: string}} cfg - Configuration
21
24
  * @returns {void}
22
25
  */
23
- template(value: any, cfg: {
24
- mode: string;
26
+ template<U>(this: JSONPathTransformerContext<U>, value: any, cfg: {
27
+ mode?: string;
25
28
  }): void;
26
29
  };
27
30
  transformPropertyNames: {
28
31
  /**
29
- * @param {*} value - Current context value
30
- * @returns {*}
32
+ * @param {any} value - Current context value
33
+ * @returns {any}
31
34
  */
32
35
  template(value: any): any;
33
36
  };
34
37
  transformObjects: {
35
38
  /**
36
- * @param {*} value - Value
37
- * @param {{mode: string}} cfg - Configuration
39
+ * @this {JSONPathTransformerContext}
40
+ * @param {any} value - Value
41
+ * @param {{mode?: string}} cfg - Configuration
38
42
  * @returns {void}
39
43
  */
40
- template(value: any, cfg: {
41
- mode: string;
44
+ template(this: JSONPathTransformerContext<"json">, value: any, cfg: {
45
+ mode?: string;
42
46
  }): void;
43
47
  };
44
48
  transformArrays: {
45
49
  /**
46
- * @param {*} value - Value
47
- * @param {{mode: string}} cfg - Configuration
50
+ * @this {JSONPathTransformerContext}
51
+ * @param {any} value - Value
52
+ * @param {{mode?: string}} cfg - Configuration
48
53
  * @returns {void}
49
54
  */
50
- template(value: any, cfg: {
51
- mode: string;
55
+ template(this: JSONPathTransformerContext<"json">, value: any, cfg: {
56
+ mode?: string;
52
57
  }): void;
53
58
  };
54
59
  transformScalars: {
55
60
  /**
56
- * @returns {*}
61
+ * @this {JSONPathTransformerContext}
62
+ * @returns {JSONPathTransformerContext}
57
63
  */
58
- template(): any;
64
+ template(this: JSONPathTransformerContext<"json">): JSONPathTransformerContext;
59
65
  };
60
66
  transformFunctions: {
61
67
  /**
62
- * @param {Function} value - Function at current context
63
- * @returns {*}
68
+ * @param {( ...args: any[]) => any} value - Function at current context
69
+ * @returns {any}
64
70
  */
65
- template(value: Function): any;
71
+ template(value: (...args: any[]) => any): any;
66
72
  };
67
73
  };
68
74
  /**
69
- * @param {object} config - Configuration object
70
- * @param {boolean} [config.errorOnEqualPriority] - Whether to error on
71
- * equal priority templates
72
- * @param {any[]} config.templates - Array of template objects
75
+ * @param {import('./JSONPathTransformerContext.js').
76
+ * JSONPathTransformerContextConfig<T>} config - Configuration object
73
77
  */
74
- constructor(config: {
75
- errorOnEqualPriority?: boolean | undefined;
76
- templates: any[];
77
- });
78
- _config: {
79
- errorOnEqualPriority?: boolean | undefined;
80
- templates: any[];
81
- };
82
- /** @type {any[]} */
83
- rootTemplates: any[];
84
- templates: any[];
78
+ constructor(config: import("./JSONPathTransformerContext.js").JSONPathTransformerContextConfig<T>);
79
+ _config: import("./JSONPathTransformerContext.js").JSONPathTransformerContextConfig<T>;
80
+ /** @type {import('./index.js').JSONPathTemplateObject<T>[]} */
81
+ rootTemplates: import("./index.js").JSONPathTemplateObject<T>[];
82
+ templates: import("./index.js").JSONPathTemplateObject<T>[];
85
83
  /**
86
84
  * @returns {void}
87
85
  */
88
86
  _triggerEqualPriorityError(): void;
89
87
  /**
90
- * @param {string} mode - Transformation mode
91
- * @returns {*} The transformation result
88
+ * @param {string} [mode] - Transformation mode
89
+ * @returns {import('./index.js').ResultType<T>} The transformation result
92
90
  */
93
- transform(mode: string): any;
91
+ transform(mode?: string): import("./index.js").ResultType<T>;
94
92
  }
93
+ import JSONPathTransformerContext from './JSONPathTransformerContext.js';
95
94
  //# sourceMappingURL=JSONPathTransformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"JSONPathTransformer.d.ts","sourceRoot":"","sources":["../src/JSONPathTransformer.js"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AACH;IAsEE;;;OAGG;IACH,oCAHW,MAAM,GACJ,MAAM,CAQlB;IAGD;;YAEI;;;;eAIG;4BAHQ,GAAC,OACD;gBAAC,IAAI,EAAE,MAAM,CAAA;aAAC,GACZ,IAAI;;;YAOjB;;;eAGG;4BAFQ,GAAC,GACC,GAAC;;;YAWd;;;;eAIG;4BAHQ,GAAC,OACD;gBAAC,IAAI,EAAE,MAAM,CAAA;aAAC,GACZ,IAAI;;;YAOjB;;;;eAIG;4BAHQ,GAAC,OACD;gBAAC,IAAI,EAAE,MAAM,CAAA;aAAC,GACZ,IAAI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