@lytical/jxf 1.0.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 (51) hide show
  1. package/README.md +274 -0
  2. package/index.d.ts +31 -0
  3. package/index.d.ts.map +1 -0
  4. package/index.js +6 -0
  5. package/index.js.map +1 -0
  6. package/jxf.test.d.ts +2 -0
  7. package/jxf.test.d.ts.map +1 -0
  8. package/jxf.test.js +6 -0
  9. package/jxf.test.js.map +1 -0
  10. package/package.json +52 -0
  11. package/transformers/case.d.ts +22 -0
  12. package/transformers/case.d.ts.map +1 -0
  13. package/transformers/case.js +6 -0
  14. package/transformers/case.js.map +1 -0
  15. package/transformers/for-each.d.ts +23 -0
  16. package/transformers/for-each.d.ts.map +1 -0
  17. package/transformers/for-each.js +6 -0
  18. package/transformers/for-each.js.map +1 -0
  19. package/transformers/for-keys.d.ts +23 -0
  20. package/transformers/for-keys.d.ts.map +1 -0
  21. package/transformers/for-keys.js +6 -0
  22. package/transformers/for-keys.js.map +1 -0
  23. package/transformers/if.d.ts +20 -0
  24. package/transformers/if.d.ts.map +1 -0
  25. package/transformers/if.js +6 -0
  26. package/transformers/if.js.map +1 -0
  27. package/transformers/index.d.ts +10 -0
  28. package/transformers/index.d.ts.map +1 -0
  29. package/transformers/index.js +6 -0
  30. package/transformers/index.js.map +1 -0
  31. package/transformers/length.d.ts +12 -0
  32. package/transformers/length.d.ts.map +1 -0
  33. package/transformers/length.js +6 -0
  34. package/transformers/length.js.map +1 -0
  35. package/transformers/switch.d.ts +23 -0
  36. package/transformers/switch.d.ts.map +1 -0
  37. package/transformers/switch.js +6 -0
  38. package/transformers/switch.js.map +1 -0
  39. package/transformers/value-of.d.ts +20 -0
  40. package/transformers/value-of.d.ts.map +1 -0
  41. package/transformers/value-of.js +6 -0
  42. package/transformers/value-of.js.map +1 -0
  43. package/transformers/variable.d.ts +21 -0
  44. package/transformers/variable.d.ts.map +1 -0
  45. package/transformers/variable.js +6 -0
  46. package/transformers/variable.js.map +1 -0
  47. package/transformers/with.d.ts +22 -0
  48. package/transformers/with.d.ts.map +1 -0
  49. package/transformers/with.js +6 -0
  50. package/transformers/with.js.map +1 -0
  51. package/types.d.ts +48 -0
package/README.md ADDED
@@ -0,0 +1,274 @@
1
+ # @lytical/jxf
2
+
3
+ JXF (short for JavaScript Tranformation) library provides a similar solution that XSLT provides, for plain old data (POD) JavaScript objects.\
4
+ Using JSPath for XPATH like DSL, declare transformation templates with declarative conditional statements, to transform your objects into a text formatted document.
5
+
6
+ This lightweight implementation is extendable to support simple to complex transformation.
7
+
8
+ Among other use cases...
9
+
10
+ - Use it to automate document-driven business processes.
11
+ - Dynamically render content for emails; web pages; code generation.
12
+ - Utilize it for EDI processing.
13
+
14
+ Built for TypeScript, you can utilize the library with plain old JavaScript.
15
+
16
+ Supports ES6 environments in both DOM and NodeJS.
17
+
18
+ ## Getting Started
19
+
20
+ After installing JXF, import and invoke the `jxf()` function. DSL usage documentation can be found in [JSPath]('https://www.npmjs.com/package/jspath').
21
+
22
+ ## Usage
23
+
24
+ ```javascript
25
+ jxf(data, transforms, [variables])
26
+ ```
27
+ ### Where
28
+
29
+ | argument | description |
30
+ | --- | --- |
31
+ | data | an object or array |
32
+ | transforms | an array of one or more transformers and strings |
33
+ | variables | an optional object with keys are variable names and respective values. |
34
+ | **returns** | **an array for strings you can concatenate to compose any text document.** |
35
+
36
+ ## Example
37
+
38
+ Let's say you want to create the following markdown...
39
+
40
+ ### Markdown
41
+ Thank you for your interest in our products. As discussed, the following are the top (2) products you are interested in.
42
+
43
+ | Product | Description | Cost |
44
+ | --- | --- | ---: |
45
+ | CRM | Our state-of-the-art Customer Relationship Management | $39 / mo |
46
+ | CMS | Build web applications and sites with No Coding required | $2500 / yr |
47
+
48
+ Let me know when you want to move forward...
49
+
50
+ Regards,
51
+
52
+ Sally Salesperson\
53
+ sally.salesperson@lytical.com
54
+
55
+ ### Source Code
56
+
57
+ Import jxf:
58
+
59
+ ```typescript
60
+ import jxf from '@lytical/jxf';
61
+ ```
62
+
63
+ Using the following data:
64
+
65
+ ```typescript
66
+ const data = {
67
+ customer: {
68
+ first_name: 'Barry',
69
+ last_name: 'Hayles',
70
+ email: 'barry.hayles@lytical.com',
71
+ },
72
+ product: [
73
+ {
74
+ name: 'CRM',
75
+ description: 'Our state-of-the-art Customer Relationship Management',
76
+ price: 39.0,
77
+ term: 'monthly',
78
+ },
79
+ {
80
+ name: 'CMS',
81
+ description:
82
+ 'Build web applications and sites with No Coding required',
83
+ price: 2500.0,
84
+ term: 'yearly',
85
+ },
86
+ ],
87
+ sales_rep: {
88
+ name: 'Sally Salesperson',
89
+ email: 'sally.salesperson@lytical.com',
90
+ },
91
+ };
92
+ ```
93
+
94
+ ...and with the following transformation:
95
+
96
+ ```typescript
97
+ const transform = [
98
+ `Hi `,
99
+ jxf_value_of('.customer.first_name'),
100
+ `,
101
+
102
+ Thank you for your interest in our products. As discussed, the following are the top (`,
103
+ jxf_length('.product'),
104
+ `) products you are interested in.
105
+
106
+ | Name | Description | Cost |
107
+ | --- | --- | ---: |
108
+ `,
109
+ jxf_for_each('.product', [
110
+ `| `,
111
+ jxf_value_of('.name'),
112
+ ` | `,
113
+ jxf_value_of('.description'),
114
+ ` | $`,
115
+ jxf_value_of('.price'),
116
+ ` / `,
117
+ jxf_switch('.term', [
118
+ jxf_case('.{. === "monthly"}', ['mo']),
119
+ jxf_case('.{. === "yearly"}', ['yr']),
120
+ ]),
121
+ ` |
122
+ `,
123
+ ]),
124
+ `
125
+
126
+ Let me know when you want to move forward...
127
+
128
+ Regards,
129
+
130
+ `,
131
+ jxf_value_of('.sales_rep.name'),
132
+ `\\
133
+ `,
134
+ jxf_value_of('.sales_rep.email'),
135
+ ];
136
+ ```
137
+
138
+ ...perform the transformation:
139
+
140
+ ```typescript
141
+ const rs = jxf(data, transform);
142
+ const message = rs.join('');
143
+ console.log(message);
144
+ ```
145
+
146
+ ## Documentation
147
+
148
+ A transformers takes as an argument (at the minimum), a selector string (to match the target data). (e.g. `'.property{. > 1.25}'`)
149
+
150
+ Creating a custom transformer involves returning function with the following signature: `(data, ctx) => string[]`
151
+
152
+ ```typescript
153
+ import apply from 'jspath';
154
+
155
+ import type { jxf_transformer_t } from '@lytical/jxf/types';
156
+
157
+ export function my_custom_xformer(match: string): jxf_transformer_t {
158
+ return (data, ctx): string[] => {
159
+ const [val] = apply(match, data, ctx);
160
+ return [val?.toString() ?? ''];
161
+ };
162
+ }
163
+ ```
164
+
165
+ `data` is the javascript type to select (match) and transform to an array of `string`.
166
+ `ctx` stores variables. Variable should be considered immutable within the context.
167
+
168
+ This library has standard transformers;
169
+
170
+ ```typescript
171
+ import { ... } from '@lytical/jxf/transformer';
172
+ ```
173
+
174
+ ### Transformers
175
+
176
+ #### *jxf_value_of(match, [formatter])
177
+ ---
178
+ Transforms a single scalar value to a string.
179
+
180
+ | Argument | Description |
181
+ | --- | --- |
182
+ | match | The selector to match the scalar value. |
183
+ | formatter | An optional callback function to specialize the formatting of the scalar value; `(val: any) => string`
184
+
185
+ #### * jxf_variable(name, match)
186
+ ---
187
+ Set a variable name with selected (matched) data. This is useful in capturing values in outer `for` loops, to be used in inner `for` loops.
188
+
189
+ | Argument | Description |
190
+ | --- | --- |
191
+ | name | The variable name.
192
+ | match | The selector to match the variable value. |
193
+
194
+ Note: variable names starting with `$` are reserved.
195
+
196
+ Access the variables in your select (match) statement by prefixing the name with `$`. (e.g. `'.user{.age < $max_age}'`)
197
+
198
+ #### * jxf_with(match, transformers)
199
+ ---
200
+ Select (match) data used in nested transformations.
201
+
202
+ | Argument | Description |
203
+ | --- | --- |
204
+ | match | The selector to match the scalar value. |
205
+ | transformers | An array of transformers to process the selected data.
206
+
207
+ #### * jxf_length(match)
208
+ ---
209
+ Transforms a selected array's length. The following will not select the `product` array length `.product.length`.\
210
+ This statement will try to select the `length` property of the element(s) of the `product` array.
211
+
212
+ | Argument | Description |
213
+ | --- | --- |
214
+ | match | The selector to match the array. |
215
+
216
+ #### * jxf_if(match, transformers)
217
+ ---
218
+ Execute the nested transformations if the selected (matched) value is truthy.
219
+
220
+ | Argument | Description |
221
+ | --- | --- |
222
+ | match | The selector to match the value, and test for truthyness. |
223
+ | transformers | An array of transformers to process the data in context if the match is truthy.
224
+
225
+ #### * jxf_switch(match, transformers)
226
+ ---
227
+ Transforms a single scalar value to a string.
228
+
229
+ | Argument | Description |
230
+ | --- | --- |
231
+ | match | The selector to match the value to switch. |
232
+ | transformers | An array of `jxf_case()` transformers to test the matched value. (Note: any type of transformer can be added here, but this should be last in the array to handle a default case.)
233
+
234
+ #### * jxf_case(match, transformers)
235
+ ---
236
+ Used as nested transformers to `jxf_switch()`, that are executed if the `match` case is truthy.
237
+
238
+ | Argument | Description |
239
+ | --- | --- |
240
+ | match | The selector to test the switched value. |
241
+ | transformers | An array of transformers to process the data in context if the match is truthy.
242
+
243
+ #### * jxf_for_each(match, transformers, [sort])
244
+ ---
245
+ Execute the nested transformers for each item in a selected array.
246
+
247
+ | Argument | Description |
248
+ | --- | --- |
249
+ | match | The selector to match the array value. |
250
+ | transformers | An array of transformers to process each item in the matched array.
251
+
252
+ For each array item, the following variables are available.
253
+
254
+ | Name | Description |
255
+ | --- | --- |
256
+ | $even | true if the array item is in an even position |
257
+ | $first | true if the array item is first |
258
+ | $last | true if the array item is last |
259
+ | $length | the length of the array |
260
+ | $odd | true if the array item is in an odd position |
261
+ | $parent | the outer data |
262
+
263
+ #### * jxf_for_keys(match, transformers, [sort])
264
+ ---
265
+ Execute the nested transformers for each key in a selected object.
266
+
267
+ | Argument | Description |
268
+ | --- | --- |
269
+ | match | The selector to match the first object value. |
270
+ | transformers | An array of transformers to process each key in the matched object.
271
+
272
+ Stay tuned! I have more packages to come.`
273
+
274
+ *lytical(r) is a registered trademark of lytical, inc. all rights are reserved.*
package/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { jxf_ctx_t, jxf_transformer_t } from './types';
2
+ /**
3
+ * jxf(data, transform, ctx?)
4
+ *
5
+ * @description
6
+ * Transforms a pod or array using an array of transformers, and or text to add to the transformation.
7
+ *
8
+ * @example
9
+ *
10
+ * import { jxf_value_of } from '@lytical/jxf/transformers/index.js';
11
+ *
12
+ * const data = { name: 'john', age: 42 };
13
+ * const transform = [
14
+ * 'User Information:',
15
+ * jxf_value_of('.name'),
16
+ * ' is ',
17
+ * jxf_value_of('.age'),
18
+ * ' years old.'
19
+ * ];
20
+ * const result = jxf(data, transform);
21
+ * console.log(result.join('')); // "User Information: john is 42 years old."
22
+ *
23
+ * @module \@lytical/jxf/index
24
+ *
25
+ * @param {object} data a pod or array to transform
26
+ * @param {(jxf_transformer_t | string)[]} transform an array of transformers, and or text to add to the transformation
27
+ * @param {jxf_ctx_t} ctx (optional) context object to pass to the transformers that may contain preset variables
28
+ * @returns {string[]} an array of strings that represent the transformed data
29
+ */
30
+ export default function jxf(data: object, transform: (jxf_transformer_t | string)[], ctx?: jxf_ctx_t): string[];
31
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,EACzC,GAAG,GAAE,SAAc,GAClB,MAAM,EAAE,CAaV"}
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ export default function jxf(o,t,f={}){const n=[];void 0===f.$&&(f.$=o);for(const r of t)"string"==typeof r?n.push(r):n.push(...r(o,f));return n}
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,IAAY,EACZ,SAAyC,EACzC,MAAiB,EAAE;IAEnB,MAAM,EAAE,GAAa,EAAE,CAAC;IACxB,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;QAC3B,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAClB,CAAC;IACD,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC3B,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACd,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
package/jxf.test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=jxf.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jxf.test.d.ts","sourceRoot":"","sources":["../src/jxf.test.ts"],"names":[],"mappings":""}
package/jxf.test.js ADDED
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ var __awaiter=this&&this.__awaiter||function(e,a,t,n){return new(t||(t=Promise))(function(r,s){function fulfilled(e){try{step(n.next(e))}catch(e){s(e)}}function rejected(e){try{step(n.throw(e))}catch(e){s(e)}}function step(e){var a;e.done?r(e.value):(a=e.value,a instanceof t?a:new t(function(e){e(a)})).then(fulfilled,rejected)}step((n=n.apply(e,a||[])).next())})};import{expect}from"chai";import{describe}from"mocha";import jxf from"./index.js";import{jxf_case,jxf_for_each,jxf_if,jxf_length,jxf_switch,jxf_value_of,jxf_variable,jxf_with}from"./transformers/index.js";describe("a jsxform instance",()=>{it("can transform plain text",()=>__awaiter(void 0,void 0,void 0,function*(){const e=jxf({},["Hello, World!"]);expect(e).exist.and.is.an("array").that.includes("Hello, World!")})),it("can transform an object property using jxf_value(), into a formatted string",()=>__awaiter(void 0,void 0,void 0,function*(){const e=jxf({name:"Barry"},["Hello, ",jxf_value_of(".name"),"!"]);expect(e).exist.and.is.an("array"),expect(e.join("")).equals("Hello, Barry!")})),it("can transform an object property using jxf_value() and jxf_variable(), into a formatted string",()=>__awaiter(void 0,void 0,void 0,function*(){const e=jxf({first_name:"Barry",last_name:"Hayles"},[jxf_variable("lname",".last_name"),"Hello, ",jxf_value_of(".first_name")," ",jxf_value_of("$lname"),"!"]);expect(e).exist.and.is.an("array"),expect(e.join("")).equals("Hello, Barry Hayles!")})),it("can transform objects using jxf_for_each()",()=>{const e=jxf({name:["Barry","Hayles"]},["Names:",jxf_for_each(".name",[jxf_value_of(".")])]);expect(e).exist.and.is.an("array"),expect(e.join(" ")).equals("Names: Barry Hayles")}),it("can transform objects using jxf_with()",()=>{const e=jxf({first_name:"Barry",last_name:"Hayles"},["Full Name:",jxf_with(".",[jxf_value_of(".first_name"),jxf_value_of(".last_name")])]);expect(e).exist.and.is.an("array"),expect(e.join(" ")).equals("Full Name: Barry Hayles")}),it("can transform objects using jxf_switch() and jfx_case()",()=>{const e=jxf([{first_name:"Barry",last_name:"Hayles",age:42},{first_name:"Roger",last_name:"Rabbit",age:25}],["Ages:",jxf_for_each(".",[jxf_value_of(".first_name"),jxf_value_of(".last_name"),jxf_switch(".age",[jxf_case(".{. <= 30}",["Is Young"]),jxf_case(".{. > 30}",["Is Old"])]),jxf_if(".{$$last === false}",["and"])])]);expect(e).exist.and.is.an("array"),expect(e.join(" ")).equals("Ages: Barry Hayles Is Old and Roger Rabbit Is Young")}),it("can transform an object to email message.",()=>{const e=["Hi ",jxf_value_of(".customer.first_name"),", \n\nThank you for your interest in our products. As discussed, the following are the top (",jxf_length(".product"),") products you are interested in.\n\n| Name | Description | Cost |\n| --- | --- | ---: |\n",jxf_for_each(".product",["| ",jxf_value_of(".name")," | ",jxf_value_of(".description")," | $",jxf_value_of(".price")," / ",jxf_switch(".term",[jxf_case('.{. === "monthly"}',["mo"]),jxf_case('.{. === "yearly"}',["yr"])])," |\n"]),"\n\nLet me know when you want to move forward... \n\nRegards, \n\n",jxf_value_of(".sales_rep.name"),"\\\n",jxf_value_of(".sales_rep.email")],a=jxf({customer:{first_name:"Barry",last_name:"Hayles",email:"barry.hayles@lytical.com"},product:[{name:"CRM",description:"Our state-of-the-art Customer Relationship Management",price:39,term:"monthly"},{name:"CMS",description:"Build web applications and sites with No Coding required",price:2500,term:"yearly"}],sales_rep:{name:"Sally Salesperson",email:"sally.salesperson@lytical.com"}},e);expect(a).exist.and.is.an("array");const t=a.join("");console.log(t)}),it("can transform objects using jxf_for_each and jxf_if()",()=>{const e=jxf([{first_name:"Barry",last_name:"Hayles",age:42},{first_name:"Roger",last_name:"Rabbit",age:25}],["Full Name:",jxf_for_each(".",[jxf_if(".{.age < 30}",[jxf_value_of(".first_name"),jxf_value_of(".last_name")])])]);expect(e).exist.and.is.an("array"),expect(e.join(" ")).equals("Full Name: Roger Rabbit")})});
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jxf.test.js","sourceRoot":"","sources":["../src/jxf.test.ts"],"names":[],"mappings":"AAAA;;;;EAIE;;;;;;;;;;AAEF,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,UAAU,EACV,UAAU,EACV,YAAY,E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AAY,CAAC,YAAY,CAAC;iBAC3B,CAAC;aACH,CAAC;SACH,CACF,CAAC;QACF,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@lytical/jxf",
3
+ "version": "1.0.0",
4
+ "description": "A TypeScript library for transforming template declarations into formatted strings based on provided data.",
5
+ "main": "index.js",
6
+ "private": false,
7
+ "scripts": {
8
+ "build": "tsc --build&&gulp post_build",
9
+ "clean": "rimraf ./dist",
10
+ "rebuild": "npm run clean&&npm run build",
11
+ "test": "mocha --recursive ./dist/**/*.test.js"
12
+ },
13
+ "keywords": [
14
+ "dom",
15
+ "dsl",
16
+ "lytical",
17
+ "node",
18
+ "template",
19
+ "template-engine",
20
+ "transformation",
21
+ "typescript",
22
+ "xpath",
23
+ "xslt"
24
+ ],
25
+ "author": {
26
+ "email": "barry.hayles@lytical.com",
27
+ "name": "Barry Hayles",
28
+ "url": "https://www.lytical.com"
29
+ },
30
+ "repository": {
31
+ "type": "github",
32
+ "url": "git+https://github.com/lytical/jxf.git"
33
+ },
34
+ "license": "ISC",
35
+ "type": "module",
36
+ "dependencies": {
37
+ "chai": "^6.2.2",
38
+ "jspath": "^0.4.0",
39
+ "mocha": "^11.7.5",
40
+ "typescript": "^5.9.3"
41
+ },
42
+ "devDependencies": {
43
+ "@types/chai": "^5.2.3",
44
+ "@types/jspath": "^0.4.2",
45
+ "@types/mocha": "^10.0.10",
46
+ "@types/node": "^25.0.9",
47
+ "gulp": "^5.0.1",
48
+ "gulp-uglify-es": "^3.0.0",
49
+ "pump": "^3.0.3",
50
+ "rimraf": "^6.1.2"
51
+ }
52
+ }
@@ -0,0 +1,22 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_case(match, transform)
4
+ * @description
5
+ * A transformer that applies the given transform if the match expression evaluates to true.
6
+ * @param {string} match a jspath expression that evaluates to a truthy or falsy value
7
+ * @param {(jxf_transformer_t | string)[]} transform transformers and/or strings to apply if the match is true
8
+ * @returns {jxf_transformer_t} A jxf transformer function.
9
+ * @module \@lytical/jxf/transformers/case
10
+ * @example
11
+ * import { jxf_case } from '@lytical/jxf/transformers/case.js';
12
+ * import jxf from '@lytical/jxf/index.js';
13
+ *
14
+ * const data = { age: 25 };
15
+ * const transform = [
16
+ * jxf_case('{.age < 30}', ['Is Young']),
17
+ * jxf_case('{.age >= 30}', ['Is Old']),
18
+ * ];
19
+ *
20
+ */
21
+ export declare function jxf_case(match: string, transform: (jxf_transformer_t | string)[]): jxf_transformer_t;
22
+ //# sourceMappingURL=case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../../src/transformers/case.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,GACxC,iBAAiB,CAKnB"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";import jxf from"../index.js";export function jxf_case(t,r){return(s,e)=>{const[n]=apply(t,e.$switch,e);return n?jxf(s,r,Object.assign(Object.assign({},e),{$eval:n})):[]}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"case.js","sourceRoot":"","sources":["../../src/transformers/case.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAG3B,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAa,EACb,SAAyC;IAEzC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;QAChD,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,kCAAO,GAAG,KAAE,KAAK,EAAE,GAAG,IAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_for_each(match, transform, sort?)
4
+ * @description
5
+ * A transformer that iterates over each item in the array resolved by the match expression,
6
+ * applying the given transform to each item.
7
+ * @example
8
+ * import { jxf_for_each, jxf_value_of } from '@lytical/jxf/transformers/index.js';
9
+ * const data = { names: ['Alice', 'Bob', 'Charlie'] };
10
+ * const transform = [
11
+ * 'Names:',
12
+ * jxf_for_each('.names', [jxf_value_of('.')]),
13
+ * ];
14
+ * const result = jxf(data, transform);
15
+ * console.log(result.join(' ')); // "Names: Alice Bob Charlie"
16
+ * @module \@lytical/jxf/transformers/for-each
17
+ * @param {string} match a jspath expression that resolves to an array
18
+ * @param {(jxf_transformer_t | string)[]} transform transformers and/or strings to apply to each item in the array
19
+ * @param {(a: string, b: string) => number} [sort] (optional) a sort function to order the items before transformation
20
+ * @returns {jxf_transformer_t} A jxf transformer function.
21
+ */
22
+ export declare function jxf_for_each(match: string, transform: (jxf_transformer_t | string)[], sort?: (a: string, b: string) => number): jxf_transformer_t;
23
+ //# sourceMappingURL=for-each.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-each.d.ts","sourceRoot":"","sources":["../../src/transformers/for-each.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,EACzC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,GACtC,iBAAiB,CA+BnB"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";import jxf from"../index.js";export function jxf_for_each(t,r,e){return(o,n)=>{const s=[];let a=apply(t,o,n);const f="object"==typeof a&&null!==a&&Array.isArray(a);if(console.assert(f,`jxf_for_key: match '${t}' did not resolve to an array.`),f){e&&(a=[...a].sort(e));for(let t=0,e=a.length;t<e;++t)s.push(...jxf(a[t],r,Object.assign(Object.assign({},n),{$even:t%2==0,$first:0===t,$index:t,$last:t===e-1,$length:e,$odd:t%2!=0,$parent:o})))}return s}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-each.js","sourceRoot":"","sources":["../../src/transformers/for-each.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAI3B,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAa,EACb,SAAyC,EACzC,IAAuC;IAEvC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,EAAE,GAAa,EAAE,CAAC;QACxB,IAAI,GAAG,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QAClC,MAAM,QAAQ,GACZ,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAChE,OAAO,CAAC,MAAM,CACZ,QAAQ,EACR,uBAAuB,KAAK,gCAAgC,CAC7D,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,IAAI,EAAE,CAAC;gBACT,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YACD,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC;gBACrD,EAAE,CAAC,IAAI,CACL,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,SAAS,kCACrB,GAAG,KACN,KAAK,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,EACpB,MAAM,EAAE,GAAG,KAAK,CAAC,EACjB,MAAM,EAAE,GAAG,EACX,KAAK,EAAE,GAAG,KAAK,GAAG,GAAG,CAAC,EACtB,OAAO,EAAE,GAAG,EACZ,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,EACnB,OAAO,EAAE,IAAI,IACb,CACH,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_for_key(match, transform, sort?)
4
+ * @description
5
+ * A transformer that iterates over each key in the object resolved by the match expression,
6
+ * applying the given transform to each key.
7
+ * @example
8
+ * import { jxf_for_key } from '@lytical/jxf/transformers/index.js';
9
+ * const data = { age: 25, name: 'Alice' };
10
+ * const transform = [
11
+ * 'Keys:',
12
+ * jxf_for_key('.*', [jxf_value_of('$key')]),
13
+ * ];
14
+ * const result = jxf(data, transform);
15
+ * console.log(result.join(' ')); // "Keys: age name"
16
+ * @module \@lytical/jxf/transformers/for-keys
17
+ * @param {string} match a jspath expression that resolves to an object
18
+ * @param {(jxf_transformer_t | string)[]} transform transformers and/or strings to apply to each key in the object
19
+ * @param {(a: string, b: string) => number} [sort] (optional) a sort function to order the keys before transformation
20
+ * @returns {jxf_transformer_t} A jxf transformer function.
21
+ */
22
+ export declare function jxf_for_key(match: string, transform: (jxf_transformer_t | string)[], sort?: (a: string, b: string) => number): jxf_transformer_t;
23
+ //# sourceMappingURL=for-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-keys.d.ts","sourceRoot":"","sources":["../../src/transformers/for-keys.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,EACzC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,GACtC,iBAAiB,CAiBnB"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";import jxf from"../index.js";export function jxf_for_key(t,e,o){return(r,s)=>{const n=[],[f]=apply(t,r,s);if(console.assert("object"==typeof f&&null!==f,`jxf_for_key: match '${t}' did not resolve to an object.`),f)for(const t of o?Object.keys(f).sort(o):Object.keys(f))n.push(...jxf(f[t],e,Object.assign(Object.assign({},s),{$key:t,$parent:r})));return n}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"for-keys.js","sourceRoot":"","sources":["../../src/transformers/for-keys.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAI3B,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,WAAW,CACzB,KAAa,EACb,SAAyC,EACzC,IAAuC;IAEvC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,EAAE,GAAa,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACtC,OAAO,CAAC,MAAM,CACZ,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EACvC,uBAAuB,KAAK,iCAAiC,CAC9D,CAAC;QACF,IAAI,GAAG,EAAE,CAAC;YACR,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACxE,EAAE,CAAC,IAAI,CACL,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,SAAS,kCAAO,GAAG,KAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,IAAG,CAClE,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_if(match, transform)
4
+ * @description
5
+ * A transformer that conditionally applies the given transform to the data if the match expression evaluates to a truthy value.
6
+ * @example
7
+ * import { jxf_if, jxf_value_of } from '@lytical/jxf/transformers/index.js';
8
+ * const data = { age: 25 };
9
+ * const transform = [
10
+ * jxf_if('.age > 18', ['You are an adult.']),
11
+ * ];
12
+ * const result = jxf(data, transform);
13
+ * console.log(result.join(' ')); // "You are an adult."
14
+ * @module \@lytical/jxf/transformers/if
15
+ * @param {string} match a jspath expression that resolves to a boolean value
16
+ * @param {(jxf_transformer_t | string)[]} transform transformers and/or strings to apply if the match expression evaluates to a truthy value
17
+ * @returns {jxf_transformer_t} A jxf transformer function.
18
+ */
19
+ export declare function jxf_if(match: string, transform: (jxf_transformer_t | string)[]): jxf_transformer_t;
20
+ //# sourceMappingURL=if.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if.d.ts","sourceRoot":"","sources":["../../src/transformers/if.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,GACxC,iBAAiB,CAKnB"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";import jxf from"../index.js";export function jxf_if(t,r){return(n,p)=>{const[e]=apply(t,n,p);return e?jxf(n,r,Object.assign(Object.assign({},p),{$eval:e})):[]}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if.js","sourceRoot":"","sources":["../../src/transformers/if.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAG3B,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CACpB,KAAa,EACb,SAAyC;IAEzC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACtC,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,kCAAO,GAAG,KAAE,KAAK,EAAE,GAAG,IAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ export * from './case.js';
2
+ export * from './for-keys.js';
3
+ export * from './for-each.js';
4
+ export * from './if.js';
5
+ export * from './length.js';
6
+ export * from './switch.js';
7
+ export * from './value-of.js';
8
+ export * from './variable.js';
9
+ export * from './with.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"AAMA,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ export*from"./case.js";export*from"./for-keys.js";export*from"./for-each.js";export*from"./if.js";export*from"./length.js";export*from"./switch.js";export*from"./value-of.js";export*from"./variable.js";export*from"./with.js";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_length(match)
4
+ * @description
5
+ * A transformer that computes the length of the array or string resolved by the match expression.
6
+ * @example
7
+ * import { jxf_length } from '@lytical/jxf/transformers/index.js';
8
+ * @param match a jspath expression that resolves to an array or string
9
+ * @returns {jxf_transformer_t} A jxf transformer function.
10
+ */
11
+ export declare function jxf_length(match: string): jxf_transformer_t;
12
+ //# sourceMappingURL=length.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"length.d.ts","sourceRoot":"","sources":["../../src/transformers/length.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAK3D"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";export function jxf_length(t){return(p,n)=>[apply(t,p,n).length.toString()]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"length.js","sourceRoot":"","sources":["../../src/transformers/length.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAI3B;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_switch(match, transform)
4
+ * @description
5
+ * A transformer that evaluates the match expression and applies the first case transform that matches.
6
+ * @example
7
+ * import { jxf_switch, jxf_case } from '@lytical/jxf/transformers/index.js';
8
+ * const data = { age: 25 };
9
+ * const transform = [
10
+ * jxf_switch('.age', [
11
+ * jxf_case('.age < 18', ['You are a minor.']),
12
+ * jxf_case('.age >= 18', ['You are an adult.']),
13
+ * ]),
14
+ * ];
15
+ * const result = jxf(data, transform);
16
+ * console.log(result.join(' ')); // "You are an adult."
17
+ * @module \@lytical/jxf/transformers/switch
18
+ * @param {string} match a jspath expression that resolves to a value to be matched
19
+ * @param {(jxf_transformer_t | string)[]} transform transformers and/or strings to apply if the match expression evaluates to a truthy value
20
+ * @returns {jxf_transformer_t} A jxf transformer function.
21
+ */
22
+ export declare function jxf_switch(match: string, transform: (jxf_transformer_t | string)[]): jxf_transformer_t;
23
+ //# sourceMappingURL=switch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/transformers/switch.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,GACxC,iBAAiB,CAWnB"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";import jxf from"../index.js";export function jxf_switch(t,n){return(r,o)=>{const[s]=apply(t,r,o);for(const t of n){const n=jxf(r,[t],Object.assign(Object.assign({},o),{$switch:s}));if(0!==n.length)return n}return[]}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/transformers/switch.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAG3B,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,UAAU,CACxB,KAAa,EACb,SAAyC;IAEzC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACtC,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;YAC1B,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,kCAAO,GAAG,KAAE,OAAO,EAAE,GAAG,IAAG,CAAC;YACpD,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpB,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_value_of(match, format)
4
+ * @description
5
+ * A transformer that extracts the value resolved by the match expression and formats it as a string.
6
+ * @example
7
+ * import { jxf_value_of } from '@lytical/jxf/transformers/index.js';
8
+ * const data = { name: 'John Doe' };
9
+ * const transform = [
10
+ * jxf_value_of('.name', (val) => `Name: ${val}`),
11
+ * ];
12
+ * const result = jxf(data, transform);
13
+ * console.log(result.join(' ')); // "Name: John Doe"
14
+ * @module \@lytical/jxf/transformers/value-of
15
+ * @param match a jspath expression that resolves to a value
16
+ * @param format a function that formats the value as a string
17
+ * @returns {jxf_transformer_t} A jxf transformer function.
18
+ */
19
+ export declare function jxf_value_of(match: string, format?: (val: any) => string): jxf_transformer_t;
20
+ //# sourceMappingURL=value-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-of.d.ts","sourceRoot":"","sources":["../../src/transformers/value-of.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAiC,GACtD,iBAAiB,CAKnB"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";export function jxf_value_of(t,o=t=>null==t?void 0:t.toString()){return(r,n)=>{const[p]=apply(t,r,n);return[o(p)]}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-of.js","sourceRoot":"","sources":["../../src/transformers/value-of.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAI3B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAa,EACb,SAA+B,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,EAAE;IAEvD,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACtC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_variable(name, match)
4
+ * @description
5
+ * A transformer that defines a variable in the transformation context by evaluating the match expression.
6
+ * @example
7
+ * import { jxf_variable, jxf_value_of } from '@lytical/jxf/transformers/index.js';
8
+ * const data = { first_name: 'John', last_name: 'Doe' };
9
+ * const transform = [
10
+ * jxf_variable('fullName', '.first_name + " " + .last_name'),
11
+ * jxf_value_of('.fullName', (val) => `Full Name: ${val}`),
12
+ * ];
13
+ * const result = jxf(data, transform);
14
+ * console.log(result.join(' ')); // "Full Name: John Doe"
15
+ * @module \@lytical/jxf/transformers/variable
16
+ * @param name the name of the variable to define
17
+ * @param match a jspath expression that resolves to a value
18
+ * @returns {jxf_transformer_t} A jxf transformer function.
19
+ */
20
+ export declare function jxf_variable(name: string, match: string): jxf_transformer_t;
21
+ //# sourceMappingURL=variable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/transformers/variable.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAY3E"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";export function jxf_variable(a,e){return(r,t)=>{const i=t[a];return console.assert(void 0===i,`jxf_variable: variable '${a}' is already defined in the context. variables are immutable.`),i||(t[a]=apply(e,r,t)),[]}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable.js","sourceRoot":"","sources":["../../src/transformers/variable.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAI3B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,KAAa;IACtD,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO,CAAC,MAAM,CACZ,GAAG,KAAK,SAAS,EACjB,2BAA2B,IAAI,+DAA+D,CAC/F,CAAC;QACF,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { jxf_transformer_t } from '../types';
2
+ /**
3
+ * jxf_with(match, transform)
4
+ * @description
5
+ * A transformer that changes the context to the value resolved by the match expression and applies the given transform.
6
+ * @example
7
+ * import { jxf_with, jxf_value_of } from '@lytical/jxf/transformers/index.js';
8
+ * const data = { user: { name: 'John Doe', age: 30 } };
9
+ * const transform = [
10
+ * jxf_with('.user', [
11
+ * jxf_value_of('.name', (val) => `Name: ${val}`),
12
+ * jxf_value_of('.age', (val) => `Age: ${val}`),
13
+ * ]),
14
+ * ];
15
+ * const result = jxf(data, transform);
16
+ * console.log(result.join(' ')); // "Name: John Doe Age: 30"
17
+ * @param match a jspath expression that resolves to a value
18
+ * @param transform transformers and/or strings to apply with the new context
19
+ * @returns {jxf_transformer_t} A jxf transformer function.
20
+ */
21
+ export declare function jxf_with(match: string, transform: (jxf_transformer_t | string)[]): jxf_transformer_t;
22
+ //# sourceMappingURL=with.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with.d.ts","sourceRoot":"","sources":["../../src/transformers/with.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,GACxC,iBAAiB,CAKnB"}
@@ -0,0 +1,6 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+ import apply from"jspath";import jxf from"../index.js";export function jxf_with(t,r){return(n,p)=>{const e=apply(t,n,p);return e?jxf(e,r,Object.assign(Object.assign({},p),{$parent:n})):[]}}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with.js","sourceRoot":"","sources":["../../src/transformers/with.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,MAAM,QAAQ,CAAC;AAG3B,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAa,EACb,SAAyC;IAEzC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAY,EAAE;QAC7B,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,kCAAO,GAAG,KAAE,OAAO,EAAE,IAAI,IAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC"}
package/types.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /* @preserve
2
+ (c) 2025 lytical, inc. all rights are reserved.
3
+ lytical(r) is a registered trademark of lytical, inc.
4
+ please refer to your license agreement on the use of this file.
5
+ */
6
+
7
+ /**
8
+ * jxf_ctx_t
9
+ * Stores context variables for jxf transformers.
10
+ * @description
11
+ * Context object type used in jxf transformers.
12
+ * @typedef {Record<string, any>} jxf_ctx_t
13
+ * @property {Record<string, any>} [key: string] - dynamic properties to hold context variables
14
+ * @module \@lytical/jxf/types
15
+ */
16
+ export type jxf_ctx_t = Record<string, any>;
17
+
18
+ /**
19
+ * jxf_transformer_t
20
+ * A function type for jxf transformers.
21
+ * @description
22
+ * Function type that defines the signature for jxf transformers.
23
+ * @example
24
+ * import type { jxf_ctx_t, jxf_transformer_t } from '@lytical/jxf/types';
25
+ *
26
+ * const myTransformer: jxf_transformer_t = (data: any, ctx: jxf_ctx_t): string[] => {
27
+ * // Transformer logic here
28
+ * return [`Transformed data: ${JSON.stringify(data)}`];
29
+ * };
30
+ *
31
+ * export default myTransformer;
32
+ *
33
+ * @typedef {(data: any, ctx: jxf_ctx_t) => string[]} jxf_transformer_t
34
+ * @module \@lytical/jxf/types
35
+ * @param {any} data - The input data to be transformed.
36
+ * @param {jxf_ctx_t} ctx - The context object containing variables for transformation.
37
+ * @returns {string[]} An array of strings resulting from the transformation.
38
+ */
39
+ export type jxf_transformer_t = (data: any, ctx: jxf_ctx_t) => string[];
40
+
41
+ // the current version of (@types/jspath@0.4.2) is outdated and does not properly exports the default apply() function.
42
+ declare module 'jspath' {
43
+ export default function apply<_t_ = any>(
44
+ path: string,
45
+ data: any,
46
+ replacement?: any,
47
+ ): _t_[];
48
+ }