jtlt 0.1.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 (43) hide show
  1. package/.editorconfig +16 -0
  2. package/CHANGES.md +5 -0
  3. package/LICENSE-MIT.txt +21 -0
  4. package/README.md +534 -0
  5. package/dist/AbstractJoiningTransformer.d.ts +42 -0
  6. package/dist/AbstractJoiningTransformer.d.ts.map +1 -0
  7. package/dist/DOMJoiningTransformer.d.ts +113 -0
  8. package/dist/DOMJoiningTransformer.d.ts.map +1 -0
  9. package/dist/JSONJoiningTransformer.d.ts +160 -0
  10. package/dist/JSONJoiningTransformer.d.ts.map +1 -0
  11. package/dist/JSONPathTransformer.d.ts +95 -0
  12. package/dist/JSONPathTransformer.d.ts.map +1 -0
  13. package/dist/JSONPathTransformerContext.d.ts +263 -0
  14. package/dist/JSONPathTransformerContext.d.ts.map +1 -0
  15. package/dist/StringJoiningTransformer.d.ts +168 -0
  16. package/dist/StringJoiningTransformer.d.ts.map +1 -0
  17. package/dist/XPathTransformer.d.ts +51 -0
  18. package/dist/XPathTransformer.d.ts.map +1 -0
  19. package/dist/XPathTransformerContext.d.ts +260 -0
  20. package/dist/XPathTransformerContext.d.ts.map +1 -0
  21. package/dist/XSLTStyleJSONPathResolver.d.ts +16 -0
  22. package/dist/XSLTStyleJSONPathResolver.d.ts.map +1 -0
  23. package/dist/index.d.ts +168 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/docs/API.expanded.md +263 -0
  26. package/docs/API.md +69 -0
  27. package/eslint.config.js +30 -0
  28. package/package.json +53 -0
  29. package/pnpm-workspace.yaml +3 -0
  30. package/src/AbstractJoiningTransformer.js +73 -0
  31. package/src/DOMJoiningTransformer.js +237 -0
  32. package/src/JSONJoiningTransformer.js +472 -0
  33. package/src/JSONPathTransformer.js +159 -0
  34. package/src/JSONPathTransformerContext.js +807 -0
  35. package/src/StringJoiningTransformer.js +589 -0
  36. package/src/XPathTransformer.js +94 -0
  37. package/src/XPathTransformerContext.js +496 -0
  38. package/src/XSLTStyleJSONPathResolver.js +39 -0
  39. package/src/index.js +299 -0
  40. package/src/types/xpath2-js.d.ts +2 -0
  41. package/tsconfig-prod.json +19 -0
  42. package/tsconfig.json +14 -0
  43. package/typings/xpath2-js.d.ts +2 -0
@@ -0,0 +1,168 @@
1
+ export default StringJoiningTransformer;
2
+ /**
3
+ *
4
+ */
5
+ /**
6
+ * Joining transformer that builds a string result.
7
+ *
8
+ * This transformer provides a fluent API to compose strings while supporting
9
+ * object/array-building semantics similar to template languages. Most methods
10
+ * funnel through append(), which is state-aware:
11
+ *
12
+ * - Inside object(): values go to object properties via propOnly()/propValue().
13
+ * - Inside array(): values are pushed to the current array.
14
+ * - Otherwise: values are concatenated into the internal string buffer.
15
+ *
16
+ * Escaping rules:
17
+ * - text(): escapes HTML special chars (& and <) and will close an open tag.
18
+ * - string(): no HTML escaping or JSON stringification; context-aware.
19
+ * - plainText(): raw append to the top-level string buffer (bypasses state).
20
+ * - rawAppend(): like plainText() but documented as lower-level.
21
+ *
22
+ * HTML/XML helpers:
23
+ * - element() and attribute() allow building tags with optional auto-escaping
24
+ * for attribute values unless cfg.preEscapedAttributes is set.
25
+ *
26
+ * Configuration hints (see joiningConfig in JTLT):
27
+ * - cfg.xmlElements: switch element() serializer to XML mode (self-closing,
28
+ * name mapping rules differ, etc.).
29
+ * - cfg.preEscapedAttributes: skip escaping attribute values.
30
+ * - cfg.JHTMLForJSON / cfg.mode: affect how object()/array() serialize.
31
+ */
32
+ declare class StringJoiningTransformer extends AbstractJoiningTransformer {
33
+ /**
34
+ * @param {string} s - Initial string
35
+ * @param {object} cfg - Configuration object
36
+ */
37
+ constructor(s: string, cfg: object);
38
+ _str: string;
39
+ /** @type {any} */
40
+ _objPropTemp: any;
41
+ /** @type {boolean | undefined} */
42
+ propOnlyState: boolean | undefined;
43
+ /** @type {boolean | undefined} */
44
+ _arrItemState: boolean | undefined;
45
+ /** @type {boolean | undefined} */
46
+ _objPropState: boolean | undefined;
47
+ /** @type {any} */
48
+ _obj: any;
49
+ /** @type {any[]} */
50
+ _arr: any[];
51
+ /** @type {string | undefined} */
52
+ _strTemp: string | undefined;
53
+ /** @type {Record<string, any>} */
54
+ propertySets: Record<string, any>;
55
+ /**
56
+ * @param {string|*} s - String or value to append
57
+ * @returns {StringJoiningTransformer}
58
+ */
59
+ append(s: string | any): StringJoiningTransformer;
60
+ /**
61
+ * @returns {string}
62
+ */
63
+ get(): string;
64
+ /**
65
+ * @param {string} prop - Property name
66
+ * @param {*} val - Property value
67
+ * @returns {StringJoiningTransformer}
68
+ */
69
+ propValue(prop: string, val: any): StringJoiningTransformer;
70
+ /**
71
+ * @param {string} prop - Property name
72
+ * @param {Function} cb - Callback function
73
+ * @returns {StringJoiningTransformer}
74
+ */
75
+ propOnly(prop: string, cb: Function): StringJoiningTransformer;
76
+ /**
77
+ * @param {object|Element} obj - Object to serialize
78
+ * @param {Function} cb - Callback function
79
+ * @param {any[]} [usePropertySets] - Property sets to use
80
+ * @param {object} [propSets] - Additional property sets
81
+ * @returns {StringJoiningTransformer}
82
+ */
83
+ object(obj: object | Element, cb: Function, usePropertySets?: any[], propSets?: object): StringJoiningTransformer;
84
+ /**
85
+ * @param {any[]|Element} [arr] - Array to serialize
86
+ * @param {Function} [cb] - Callback function
87
+ * @returns {StringJoiningTransformer}
88
+ */
89
+ array(arr?: any[] | Element, cb?: Function): StringJoiningTransformer;
90
+ /**
91
+ * @param {string|Element|object} str - String value or element
92
+ * @param {Function} [cb] - Callback function
93
+ * @returns {StringJoiningTransformer}
94
+ */
95
+ string(str: string | Element | object, cb?: Function): StringJoiningTransformer;
96
+ /**
97
+ * @param {number|Element|object} num - Number value or element
98
+ * @returns {StringJoiningTransformer}
99
+ */
100
+ number(num: number | Element | object): StringJoiningTransformer;
101
+ /**
102
+ * @param {boolean|Element|object} bool - Boolean value or element
103
+ * @returns {StringJoiningTransformer}
104
+ */
105
+ boolean(bool: boolean | Element | object): StringJoiningTransformer;
106
+ /**
107
+ * @returns {StringJoiningTransformer}
108
+ */
109
+ null(): StringJoiningTransformer;
110
+ /**
111
+ * @returns {StringJoiningTransformer}
112
+ */
113
+ undefined(): StringJoiningTransformer;
114
+ /**
115
+ * @param {number|Element} num - Non-finite number (NaN, Infinity, -Infinity)
116
+ * @returns {StringJoiningTransformer}
117
+ */
118
+ nonfiniteNumber(num: number | Element): StringJoiningTransformer;
119
+ /**
120
+ * @param {Function|Element} func - Function to stringify
121
+ * @returns {StringJoiningTransformer}
122
+ */
123
+ function(func: Function | Element): StringJoiningTransformer;
124
+ /**
125
+ * @param {string|object} elName - Element name or element object
126
+ * @param {object} [atts] - Element attributes
127
+ * @param {any[]} [childNodes] - Child nodes
128
+ * @param {Function} [cb] - Callback function
129
+ * @returns {StringJoiningTransformer}
130
+ */
131
+ element(elName: string | object, atts?: object, childNodes?: any[], cb?: Function): StringJoiningTransformer;
132
+ _openTagState: any;
133
+ /**
134
+ * @param {string} name - Attribute name
135
+ * @param {string|object} val - Attribute value
136
+ * @param {boolean} [avoidAttEscape] - Whether to avoid escaping the
137
+ * attribute value
138
+ * @returns {StringJoiningTransformer}
139
+ */
140
+ attribute(name: string, val: string | object, avoidAttEscape?: boolean): StringJoiningTransformer;
141
+ /**
142
+ * @param {string} txt - Text content to escape and append
143
+ * @returns {StringJoiningTransformer}
144
+ */
145
+ text(txt: string): StringJoiningTransformer;
146
+ /**
147
+ * Unlike text(), does not escape for HTML; unlike string(), does not perform
148
+ * JSON stringification; unlike append(), does not do other checks (but still
149
+ * varies in its role across transformers).
150
+ * @param {string} str
151
+ * @returns {StringJoiningTransformer}
152
+ */
153
+ rawAppend(str: string): StringJoiningTransformer;
154
+ /**
155
+ * @param {string} str - Plain text to append without escaping
156
+ * @returns {StringJoiningTransformer}
157
+ */
158
+ plainText(str: string): StringJoiningTransformer;
159
+ /**
160
+ * Helper method to use property sets.
161
+ * @param {object} obj - Object to apply property set to
162
+ * @param {string} psName - Property set name
163
+ * @returns {object}
164
+ */
165
+ _usePropertySets(obj: object, psName: string): object;
166
+ }
167
+ import AbstractJoiningTransformer from './AbstractJoiningTransformer.js';
168
+ //# sourceMappingURL=StringJoiningTransformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StringJoiningTransformer.d.ts","sourceRoot":"","sources":["../src/StringJoiningTransformer.js"],"names":[],"mappings":";AAuBA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH;IACE;;;OAGG;IACH,eAHW,MAAM,OACN,MAAM,EAsBhB;IAjBC,aAAmB;IACnB,kBAAkB;IAClB,cADW,GAAG,CACe;IAC7B,kCAAkC;IAClC,eADW,OAAO,GAAG,SAAS,CACA;IAC9B,kCAAkC;IAClC,eADW,OAAO,GAAG,SAAS,CACA;IAC9B,kCAAkC;IAClC,eADW,OAAO,GAAG,SAAS,CACA;IAC9B,kBAAkB;IAClB,MADW,GAAG,CACO;IACrB,oBAAoB;IACpB,MADW,GAAG,EAAE,CACF;IACd,iCAAiC;IACjC,UADW,MAAM,GAAG,SAAS,CACJ;IACzB,kCAAkC;IAClC,cADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACR;IAGxB;;;OAGG;IACH,UAHW,MAAM,GAAC,GAAC,GACN,wBAAwB,CAqBpC;IAED;;OAEG;IACH,OAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,gBAJW,MAAM,OACN,GAAC,GACC,wBAAwB,CAUpC;IAED;;;;OAIG;IACH,eAJW,MAAM,iBAEJ,wBAAwB,CAuBpC;IAED;;;;;;OAMG;IACH,YANW,MAAM,GAAC,OAAO,kCAEd,GAAG,EAAE,aACL,MAAM,GACJ,wBAAwB,CAkDpC;IAED;;;;OAIG;IACH,YAJW,GAAG,EAAE,GAAC,OAAO,kBAEX,wBAAwB,CA2CpC;IAED;;;;OAIG;IACH,YAJW,MAAM,GAAC,OAAO,GAAC,MAAM,kBAEnB,wBAAwB,CA4BpC;IAED;;;OAGG;IACH,YAHW,MAAM,GAAC,OAAO,GAAC,MAAM,GACnB,wBAAwB,CAWpC;IAED;;;OAGG;IACH,cAHW,OAAO,GAAC,OAAO,GAAC,MAAM,GACpB,wBAAwB,CAWpC;IAED;;OAEG;IACH,QAFa,wBAAwB,CAMpC;IAED;;OAEG;IACH,aAFa,wBAAwB,CAWpC;IAED;;;OAGG;IACH,qBAHW,MAAM,GAAC,OAAO,GACZ,wBAAwB,CAgBpC;IAED;;;OAGG;IACH,eAHW,WAAS,OAAO,GACd,wBAAwB,CAgBpC;IAED;;;;;;OAMG;IACH,gBANW,MAAM,GAAC,MAAM,SACb,MAAM,eACN,GAAG,EAAE,kBAEH,wBAAwB,CA2EpC;IAtBC,mBAAyB;IAwB3B;;;;;;OAMG;IACH,gBANW,MAAM,OACN,MAAM,GAAC,MAAM,mBACb,OAAO,GAEL,wBAAwB,CAqDpC;IAED;;;OAGG;IACH,UAHW,MAAM,GACJ,wBAAwB,CAWpC;IAED;;;;;;MAME;IACF,eAHU,MAAM,GACJ,wBAAwB,CAMnC;IAED;;;OAGG;IACH,eAHW,MAAM,GACJ,wBAAwB,CAQpC;IAED;;;;;OAKG;IACH,sBAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAWlB;CACF;uCAtkBsC,iCAAiC"}
@@ -0,0 +1,51 @@
1
+ export default XPathTransformer;
2
+ /**
3
+ * Applies named XPath-driven templates to XML/HTML DOM data.
4
+ *
5
+ * Finds templates whose `path` XPath matches the current node (plus optional
6
+ * `mode`), sorts by priority, and invokes the winning template.
7
+ * Falls back to default rules when no template matches.
8
+ */
9
+ declare class XPathTransformer {
10
+ static DefaultTemplateRules: {
11
+ transformRoot: {
12
+ /**
13
+ * @param {*} node Node
14
+ * @param {{mode:string}} cfg Config
15
+ * @returns {void}
16
+ */
17
+ template(node: any, cfg: {
18
+ mode: string;
19
+ }): void;
20
+ };
21
+ };
22
+ /**
23
+ * @param {object} config Configuration
24
+ * @param {boolean} [config.errorOnEqualPriority] Throw on equal priority
25
+ * @param {any[]} config.templates Template objects
26
+ * @param {number} [config.xpathVersion] XPath version (1|2)
27
+ */
28
+ constructor(config: {
29
+ errorOnEqualPriority?: boolean | undefined;
30
+ templates: any[];
31
+ xpathVersion?: number | undefined;
32
+ });
33
+ _config: {
34
+ errorOnEqualPriority?: boolean | undefined;
35
+ templates: any[];
36
+ xpathVersion?: number | undefined;
37
+ };
38
+ /** @type {any[]} */
39
+ rootTemplates: any[];
40
+ templates: any[];
41
+ /**
42
+ * @returns {void}
43
+ */
44
+ _triggerEqualPriorityError(): void;
45
+ /**
46
+ * @param {string} mode Transformation mode
47
+ * @returns {*} Result of transformation
48
+ */
49
+ transform(mode: string): any;
50
+ }
51
+ //# sourceMappingURL=XPathTransformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XPathTransformer.d.ts","sourceRoot":"","sources":["../src/XPathTransformer.js"],"names":[],"mappings":";AAEA;;;;;;GAMG;AACH;IAsEE;;YAEI;;;;eAIG;2BAHQ,GAAC,OACD;gBAAC,IAAI,EAAC,MAAM,CAAA;aAAC,GACX,IAAI;;MAMnB;IAhFF;;;;;OAKG;IACH,oBAJG;QAAyB,oBAAoB;QACvB,SAAS,EAAvB,GAAG,EAAE;QACW,YAAY;KACtC,EA4BA;IAzBC;;mBALS,GAAG,EAAE;;MAKO;IACrB,oBAAoB;IACpB,eADW,GAAG,EAAE,CACO;IACvB,iBAAiC;IAwBnC;;OAEG;IACH,8BAFa,IAAI,CAShB;IAED;;;OAGG;IACH,gBAHW,MAAM,GACJ,GAAC,CAkBb;CAcF"}
@@ -0,0 +1,260 @@
1
+ export default XPathTransformerContext;
2
+ /**
3
+ * Execution context for XPath-driven template application.
4
+ *
5
+ * Similar to JSONPathTransformerContext but uses XPath expressions on a
6
+ * DOM/XML-like tree. Supports XPath 1.0 (default) or 2.0 when
7
+ * `xpathVersion: 2`.
8
+ *
9
+ * Expected config:
10
+ * - data: A Document, Element, or XML-like root node.
11
+ * - joiningTransformer: joiner with append(), string(), object(), array(), etc.
12
+ * - xpathVersion: 1|2 (default 1)
13
+ * - errorOnEqualPriority, specificityPriorityResolver (same semantics).
14
+ */
15
+ declare class XPathTransformerContext {
16
+ /**
17
+ * Log a message (for debugging).
18
+ * @param {*} json Any value
19
+ * @returns {void}
20
+ */
21
+ static message(json: any): void;
22
+ static DefaultTemplateRules: {
23
+ transformRoot: {
24
+ /**
25
+ * @param {*} node Root node
26
+ * @param {{mode:string}} cfg Config
27
+ * @returns {void}
28
+ */
29
+ template(node: any, cfg: {
30
+ mode: string;
31
+ }): void;
32
+ };
33
+ transformElements: {
34
+ /**
35
+ * @param {*} node Element node
36
+ * @param {{mode:string}} cfg Config
37
+ * @returns {void}
38
+ */
39
+ template(node: any, cfg: {
40
+ mode: string;
41
+ }): void;
42
+ };
43
+ transformTextNodes: {
44
+ /**
45
+ * @param {{nodeValue:string}} node Text node
46
+ * @returns {string}
47
+ */
48
+ template(node: {
49
+ nodeValue: string;
50
+ }): string;
51
+ };
52
+ transformScalars: {
53
+ /** @returns {*} */
54
+ template(): any;
55
+ };
56
+ };
57
+ /**
58
+ * @param {object} config - Configuration object
59
+ * @param {Document|Element|any} config.data - XML/DOM root to transform
60
+ * @param {number} [config.xpathVersion] - 1 or 2 (default 1)
61
+ * @param {object} config.joiningTransformer Joiner
62
+ * @param {Function} config.joiningTransformer.append Append output
63
+ * @param {Function} config.joiningTransformer.get Get output
64
+ * @param {Function} config.joiningTransformer.string Emit string
65
+ * @param {Function} config.joiningTransformer.object Emit object
66
+ * @param {Function} config.joiningTransformer.array Emit array
67
+ * @param {boolean} [config.errorOnEqualPriority]
68
+ * @param {Function} [config.specificityPriorityResolver]
69
+ * @param {any[]} templates - Template objects
70
+ */
71
+ constructor(config: {
72
+ data: Document | Element | any;
73
+ xpathVersion?: number | undefined;
74
+ joiningTransformer: {
75
+ append: Function;
76
+ get: Function;
77
+ string: Function;
78
+ object: Function;
79
+ array: Function;
80
+ };
81
+ errorOnEqualPriority?: boolean | undefined;
82
+ specificityPriorityResolver?: Function | undefined;
83
+ }, templates: any[]);
84
+ _config: {
85
+ data: Document | Element | any;
86
+ xpathVersion?: number | undefined;
87
+ joiningTransformer: {
88
+ append: Function;
89
+ get: Function;
90
+ string: Function;
91
+ object: Function;
92
+ array: Function;
93
+ };
94
+ errorOnEqualPriority?: boolean | undefined;
95
+ specificityPriorityResolver?: Function | undefined;
96
+ };
97
+ _templates: any[];
98
+ _contextNode: any;
99
+ _origNode: any;
100
+ /** @type {Record<string, any>} */
101
+ vars: Record<string, any>;
102
+ /** @type {Record<string, any>} */
103
+ propertySets: Record<string, any>;
104
+ /** @type {Record<string, any>} */
105
+ keys: Record<string, any>;
106
+ /** @type {boolean|undefined} */
107
+ _initialized: boolean | undefined;
108
+ /** @type {string|undefined} */
109
+ _currPath: string | undefined;
110
+ /** @returns {any} */
111
+ _getJoiningTransformer(): any;
112
+ /**
113
+ * Evaluate an XPath expression against the current context node.
114
+ * @param {string} expr - XPath expression
115
+ * @param {boolean} [asNodes] Return nodes (array) instead of scalar
116
+ * @returns {any}
117
+ */
118
+ _evalXPath(expr: string, asNodes?: boolean): any;
119
+ /**
120
+ * Append raw item to output.
121
+ * @param {*} item
122
+ * @returns {XPathTransformerContext}
123
+ */
124
+ appendOutput(item: any): XPathTransformerContext;
125
+ /** @returns {*} */
126
+ getOutput(): any;
127
+ /**
128
+ * Get value(s) by XPath relative to current context.
129
+ * @param {string} select - XPath expression
130
+ * @param {boolean} [asNodes]
131
+ * @returns {*}
132
+ */
133
+ get(select: string, asNodes?: boolean): any;
134
+ /**
135
+ * Set current context's parent property (for parity with JSONPath context).
136
+ * Mostly placeholder for object-mirroring behavior.
137
+ * @param {*} v
138
+ * @returns {XPathTransformerContext}
139
+ */
140
+ set(v: any): XPathTransformerContext;
141
+ /**
142
+ * Apply templates to nodes matched by an XPath expression.
143
+ * @param {string} select - XPath expression (default '.')
144
+ * @param {string} [mode]
145
+ * @returns {XPathTransformerContext}
146
+ */
147
+ applyTemplates(select: string, mode?: string): XPathTransformerContext;
148
+ /**
149
+ * Iterate over nodes selected by XPath.
150
+ * @param {string} select - XPath expression
151
+ * @param {Function} cb - Callback invoked per node
152
+ * @returns {XPathTransformerContext}
153
+ */
154
+ forEach(select: string, cb: Function): XPathTransformerContext;
155
+ /**
156
+ * Append the value from an XPath expression or the context node text.
157
+ * @param {string|object} [select]
158
+ * @returns {XPathTransformerContext}
159
+ */
160
+ valueOf(select?: string | object): XPathTransformerContext;
161
+ /**
162
+ * Define a variable by XPath selection (stores node array if nodes).
163
+ * @param {string} name Variable name
164
+ * @param {string} select XPath expression
165
+ * @returns {XPathTransformerContext}
166
+ */
167
+ variable(name: string, select: string): XPathTransformerContext;
168
+ /**
169
+ * Append string.
170
+ * @param {string} str String to append
171
+ * @param {Function} [cb] Callback
172
+ * @returns {XPathTransformerContext}
173
+ */
174
+ string(str: string, cb?: Function): XPathTransformerContext;
175
+ /**
176
+ * Append number.
177
+ * @param {number} num Number
178
+ * @returns {XPathTransformerContext}
179
+ */
180
+ number(num: number): XPathTransformerContext;
181
+ /**
182
+ * Append plain text (no escaping changes).
183
+ * @param {string} str Text
184
+ * @returns {XPathTransformerContext}
185
+ */
186
+ plainText(str: string): XPathTransformerContext;
187
+ /**
188
+ * Append property/value pair.
189
+ * @param {string} prop Property name
190
+ * @param {*} val Value
191
+ * @returns {XPathTransformerContext}
192
+ */
193
+ propValue(prop: string, val: any): XPathTransformerContext;
194
+ /**
195
+ * Append object.
196
+ * @param {...any} args Object args
197
+ * @returns {XPathTransformerContext}
198
+ */
199
+ object(...args: any[]): XPathTransformerContext;
200
+ /**
201
+ * Append array.
202
+ * @param {...any} args Array args
203
+ * @returns {XPathTransformerContext}
204
+ */
205
+ array(...args: any[]): XPathTransformerContext;
206
+ /**
207
+ * Append element.
208
+ * @param {string} name Tag name
209
+ * @param {object} [atts] Attributes
210
+ * @param {any[]} [children] Children
211
+ * @param {Function} [cb] Callback
212
+ * @returns {XPathTransformerContext}
213
+ */
214
+ element(name: string, atts?: object, children?: any[], cb?: Function): XPathTransformerContext;
215
+ /**
216
+ * Append attribute.
217
+ * @param {string} name Attribute name
218
+ * @param {string|object} val Value
219
+ * @param {boolean} [avoid] Avoid duplicates
220
+ * @returns {XPathTransformerContext}
221
+ */
222
+ attribute(name: string, val: string | object, avoid?: boolean): XPathTransformerContext;
223
+ /**
224
+ * Append text node content.
225
+ * @param {string} txt Text
226
+ * @returns {XPathTransformerContext}
227
+ */
228
+ text(txt: string): XPathTransformerContext;
229
+ /**
230
+ * Define a property set (optionally composed from other sets).
231
+ * @param {string} name Property set name
232
+ * @param {object} obj Base properties
233
+ * @param {string[]} [use] Property set names to merge
234
+ * @returns {XPathTransformerContext}
235
+ */
236
+ propertySet(name: string, obj: object, use?: string[]): XPathTransformerContext;
237
+ /**
238
+ * Merge properties from a named property set into obj.
239
+ * @param {object} obj Target object
240
+ * @param {string} name Property set name
241
+ * @returns {object}
242
+ */
243
+ _usePropertySets(obj: object, name: string): object;
244
+ /**
245
+ * Retrieve a key-mapped node matching a value or return context.
246
+ * @param {string} name Key name
247
+ * @param {*} value Value to match
248
+ * @returns {*}
249
+ */
250
+ getKey(name: string, value: any): any;
251
+ /**
252
+ * Register a key for later lookup.
253
+ * @param {string} name Key name
254
+ * @param {string} match XPath selecting nodes
255
+ * @param {string} use Attribute (or property) name to compare
256
+ * @returns {XPathTransformerContext}
257
+ */
258
+ key(name: string, match: string, use: string): XPathTransformerContext;
259
+ }
260
+ //# sourceMappingURL=XPathTransformerContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XPathTransformerContext.d.ts","sourceRoot":"","sources":["../src/XPathTransformerContext.js"],"names":[],"mappings":"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"}
@@ -0,0 +1,16 @@
1
+ export default XSLTStyleJSONPathResolver;
2
+ /**
3
+ * Computes a simple specificity score for JSONPath selectors inspired by XSLT.
4
+ *
5
+ * Used by the engine to break ties between templates when multiple JSONPath
6
+ * expressions match the same node. Lower values indicate broader matches
7
+ * (e.g., wildcards), while higher values indicate more specific matches.
8
+ */
9
+ declare class XSLTStyleJSONPathResolver {
10
+ /**
11
+ * @param {string|string[]} path
12
+ * @returns {-0.5|0.5|0}
13
+ */
14
+ getPriorityBySpecificity(path: string | string[]): -0.5 | 0.5 | 0;
15
+ }
16
+ //# sourceMappingURL=XSLTStyleJSONPathResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XSLTStyleJSONPathResolver.d.ts","sourceRoot":"","sources":["../src/XSLTStyleJSONPathResolver.js"],"names":[],"mappings":";AAEA;;;;;;GAMG;AACH;IACE;;;OAGG;IAEH,+BAJW,MAAM,GAAC,MAAM,EAAE,GACb,CAAC,GAAG,GAAC,GAAG,GAAC,CAAC,CAuBtB;CACF"}
@@ -0,0 +1,168 @@
1
+ export { default as AbstractJoiningTransformer } from "./AbstractJoiningTransformer.js";
2
+ export { default as StringJoiningTransformer } from "./StringJoiningTransformer.js";
3
+ export { default as DOMJoiningTransformer } from "./DOMJoiningTransformer.js";
4
+ export { default as JSONJoiningTransformer } from "./JSONJoiningTransformer.js";
5
+ export { default as XSLTStyleJSONPathResolver } from "./XSLTStyleJSONPathResolver.js";
6
+ export { default as JSONPathTransformerContext } from "./JSONPathTransformerContext.js";
7
+ export { default as JSONPathTransformer } from "./JSONPathTransformer.js";
8
+ export { default as XPathTransformerContext } from "./XPathTransformerContext.js";
9
+ export { default as XPathTransformer } from "./XPathTransformer.js";
10
+ export default JTLT;
11
+ export type JTLTOptions = {
12
+ /**
13
+ * A callback supplied with a single
14
+ * argument that is the result of this instance's transform() method.
15
+ */
16
+ success: Function;
17
+ /**
18
+ * An array of template objects
19
+ */
20
+ templates?: any[] | undefined;
21
+ /**
22
+ * A function assumed to be a
23
+ * root template or a single, complete template object
24
+ */
25
+ template?: object | Function | undefined;
26
+ /**
27
+ * A function assumed to be a root template
28
+ */
29
+ query?: Function | undefined;
30
+ /**
31
+ * An array with arguments to be supplied
32
+ * to a single call to `forEach` (and which will serve as the root
33
+ * template)
34
+ */
35
+ forQuery?: any[] | undefined;
36
+ /**
37
+ * A JSON object
38
+ */
39
+ data?: any;
40
+ /**
41
+ * URL of a JSON file to retrieve for
42
+ * evaluation
43
+ */
44
+ ajaxData?: string | undefined;
45
+ /**
46
+ * Whether or not to
47
+ * report an error when equal priority templates are found
48
+ */
49
+ errorOnEqualPriority?: boolean | undefined;
50
+ /**
51
+ * Whether to begin transform()
52
+ * immediately.
53
+ */
54
+ autostart?: boolean | undefined;
55
+ /**
56
+ * Whether to prevent
57
+ * parenthetical evaluations in JSONPath. Safer if relying on user
58
+ * input, but reduces capabilities of JSONPath.
59
+ */
60
+ preventEval?: boolean | undefined;
61
+ /**
62
+ * For JSON output, whether to
63
+ * unwrap single-element root arrays to return just the element
64
+ */
65
+ unwrapSingleResult?: boolean | undefined;
66
+ /**
67
+ * The mode in which to begin the transform.
68
+ */
69
+ mode?: string | undefined;
70
+ /**
71
+ * Output type: 'string', 'dom', or 'json'
72
+ */
73
+ outputType?: string | undefined;
74
+ /**
75
+ * Will be based the
76
+ * same config as passed to this instance. Defaults to a transforming
77
+ * function based on JSONPath and with its own set of priorities for
78
+ * processing templates.
79
+ */
80
+ engine?: Function | undefined;
81
+ /**
82
+ * Choose built-in engine.
83
+ * Defaults to 'jsonpath'. When 'xpath', `xpathVersion` may be used.
84
+ */
85
+ engineType?: "jsonpath" | "xpath" | undefined;
86
+ /**
87
+ * XPath engine version: 1 (native) or 2
88
+ * (xpath2.js) when `engineType` is 'xpath'.
89
+ */
90
+ xpathVersion?: 1 | 2 | undefined;
91
+ /**
92
+ * Callback for getting the priority by specificity
93
+ */
94
+ specificityPriorityResolver?: Function | undefined;
95
+ /**
96
+ * Can
97
+ * be a singleton or class instance. Defaults to string joining for output
98
+ * transformation.
99
+ */
100
+ joiningTransformer?: {
101
+ get: Function;
102
+ append: Function;
103
+ string?: Function;
104
+ object?: Function;
105
+ array?: Function;
106
+ } | undefined;
107
+ /**
108
+ * Config to pass on to the joining
109
+ * transformer
110
+ */
111
+ joiningConfig?: object | undefined;
112
+ /**
113
+ * Parent object for context
114
+ */
115
+ parent?: any;
116
+ /**
117
+ * Parent property name for context
118
+ */
119
+ parentProperty?: string | undefined;
120
+ };
121
+ /**
122
+ * High-level façade for running a JTLT transform.
123
+ *
124
+ * Accepts data and templates (or a root template/query), constructs a joining
125
+ * transformer based on `outputType`, and invokes the JSONPath-based engine.
126
+ * The result is returned to the required `success` callback and also returned
127
+ * from transform().
128
+ */
129
+ declare class JTLT {
130
+ /**
131
+ * For templates/queries, one may choose among config.query,
132
+ * config.template, or config.templates, but one must be
133
+ * present and of valid type. For the source json, one must use
134
+ * either a valid config.ajaxData or config.data parameter.
135
+ * @param {JTLTOptions} config Options
136
+ * @todo Remove JSONPath dependency in query use of '$'?
137
+ */
138
+ constructor(config: JTLTOptions);
139
+ /** @type {JTLTOptions} */
140
+ config: JTLTOptions;
141
+ /**
142
+ * @returns {DOMJoiningTransformer|JSONJoiningTransformer|
143
+ * StringJoiningTransformer}
144
+ */
145
+ _createJoiningTransformer(): DOMJoiningTransformer | JSONJoiningTransformer | StringJoiningTransformer;
146
+ /**
147
+ * @param {string} mode
148
+ * @returns {void}
149
+ */
150
+ _autoStart(mode: string): void;
151
+ /**
152
+ * @param {JTLTOptions} config
153
+ * @returns {JTLT}
154
+ */
155
+ setDefaults(config: JTLTOptions): JTLT;
156
+ /**
157
+ * @param {string} mode The mode of the transformation
158
+ * @returns {any} Result of transformation
159
+ * @todo Allow for a success callback in case the jsonpath code is modified
160
+ * to work asynchronously (as with queries to access remote JSON
161
+ * stores)
162
+ */
163
+ transform(mode: string): any;
164
+ }
165
+ import DOMJoiningTransformer from './DOMJoiningTransformer.js';
166
+ import JSONJoiningTransformer from './JSONJoiningTransformer.js';
167
+ import StringJoiningTransformer from './StringJoiningTransformer.js';
168
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA0Bc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA8BH,GAAG;;;;;;AAOjB;;;;;;;GAOG;AACH;IACE;;;;;;;OAOG;IACH,oBAHW,WAAW,EA4BrB;IAxBC,0BAA0B;IAC1B,QADW,WAAW,CACI;IAyB5B;;;OAGG;IACH,6BAHa,qBAAqB,GAAC,sBAAsB,GACpD,wBAAwB,CAuD5B;IAED;;;OAGG;IACH,iBAHW,MAAM,GACJ,IAAI,CAYhB;IAED;;;OAGG;IACH,oBAHW,WAAW,GACT,IAAI,CAoDhB;IAED;;;;;;OAMG;IACH,gBANW,MAAM,GACJ,GAAG,CA2Bf;CACF;kCApQiC,4BAA4B;mCAC3B,6BAA6B;qCAG3B,+BAA+B"}