jtlt 0.2.0 → 0.4.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 +27 -0
- package/README.md +61 -164
- package/demo/calltemplate-params-demo.js +138 -0
- package/demo/codemirror.esm.js +28242 -0
- package/demo/codemirror.js +94 -0
- package/demo/index.css +7 -0
- package/demo/index.html +28 -0
- package/demo/index.js +210 -0
- package/demo/vendor/jamilih/dist/jml.mjs +2341 -0
- package/demo/vendor/jhtml/src/SAJJ/SAJJ.ObjectArrayDelegator.js +356 -0
- package/demo/vendor/jhtml/src/SAJJ/SAJJ.Stringifier.js +186 -0
- package/demo/vendor/jhtml/src/SAJJ/SAJJ.js +746 -0
- package/demo/vendor/jhtml/src/SAJJ/testing/SAJJ.html +33 -0
- package/demo/vendor/jhtml/src/SAJJ/testing/SAJJ.testing.js +25 -0
- package/demo/vendor/jhtml/src/jhtml-browser.js +5 -0
- package/demo/vendor/jhtml/src/jhtml-node.cts +3 -0
- package/demo/vendor/jhtml/src/jhtml-node.js +8 -0
- package/demo/vendor/jhtml/src/jhtml-node.mts +1 -0
- package/demo/vendor/jhtml/src/jhtml.cts +3 -0
- package/demo/vendor/jhtml/src/jhtml.js +602 -0
- package/demo/vendor/jhtml/src/jhtml.mts +1 -0
- package/demo/vendor/jsonpath-plus/dist/index-browser-esm.js +2158 -0
- package/demo/vendor/simple-get-json/dist/index-es.js +151 -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 +334 -124
- 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 +281 -105
- 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 +172 -5
- package/docs/API.md +92 -2
- package/docs/TO-DO.md +168 -0
- package/docs/calltemplate-params.md +251 -0
- package/eslint.config.js +11 -5
- package/package.json +35 -9
- package/pnpm-workspace.yaml +1 -0
- package/rollup.config.js +13 -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 +729 -107
- package/src/StringJoiningTransformer.js +311 -57
- package/src/XPathTransformer.js +27 -12
- package/src/XPathTransformerContext.js +928 -99
- package/src/index-browser.js +5 -0
- package/src/index-node.js +7 -0
- package/src/index.js +502 -98
- package/tsconfig.json +5 -2
- package/typings/xpath2-js.d.ts +40 -1
- package/src/types/xpath2-js.d.ts +0 -2
|
@@ -1,4 +1,108 @@
|
|
|
1
1
|
export default JSONPathTransformerContext;
|
|
2
|
+
export type NumberValue = number | string | {
|
|
3
|
+
value?: number | string;
|
|
4
|
+
count?: string;
|
|
5
|
+
format?: string;
|
|
6
|
+
groupingSeparator?: string;
|
|
7
|
+
groupingSize?: number;
|
|
8
|
+
lang?: string;
|
|
9
|
+
letterValue?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Sort spec types used by applyTemplates() and forEach().
|
|
13
|
+
*/
|
|
14
|
+
export type SortObject = {
|
|
15
|
+
select?: string;
|
|
16
|
+
order?: "ascending" | "descending";
|
|
17
|
+
type?: "text" | "number";
|
|
18
|
+
locale?: string;
|
|
19
|
+
localeOptions?: unknown;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Sort spec types used by applyTemplates() and forEach().
|
|
23
|
+
*/
|
|
24
|
+
export type SortComparator = (a: unknown, b: unknown, ctx: JSONPathTransformerContext) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Sort spec types used by applyTemplates() and forEach().
|
|
27
|
+
*/
|
|
28
|
+
export type SortSpec = string | SortObject | SortComparator | Array<string | SortObject>;
|
|
29
|
+
export type JSONPathTransformerContextConfig<T = "json"> = {
|
|
30
|
+
/**
|
|
31
|
+
* - Data to transform
|
|
32
|
+
*/
|
|
33
|
+
data: null | boolean | number | string | object;
|
|
34
|
+
/**
|
|
35
|
+
* - Parent object
|
|
36
|
+
*/
|
|
37
|
+
parent?: object | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* - Parent property name
|
|
40
|
+
*/
|
|
41
|
+
parentProperty?: string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* - Whether to error on
|
|
44
|
+
* equal priority
|
|
45
|
+
*/
|
|
46
|
+
errorOnEqualPriority?: boolean | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* - Joining transformer
|
|
49
|
+
*/
|
|
50
|
+
joiningTransformer: T extends "json" ? import("./JSONJoiningTransformer.js").default : T extends "string" ? import("./StringJoiningTransformer.js").default : import("./DOMJoiningTransformer.js").default;
|
|
51
|
+
/**
|
|
52
|
+
* - Whether to prevent eval in
|
|
53
|
+
* JSONPath
|
|
54
|
+
*/
|
|
55
|
+
preventEval?: boolean | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Priority resolver function
|
|
58
|
+
*/
|
|
59
|
+
specificityPriorityResolver?: ((path: string) => number) | undefined;
|
|
60
|
+
templates: import("./index.js").JSONPathTemplateObject<T>[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* @typedef {number|string|{
|
|
64
|
+
* value?: number|string,
|
|
65
|
+
* count?: string,
|
|
66
|
+
* format?: string,
|
|
67
|
+
* groupingSeparator?: string,
|
|
68
|
+
* groupingSize?: number,
|
|
69
|
+
* lang?: string,
|
|
70
|
+
* letterValue?: string
|
|
71
|
+
* }} NumberValue
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* Sort spec types used by applyTemplates() and forEach().
|
|
75
|
+
* @typedef {{
|
|
76
|
+
* select?: string,
|
|
77
|
+
* order?: 'ascending' | 'descending',
|
|
78
|
+
* type?: 'text'|'number',
|
|
79
|
+
* locale?: string,
|
|
80
|
+
* localeOptions?: unknown
|
|
81
|
+
* }} SortObject
|
|
82
|
+
* @typedef {(a: unknown, b: unknown,
|
|
83
|
+
* ctx: JSONPathTransformerContext
|
|
84
|
+
* ) => number} SortComparator
|
|
85
|
+
* @typedef {string | SortObject | SortComparator |
|
|
86
|
+
* Array<string|SortObject>} SortSpec
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* @template [T = "json"]
|
|
90
|
+
* @typedef {object} JSONPathTransformerContextConfig
|
|
91
|
+
* @property {null|boolean|number|string|object} data - Data to transform
|
|
92
|
+
* @property {object} [parent] - Parent object
|
|
93
|
+
* @property {string} [parentProperty] - Parent property name
|
|
94
|
+
* @property {boolean} [errorOnEqualPriority] - Whether to error on
|
|
95
|
+
* equal priority
|
|
96
|
+
* @property {T extends "json" ? import('./JSONJoiningTransformer.js').
|
|
97
|
+
* default : T extends "string" ? import('./StringJoiningTransformer.js').
|
|
98
|
+
* default : import('./DOMJoiningTransformer.js').
|
|
99
|
+
* default} joiningTransformer - Joining transformer
|
|
100
|
+
* @property {boolean} [preventEval] - Whether to prevent eval in
|
|
101
|
+
* JSONPath
|
|
102
|
+
* @property {(path: string) => number} [specificityPriorityResolver]
|
|
103
|
+
* Priority resolver function
|
|
104
|
+
* @property {import('./index.js').JSONPathTemplateObject<T>[]} templates
|
|
105
|
+
*/
|
|
2
106
|
/**
|
|
3
107
|
* Execution context for JSONPath-driven template application.
|
|
4
108
|
*
|
|
@@ -6,69 +110,43 @@ export default JSONPathTransformerContext;
|
|
|
6
110
|
* running templates. Exposes helper methods that mirror the underlying
|
|
7
111
|
* joining transformer (e.g., string(), object(), array()) so templates can
|
|
8
112
|
* emit results without referencing the joiner directly.
|
|
113
|
+
* @template [T = "json"]
|
|
9
114
|
*/
|
|
10
|
-
declare class JSONPathTransformerContext {
|
|
11
|
-
/**
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
data: object;
|
|
29
|
-
parent?: object | undefined;
|
|
30
|
-
parentProperty?: string | undefined;
|
|
31
|
-
errorOnEqualPriority?: boolean | undefined;
|
|
32
|
-
joiningTransformer: {
|
|
33
|
-
append: Function;
|
|
34
|
-
get: Function;
|
|
35
|
-
string: Function;
|
|
36
|
-
object: Function;
|
|
37
|
-
array: Function;
|
|
38
|
-
};
|
|
39
|
-
preventEval?: boolean | undefined;
|
|
40
|
-
specificityPriorityResolver?: Function | undefined;
|
|
41
|
-
}, templates: any[]);
|
|
42
|
-
_config: {
|
|
43
|
-
data: object;
|
|
44
|
-
parent?: object | undefined;
|
|
45
|
-
parentProperty?: string | undefined;
|
|
46
|
-
errorOnEqualPriority?: boolean | undefined;
|
|
47
|
-
joiningTransformer: {
|
|
48
|
-
append: Function;
|
|
49
|
-
get: Function;
|
|
50
|
-
string: Function;
|
|
51
|
-
object: Function;
|
|
52
|
-
array: Function;
|
|
53
|
-
};
|
|
54
|
-
preventEval?: boolean | undefined;
|
|
55
|
-
specificityPriorityResolver?: Function | undefined;
|
|
56
|
-
};
|
|
57
|
-
_templates: any[];
|
|
58
|
-
_contextObj: object;
|
|
59
|
-
_origObj: object;
|
|
115
|
+
declare class JSONPathTransformerContext<T = "json"> {
|
|
116
|
+
/**
|
|
117
|
+
* @param {JSONPathTransformerContextConfig<T>} config
|
|
118
|
+
* @param {import('./index.js').JSONPathTemplateObject<T>[]} templates - Array
|
|
119
|
+
* of template objects
|
|
120
|
+
*/
|
|
121
|
+
constructor(config: JSONPathTransformerContextConfig<T>, templates: import("./index.js").JSONPathTemplateObject<T>[]);
|
|
122
|
+
/**
|
|
123
|
+
* Holds the current iteration state (for position calculations).
|
|
124
|
+
* @type {{ index?: number } | undefined}
|
|
125
|
+
*/
|
|
126
|
+
iterationState: {
|
|
127
|
+
index?: number;
|
|
128
|
+
} | undefined;
|
|
129
|
+
_config: JSONPathTransformerContextConfig<T>;
|
|
130
|
+
_templates: import("./index.js").JSONPathTemplateObject<T>[];
|
|
131
|
+
_contextObj: string | number | boolean | object | null;
|
|
132
|
+
_origObj: string | number | boolean | object | null;
|
|
60
133
|
_parent: object;
|
|
61
134
|
_parentProperty: string;
|
|
62
|
-
/** @type {Record<string,
|
|
63
|
-
vars: Record<string,
|
|
64
|
-
/** @type {Record<string,
|
|
65
|
-
propertySets: Record<string,
|
|
66
|
-
/** @type {Record<string,
|
|
67
|
-
keys: Record<string,
|
|
135
|
+
/** @type {Record<string, unknown>} */
|
|
136
|
+
vars: Record<string, unknown>;
|
|
137
|
+
/** @type {Record<string, Record<string, unknown>>} */
|
|
138
|
+
propertySets: Record<string, Record<string, unknown>>;
|
|
139
|
+
/** @type {Record<string, {match: string, use: string}>} */
|
|
140
|
+
keys: Record<string, {
|
|
141
|
+
match: string;
|
|
142
|
+
use: string;
|
|
143
|
+
}>;
|
|
68
144
|
/** @type {boolean | undefined} */
|
|
69
145
|
_initialized: boolean | undefined;
|
|
70
146
|
/** @type {string | undefined} */
|
|
71
147
|
_currPath: string | undefined;
|
|
148
|
+
/** @type {Record<string, any> | undefined} */
|
|
149
|
+
_params: Record<string, any> | undefined;
|
|
72
150
|
/**
|
|
73
151
|
* Triggers an error if equal priority templates are found.
|
|
74
152
|
* @returns {void}
|
|
@@ -76,17 +154,20 @@ declare class JSONPathTransformerContext {
|
|
|
76
154
|
_triggerEqualPriorityError(): void;
|
|
77
155
|
/**
|
|
78
156
|
* Gets the joining transformer from config.
|
|
79
|
-
* @returns {
|
|
157
|
+
* @returns {T extends "json" ? import('./JSONJoiningTransformer.js').
|
|
158
|
+
* default : T extends "string" ? import('./StringJoiningTransformer.js').
|
|
159
|
+
* default : import('./DOMJoiningTransformer.js').
|
|
160
|
+
* default} The joining transformer
|
|
80
161
|
*/
|
|
81
|
-
_getJoiningTransformer():
|
|
162
|
+
_getJoiningTransformer(): T extends "json" ? import("./JSONJoiningTransformer.js").default : T extends "string" ? import("./StringJoiningTransformer.js").default : import("./DOMJoiningTransformer.js").default;
|
|
82
163
|
/**
|
|
83
|
-
* @param {
|
|
84
|
-
* @returns {
|
|
164
|
+
* @param {string | Node} item - Item to append to output
|
|
165
|
+
* @returns {this}
|
|
85
166
|
*/
|
|
86
|
-
appendOutput(item:
|
|
167
|
+
appendOutput(item: string | Node): this;
|
|
87
168
|
/**
|
|
88
169
|
* Gets the current output.
|
|
89
|
-
* @returns {
|
|
170
|
+
* @returns {any} The output from the joining transformer
|
|
90
171
|
*/
|
|
91
172
|
getOutput(): any;
|
|
92
173
|
/**
|
|
@@ -95,14 +176,14 @@ declare class JSONPathTransformerContext {
|
|
|
95
176
|
* to the result tree instead).
|
|
96
177
|
* @param {string} select - JSONPath selector
|
|
97
178
|
* @param {boolean} wrap - Whether to wrap results
|
|
98
|
-
* @returns {
|
|
179
|
+
* @returns {any} The selected value(s)
|
|
99
180
|
*/
|
|
100
181
|
get(select: string, wrap: boolean): any;
|
|
101
182
|
/**
|
|
102
|
-
* @param {
|
|
103
|
-
* @returns {
|
|
183
|
+
* @param {any} v - Value to set
|
|
184
|
+
* @returns {this}
|
|
104
185
|
*/
|
|
105
|
-
set(v: any):
|
|
186
|
+
set(v: any): this;
|
|
106
187
|
/**
|
|
107
188
|
* Apply matching templates to nodes selected by JSONPath, optionally sorted.
|
|
108
189
|
*
|
|
@@ -113,151 +194,280 @@ declare class JSONPathTransformerContext {
|
|
|
113
194
|
* locale, localeOptions }
|
|
114
195
|
* - array: multiple key objects/strings in priority order.
|
|
115
196
|
*
|
|
116
|
-
* @param {string|
|
|
197
|
+
* @param {string|null|
|
|
198
|
+
* {mode?: string, select?: string}
|
|
199
|
+
* } [select] - JSONPath selector or options object
|
|
117
200
|
* @param {string} [mode] - Mode to apply
|
|
118
|
-
* @param {
|
|
119
|
-
* @returns {
|
|
201
|
+
* @param {SortSpec} [sort] - Sort spec
|
|
202
|
+
* @returns {this}
|
|
120
203
|
*/
|
|
121
|
-
applyTemplates(select
|
|
204
|
+
applyTemplates(select?: string | null | {
|
|
205
|
+
mode?: string;
|
|
206
|
+
select?: string;
|
|
207
|
+
}, mode?: string, sort?: SortSpec): this;
|
|
122
208
|
/**
|
|
123
|
-
* @param {string|
|
|
209
|
+
* @param {string|
|
|
210
|
+
* {name: string, withParam?: any[]}} name - Template name or
|
|
211
|
+
* options object
|
|
124
212
|
* @param {any[]} [withParams] - Parameters to pass to template
|
|
125
|
-
* @returns {
|
|
213
|
+
* @returns {this}
|
|
126
214
|
*/
|
|
127
|
-
callTemplate(name: string |
|
|
215
|
+
callTemplate(name: string | {
|
|
216
|
+
name: string;
|
|
217
|
+
withParam?: any[];
|
|
218
|
+
}, withParams?: any[]): this;
|
|
128
219
|
/**
|
|
129
220
|
* Iterate over values selected by JSONPath, optionally sorted.
|
|
130
221
|
*
|
|
131
222
|
* Sort parameter forms are the same as applyTemplates().
|
|
132
223
|
* @param {string} select - JSONPath selector
|
|
133
|
-
* @param {
|
|
134
|
-
*
|
|
135
|
-
*
|
|
224
|
+
* @param {(this: JSONPathTransformerContext<T>,
|
|
225
|
+
* value: any
|
|
226
|
+
* ) => void} cb - Callback function
|
|
227
|
+
* @param {SortSpec} [sort] - Sort spec
|
|
228
|
+
* @returns {this}
|
|
136
229
|
*/
|
|
137
|
-
forEach(select: string, cb:
|
|
230
|
+
forEach(select: string, cb: (this: JSONPathTransformerContext<T>, value: any) => void, sort?: SortSpec): this;
|
|
138
231
|
/**
|
|
139
232
|
* @param {string|object} [select] - JSONPath selector
|
|
140
|
-
* @returns {
|
|
233
|
+
* @returns {this}
|
|
141
234
|
*/
|
|
142
|
-
valueOf(select?: string | object):
|
|
235
|
+
valueOf(select?: string | object): this;
|
|
236
|
+
/**
|
|
237
|
+
* Analyze a string with a regular expression, equivalent to
|
|
238
|
+
* xsl:analyze-string. Processes matching and non-matching substrings
|
|
239
|
+
* with separate callbacks.
|
|
240
|
+
* @param {string} str - The string to analyze
|
|
241
|
+
* @param {string|RegExp} regex - Regular expression to match against
|
|
242
|
+
* @param {{
|
|
243
|
+
* matchingSubstring?: (
|
|
244
|
+
* this: JSONPathTransformerContext<T>,
|
|
245
|
+
* substring: string,
|
|
246
|
+
* groups: string[],
|
|
247
|
+
* regexGroup: (n: number) => string
|
|
248
|
+
* ) => void,
|
|
249
|
+
* nonMatchingSubstring?: (
|
|
250
|
+
* this: JSONPathTransformerContext<T>,
|
|
251
|
+
* substring: string
|
|
252
|
+
* ) => void,
|
|
253
|
+
* flags?: string
|
|
254
|
+
* }} options - Options object
|
|
255
|
+
* @returns {this}
|
|
256
|
+
*/
|
|
257
|
+
analyzeString(str: string, regex: string | RegExp, options?: {
|
|
258
|
+
matchingSubstring?: (this: JSONPathTransformerContext<T>, substring: string, groups: string[], regexGroup: (n: number) => string) => void;
|
|
259
|
+
nonMatchingSubstring?: (this: JSONPathTransformerContext<T>, substring: string) => void;
|
|
260
|
+
flags?: string;
|
|
261
|
+
}): this;
|
|
143
262
|
/**
|
|
144
263
|
* Deep copy selection or current context when omitted.
|
|
145
264
|
* @param {string} [select] - JSONPath selector
|
|
146
|
-
* @returns {
|
|
265
|
+
* @returns {this}
|
|
147
266
|
*/
|
|
148
|
-
copyOf(select?: string):
|
|
267
|
+
copyOf(select?: string): this;
|
|
149
268
|
/**
|
|
150
269
|
* Shallow copy current context; optionally merge property set names.
|
|
151
270
|
* @param {string[]} [propertySets] - Property sets to merge
|
|
152
|
-
* @returns {
|
|
271
|
+
* @returns {this}
|
|
153
272
|
*/
|
|
154
|
-
copy(propertySets?: string[]):
|
|
273
|
+
copy(propertySets?: string[]): this;
|
|
155
274
|
/**
|
|
156
275
|
* @param {string} name - Variable name
|
|
157
276
|
* @param {string} select - JSONPath selector
|
|
158
|
-
* @returns {
|
|
277
|
+
* @returns {this}
|
|
159
278
|
*/
|
|
160
|
-
variable(name: string, select: string):
|
|
279
|
+
variable(name: string, select: string): this;
|
|
161
280
|
/**
|
|
162
|
-
* @param {
|
|
281
|
+
* @param {unknown} json - JSON data to log
|
|
163
282
|
* @returns {void}
|
|
164
283
|
*/
|
|
165
|
-
message(json:
|
|
284
|
+
message(json: unknown): void;
|
|
166
285
|
/**
|
|
167
286
|
* @param {string} str - String value
|
|
168
|
-
* @param {
|
|
169
|
-
*
|
|
287
|
+
* @param {import('./JSONJoiningTransformer.js').
|
|
288
|
+
* SimpleCallback<T>} [cb] - Optional callback to build nested
|
|
289
|
+
* string content
|
|
290
|
+
* @returns {this}
|
|
291
|
+
*/
|
|
292
|
+
string(str: string, cb?: import("./JSONJoiningTransformer.js").SimpleCallback<T>): this;
|
|
293
|
+
/**
|
|
294
|
+
* Append a number to JSON output with xsl:number-like formatting.
|
|
295
|
+
* @param {NumberValue} num - Number value, "position()" string, or
|
|
296
|
+
* options object
|
|
297
|
+
* @returns {this}
|
|
170
298
|
*/
|
|
171
|
-
|
|
299
|
+
number(num: NumberValue): this;
|
|
172
300
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* @
|
|
176
|
-
* @returns {JSONPathTransformerContext}
|
|
301
|
+
* Calculate position in current iteration context.
|
|
302
|
+
* @param {string} [count] - JSONPath expression to match
|
|
303
|
+
* @returns {number}
|
|
177
304
|
*/
|
|
178
|
-
|
|
305
|
+
calculatePosition(count?: string): number;
|
|
306
|
+
/**
|
|
307
|
+
* Format a number according to format string.
|
|
308
|
+
* @param {number} num - Number to format
|
|
309
|
+
* @param {string} format - Format string (1, a, A, i, I, 01, etc.)
|
|
310
|
+
* @param {string} [groupingSeparator] - Separator for grouping
|
|
311
|
+
* @param {number} [groupingSize] - Size of groups
|
|
312
|
+
* @param {string} [locale]
|
|
313
|
+
* @returns {string}
|
|
314
|
+
*/
|
|
315
|
+
_formatNumber(num: number, format: string, groupingSeparator?: string, groupingSize?: number, locale?: string): string;
|
|
316
|
+
/**
|
|
317
|
+
* Convert number to Roman numerals.
|
|
318
|
+
* @param {number} num - Number to convert (1-3999)
|
|
319
|
+
* @returns {string}
|
|
320
|
+
* @private
|
|
321
|
+
*/
|
|
322
|
+
private _toRoman;
|
|
323
|
+
/**
|
|
324
|
+
* Convert number to alphabetic sequence.
|
|
325
|
+
* @param {number} num - Number to convert
|
|
326
|
+
* @param {boolean} uppercase - Use uppercase letters
|
|
327
|
+
* @returns {string}
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
private _toAlphabetic;
|
|
179
331
|
/**
|
|
180
332
|
* Append plain text directly to the output without escaping or JSON
|
|
181
333
|
* stringification. Mirrors the joining transformer API so templates can
|
|
182
334
|
* call `this.plainText()`.
|
|
183
335
|
* @param {string} str - Plain text to append
|
|
184
|
-
* @returns {
|
|
336
|
+
* @returns {this}
|
|
185
337
|
*/
|
|
186
|
-
plainText(str: string):
|
|
338
|
+
plainText(str: string): this;
|
|
187
339
|
/**
|
|
188
340
|
* Set a property value on the current object (JSON joiner). Mirrors the
|
|
189
341
|
* joining transformer API so templates can call `this.propValue()`.
|
|
190
342
|
* @param {string} prop - Property name
|
|
191
|
-
* @param {
|
|
192
|
-
* @returns {
|
|
343
|
+
* @param {any} val - Property value
|
|
344
|
+
* @returns {this}
|
|
193
345
|
*/
|
|
194
|
-
propValue(prop: string, val: any):
|
|
346
|
+
propValue(prop: string, val: any): this;
|
|
195
347
|
/**
|
|
196
348
|
* Build an object. Mirrors the joining transformer API. All joiners now
|
|
197
349
|
* support both signatures: (obj, cb, usePropertySets, propSets) with seed
|
|
198
350
|
* object or (cb, usePropertySets, propSets) without.
|
|
199
351
|
* @param {...any} args - Arguments to pass to joiner
|
|
200
|
-
* @returns {
|
|
352
|
+
* @returns {this}
|
|
201
353
|
*/
|
|
202
|
-
object(...args: any[]):
|
|
354
|
+
object(...args: any[]): this;
|
|
203
355
|
/**
|
|
204
356
|
* Build an array. Mirrors the joining transformer API. All joiners now
|
|
205
357
|
* support both signatures: (arr, cb) with seed array or (cb) without.
|
|
206
358
|
* @param {...any} args - Arguments to pass to joiner
|
|
207
|
-
* @returns {
|
|
359
|
+
* @returns {this}
|
|
208
360
|
*/
|
|
209
|
-
array(...args: any[]):
|
|
361
|
+
array(...args: any[]): this;
|
|
362
|
+
/**
|
|
363
|
+
* Set document-level configuration.
|
|
364
|
+
* @param {import('./StringJoiningTransformer.js').OutputConfig} cfg Text
|
|
365
|
+
* @returns {this}
|
|
366
|
+
*/
|
|
367
|
+
output(cfg: import("./StringJoiningTransformer.js").OutputConfig): this;
|
|
210
368
|
/**
|
|
211
369
|
* Create an element. Mirrors the joining transformer API so templates can
|
|
212
370
|
* call `this.element()`.
|
|
213
371
|
* @param {string} name - Element name
|
|
214
|
-
* @param {
|
|
372
|
+
* @param {Record<string, string>} [atts] - Attributes object
|
|
215
373
|
* @param {any[]} [children] - Child nodes
|
|
216
|
-
* @param {
|
|
217
|
-
*
|
|
374
|
+
* @param {import('./JSONJoiningTransformer.js').
|
|
375
|
+
* SimpleCallback<T>} [cb] - Callback function
|
|
376
|
+
* @returns {this}
|
|
218
377
|
*/
|
|
219
|
-
element(name: string, atts?:
|
|
378
|
+
element(name: string, atts?: Record<string, string>, children?: any[], cb?: import("./JSONJoiningTransformer.js").SimpleCallback<T>): this;
|
|
220
379
|
/**
|
|
221
380
|
* Add an attribute to the most recently opened element. Mirrors the joining
|
|
222
381
|
* transformer API so templates can call `this.attribute()`.
|
|
223
382
|
* @param {string} name - Attribute name
|
|
224
|
-
* @param {string|
|
|
225
|
-
* @
|
|
226
|
-
* @returns {JSONPathTransformerContext}
|
|
383
|
+
* @param {string|Record<string, unknown>} val - Attribute value
|
|
384
|
+
* @returns {this}
|
|
227
385
|
*/
|
|
228
|
-
attribute(name: string, val: string |
|
|
386
|
+
attribute(name: string, val: string | Record<string, unknown>): this;
|
|
229
387
|
/**
|
|
230
388
|
* Append text content. Mirrors the joining transformer API so templates can
|
|
231
389
|
* call `this.text()`.
|
|
232
390
|
* @param {string} txt - Text content
|
|
233
|
-
* @returns {
|
|
391
|
+
* @returns {this}
|
|
392
|
+
*/
|
|
393
|
+
text(txt: string): this;
|
|
394
|
+
/**
|
|
395
|
+
* Add a comment to the most recently opened element. Mirrors the joining
|
|
396
|
+
* transformer API so templates can call `this.comment()`.
|
|
397
|
+
* @param {string} text - Comment text
|
|
398
|
+
* @returns {this}
|
|
234
399
|
*/
|
|
235
|
-
text
|
|
400
|
+
comment(text: string): this;
|
|
401
|
+
/**
|
|
402
|
+
* Add a processing instruction to the most recently opened element.
|
|
403
|
+
* Mirrors the joining transformer API so templates can call
|
|
404
|
+
* `this.processingInstruction()`.
|
|
405
|
+
* @param {string} target - Processing instruction target
|
|
406
|
+
* @param {string} data - Processing instruction data
|
|
407
|
+
* @returns {this}
|
|
408
|
+
*/
|
|
409
|
+
processingInstruction(target: string, data: string): this;
|
|
236
410
|
/**
|
|
237
411
|
* @param {string} name - Property set name
|
|
238
|
-
* @param {
|
|
412
|
+
* @param {Record<string, unknown>} propertySetObj - Property set object
|
|
239
413
|
* @param {any[]} [usePropertySets] - Property sets to use
|
|
240
|
-
* @returns {
|
|
414
|
+
* @returns {this}
|
|
241
415
|
*/
|
|
242
|
-
propertySet(name: string, propertySetObj:
|
|
416
|
+
propertySet(name: string, propertySetObj: Record<string, unknown>, usePropertySets?: any[]): this;
|
|
243
417
|
/**
|
|
244
|
-
* @param {
|
|
418
|
+
* @param {Record<string, unknown>} obj - Object to assign properties to
|
|
245
419
|
* @param {string} name - Property set name
|
|
246
|
-
* @returns {
|
|
420
|
+
* @returns {Record<string, unknown>}
|
|
247
421
|
*/
|
|
248
|
-
_usePropertySets(obj:
|
|
422
|
+
_usePropertySets(obj: Record<string, unknown>, name: string): Record<string, unknown>;
|
|
249
423
|
/**
|
|
250
424
|
* @param {string} name - Key name
|
|
251
|
-
* @param {
|
|
252
|
-
* @returns {
|
|
425
|
+
* @param {any} value - Value to match
|
|
426
|
+
* @returns {any}
|
|
253
427
|
*/
|
|
254
428
|
getKey(name: string, value: any): any;
|
|
255
429
|
/**
|
|
256
430
|
* @param {string} name - Key name
|
|
257
431
|
* @param {string} match - Match expression
|
|
258
432
|
* @param {string} use - Use expression
|
|
259
|
-
* @returns {
|
|
433
|
+
* @returns {this}
|
|
434
|
+
*/
|
|
435
|
+
key(name: string, match: string, use: string): this;
|
|
436
|
+
/**
|
|
437
|
+
* Conditionally execute a callback when a JSONPath selector evaluates
|
|
438
|
+
* to a truthy scalar or a non-empty result set (node set analogue).
|
|
439
|
+
* Mirrors XSLT's xsl:if semantics where a non-empty node set is truthy.
|
|
440
|
+
*
|
|
441
|
+
* Truthiness rules:
|
|
442
|
+
* - If the selection (with wrap) yields an array with length > 0, the
|
|
443
|
+
* condition passes.
|
|
444
|
+
* - Otherwise the (non-wrapped) scalar value is coerced with Boolean();
|
|
445
|
+
* e.g., 0, '', null, undefined => false; others => true.
|
|
446
|
+
*
|
|
447
|
+
* @param {string} select - JSONPath selector expression
|
|
448
|
+
* @param {(this: JSONPathTransformerContext<T>)
|
|
449
|
+
* => void} cb - Callback to invoke if condition is met
|
|
450
|
+
* @returns {this}
|
|
451
|
+
*/
|
|
452
|
+
if(select: string, cb: (this: JSONPathTransformerContext<T>) => void): this;
|
|
453
|
+
/**
|
|
454
|
+
* Internal helper: determine if `select` passes truthiness test.
|
|
455
|
+
* Non-empty wrapped results => true; single item: objects truthy,
|
|
456
|
+
* primitives coerced via Boolean().
|
|
457
|
+
* @param {string} select
|
|
458
|
+
* @returns {boolean}
|
|
459
|
+
*/
|
|
460
|
+
_passesIf(select: string): boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Like `if()`, but also supports an optional fallback callback executed
|
|
463
|
+
* when the test does not pass (similar to xsl:choose/xsl:otherwise).
|
|
464
|
+
* @param {string} select JSONPath selector
|
|
465
|
+
* @param {(this: JSONPathTransformerContext<T>)
|
|
466
|
+
* => void} whenCb Callback when condition passes
|
|
467
|
+
* @param {(this: JSONPathTransformerContext<T>)
|
|
468
|
+
* => void} [otherwiseCb] Callback when condition fails
|
|
469
|
+
* @returns {this}
|
|
260
470
|
*/
|
|
261
|
-
|
|
471
|
+
choose(select: string, whenCb: (this: JSONPathTransformerContext<T>) => void, otherwiseCb?: (this: JSONPathTransformerContext<T>) => void): this;
|
|
262
472
|
}
|
|
263
473
|
//# sourceMappingURL=JSONPathTransformerContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSONPathTransformerContext.d.ts","sourceRoot":"","sources":["../src/JSONPathTransformerContext.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"JSONPathTransformerContext.d.ts","sourceRoot":"","sources":["../src/JSONPathTransformerContext.js"],"names":[],"mappings":";0BAIa,MAAM,GAAC,MAAM,GAAC;IACtB,KAAK,CAAC,EAAE,MAAM,GAAC,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;;;;yBAKS;IACR,MAAM,CAAC,EA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