jexp 0.1.5 → 0.1.8
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/README.md +182 -115
- package/index.js +1 -8
- package/index.js.map +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -4,12 +4,15 @@ Command line application that allows parser and evaluator of json/yaml applying
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
- json and yaml formats
|
|
8
|
+
- Constants, enums, number, string, datetime, variables, objects and array
|
|
9
|
+
- Arithmetic , assignment , comparison , logical and bitwise operators
|
|
10
|
+
- Number , string , datetime , array and nullable functions
|
|
11
|
+
- Conversion functions
|
|
12
|
+
- Arrow functions
|
|
13
|
+
- Group functions (distinct, first, last, min, max, sum and avg)
|
|
14
|
+
- Sets functions (union, intersection, difference and symmetric difference)
|
|
11
15
|
- Environment variables
|
|
12
|
-
- json and yaml
|
|
13
16
|
|
|
14
17
|
## Global installation
|
|
15
18
|
|
|
@@ -27,11 +30,10 @@ jexp <expression> <source> [options]
|
|
|
27
30
|
|
|
28
31
|
### Expression
|
|
29
32
|
|
|
30
|
-
The expressions correspond to the package [js-expressions](https://www.npmjs.com/package/js-expressions)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
the root of the data is accessed from **dot**
|
|
33
|
+
> The expressions correspond to the package [js-expressions](https://www.npmjs.com/package/js-expressions)
|
|
34
|
+
> expression that is applied to the data source
|
|
35
|
+
>
|
|
36
|
+
> The root of the data is accessed from **dot**
|
|
35
37
|
|
|
36
38
|
```sh
|
|
37
39
|
jexp '.' ./data/orders.json
|
|
@@ -79,7 +81,6 @@ curl -s https://raw.githubusercontent.com/FlavioLionelRita/jexp/main/data/orders
|
|
|
79
81
|
|-------------------|--------------|----------------|-----------|
|
|
80
82
|
|--output <format> |-o |Force output | json, yaml|
|
|
81
83
|
|--beautiful |-b |Beautiful output| |
|
|
82
|
-
|--decorate |-d |Decorate output | |
|
|
83
84
|
|
|
84
85
|
## Examples
|
|
85
86
|
|
|
@@ -106,53 +107,64 @@ file orders.js
|
|
|
106
107
|
{ "article": "Banana", "unitPrice": 1.99, "qty": 2 },
|
|
107
108
|
{ "article": "Pear", "unitPrice": 1.78, "qty": 1 }
|
|
108
109
|
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"number": "20003",
|
|
113
|
+
"customer": { "firstName": "George", "lastName": "Williams" },
|
|
114
|
+
"orderTime": "2022-07-30T14:43:11",
|
|
115
|
+
"details": [
|
|
116
|
+
{ "article": "Apple", "unitPrice": 2.15, "qty": 1 },
|
|
117
|
+
{ "article": "Banana", "unitPrice": 1.99, "qty": 1 },
|
|
118
|
+
{ "article": "Pear", "unitPrice": 1.78, "qty": 1 },
|
|
119
|
+
{ "article": "White grape", "unitPrice": 2.03, "qty": 1 }
|
|
120
|
+
]
|
|
109
121
|
}
|
|
110
122
|
]
|
|
111
123
|
```
|
|
112
124
|
|
|
113
|
-
Return the entire content of the file
|
|
125
|
+
**Return the entire content of the file**:
|
|
114
126
|
|
|
115
127
|
```sh
|
|
116
128
|
jexp '.' ./data/orders.json
|
|
117
129
|
```
|
|
118
130
|
|
|
119
|
-
Result
|
|
131
|
+
*Result*:
|
|
120
132
|
|
|
121
133
|
```json
|
|
122
|
-
[{"number":"20001","customer":{"firstName":"John","lastName":"Murphy"},"orderTime":"2022-07-30T10:15:54","details":[{"article":"Pear","unitPrice":1.78,"qty":2},{"article":"Banana","unitPrice":1.99,"qty":1},{"article":"White grape","unitPrice":2.03,"qty":1}]},{"number":"20002","customer":{"firstName":"Paul","lastName":"Smith"},"orderTime":"2022-07-30T12:12:43","details":[{"article":"Apple","unitPrice":2.15,"qty":1},{"article":"Banana","unitPrice":1.99,"qty":2},{"article":"Pear","unitPrice":1.78,"qty":1}]}]
|
|
134
|
+
[{"number":"20001","customer":{"firstName":"John","lastName":"Murphy"},"orderTime":"2022-07-30T10:15:54","details":[{"article":"Pear","unitPrice":1.78,"qty":2},{"article":"Banana","unitPrice":1.99,"qty":1},{"article":"White grape","unitPrice":2.03,"qty":1}]},{"number":"20002","customer":{"firstName":"Paul","lastName":"Smith"},"orderTime":"2022-07-30T12:12:43","details":[{"article":"Apple","unitPrice":2.15,"qty":1},{"article":"Banana","unitPrice":1.99,"qty":2},{"article":"Pear","unitPrice":1.78,"qty":1}]},{"number":"20003","customer":{"firstName":"George","lastName":"Williams"},"orderTime":"2022-07-30T14:43:11","details":[{"article":"Apple","unitPrice":2.15,"qty":1},{"article":"Banana","unitPrice":1.99,"qty":1},{"article":"Pear","unitPrice":1.78,"qty":1},{"article":"White grape","unitPrice":2.03,"qty":1}]}]
|
|
123
135
|
```
|
|
124
136
|
|
|
125
|
-
Returns the number property of the list
|
|
137
|
+
**Returns the number property of the list**:
|
|
126
138
|
|
|
127
139
|
```sh
|
|
128
140
|
jexp '.number' ./data/orders.json
|
|
129
141
|
```
|
|
130
142
|
|
|
131
|
-
Result
|
|
143
|
+
*Result*:
|
|
132
144
|
|
|
133
145
|
```json
|
|
134
|
-
["20001","20002"]
|
|
146
|
+
["20001","20002","20003"]
|
|
135
147
|
```
|
|
136
148
|
|
|
137
|
-
Concatenates two properties and capitalizes the first one
|
|
149
|
+
**Concatenates two properties and capitalizes the first one**:
|
|
138
150
|
|
|
139
151
|
```sh
|
|
140
152
|
jexp 'concatenate(capitalize(.fruit.name)," ",.fruit.color)' '{"fruit":{"name":"apple","color":"green","price":1.20}}'
|
|
141
153
|
```
|
|
142
154
|
|
|
143
|
-
Result
|
|
155
|
+
*Result*:
|
|
144
156
|
|
|
145
157
|
```json
|
|
146
158
|
"Apple green"
|
|
147
159
|
```
|
|
148
160
|
|
|
149
|
-
Returns the first element of an array from the index in yaml format
|
|
161
|
+
**Returns the first element of an array from the index in yaml format**:
|
|
150
162
|
|
|
151
163
|
```sh
|
|
152
164
|
jexp '.[0]' ./data/orders.json -o yaml
|
|
153
165
|
```
|
|
154
166
|
|
|
155
|
-
Result
|
|
167
|
+
*Result*:
|
|
156
168
|
|
|
157
169
|
```yaml
|
|
158
170
|
number: '20001'
|
|
@@ -173,13 +185,13 @@ details:
|
|
|
173
185
|
|
|
174
186
|
```
|
|
175
187
|
|
|
176
|
-
Returns the details property of the first element in beautiful format
|
|
188
|
+
**Returns the details property of the first element in beautiful format**:
|
|
177
189
|
|
|
178
190
|
```sh
|
|
179
191
|
jexp '.[0].details' ./data/orders.json -b
|
|
180
192
|
```
|
|
181
193
|
|
|
182
|
-
Result
|
|
194
|
+
*Result*:
|
|
183
195
|
|
|
184
196
|
```json
|
|
185
197
|
[
|
|
@@ -201,145 +213,194 @@ Result:
|
|
|
201
213
|
]
|
|
202
214
|
```
|
|
203
215
|
|
|
204
|
-
Returns the details property of the
|
|
216
|
+
**Returns the details property of the first element, as the file is yaml, it returns it in yaml format**:
|
|
217
|
+
|
|
218
|
+
```sh
|
|
219
|
+
jexp '.[0].details' ./data/orders.yaml
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
*Result*:
|
|
223
|
+
|
|
224
|
+
```yaml
|
|
225
|
+
- article: Pear
|
|
226
|
+
unitPrice: 1.78
|
|
227
|
+
qty: 2
|
|
228
|
+
- article: Banana
|
|
229
|
+
unitPrice: 1.99
|
|
230
|
+
qty: 1
|
|
231
|
+
- article: White grape
|
|
232
|
+
unitPrice: 2.03
|
|
233
|
+
qty: 1
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Returns the details property of the first element, although the file is yaml it forces the output in json format**:
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
jexp '.[0].details' ./data/orders.yaml -b -o json
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
*Result*:
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
[
|
|
247
|
+
{
|
|
248
|
+
"article": "Pear",
|
|
249
|
+
"unitPrice": 1.78,
|
|
250
|
+
"qty": 2
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"article": "Banana",
|
|
254
|
+
"unitPrice": 1.99,
|
|
255
|
+
"qty": 1
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"article": "White grape",
|
|
259
|
+
"unitPrice": 2.03,
|
|
260
|
+
"qty": 1
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Returns the details property of the listing**:
|
|
205
266
|
|
|
206
267
|
```sh
|
|
207
268
|
jexp '.details' ./data/orders.json
|
|
208
269
|
```
|
|
209
270
|
|
|
210
|
-
Result
|
|
271
|
+
*Result*:
|
|
211
272
|
|
|
212
273
|
```json
|
|
213
|
-
[{"article":"Pear","unitPrice":1.78,"qty":2},{"article":"Banana","unitPrice":1.99,"qty":1},{"article":"White grape","unitPrice":2.03,"qty":1},{"article":"Apple","unitPrice":2.15,"qty":1},{"article":"Banana","unitPrice":1.99,"qty":2},{"article":"Pear","unitPrice":1.78,"qty":1}]
|
|
274
|
+
[{"article":"Pear","unitPrice":1.78,"qty":2},{"article":"Banana","unitPrice":1.99,"qty":1},{"article":"White grape","unitPrice":2.03,"qty":1},{"article":"Apple","unitPrice":2.15,"qty":1},{"article":"Banana","unitPrice":1.99,"qty":2},{"article":"Pear","unitPrice":1.78,"qty":1},{"article":"Apple","unitPrice":2.15,"qty":1},{"article":"Banana","unitPrice":1.99,"qty":1},{"article":"Pear","unitPrice":1.78,"qty":1},{"article":"White grape","unitPrice":2.03,"qty":1}]
|
|
214
275
|
```
|
|
215
276
|
|
|
216
|
-
Returns the article property of the list of details of each element of the list
|
|
277
|
+
**Returns the article property of the list of details of each element of the list**:
|
|
217
278
|
|
|
218
279
|
```sh
|
|
219
280
|
jexp '.details.article' ./data/orders.json
|
|
220
281
|
```
|
|
221
282
|
|
|
222
|
-
Result
|
|
283
|
+
*Result*:
|
|
223
284
|
|
|
224
285
|
```json
|
|
225
|
-
["Pear","Banana","White grape","Apple","Banana","Pear"]
|
|
286
|
+
["Pear","Banana","White grape","Apple","Banana","Pear","Apple","Banana","Pear","White grape"]
|
|
226
287
|
```
|
|
227
288
|
|
|
228
|
-
Get the minimum of the total property
|
|
289
|
+
**Get the minimum of the total property**:
|
|
229
290
|
|
|
230
291
|
```sh
|
|
231
292
|
jexp '.min(p=> p.total)' ./data/orders.json
|
|
232
293
|
```
|
|
233
294
|
|
|
234
|
-
Result
|
|
295
|
+
*Result*:
|
|
235
296
|
|
|
236
297
|
```json
|
|
237
298
|
null
|
|
238
299
|
```
|
|
239
300
|
|
|
240
|
-
Get the minimum of the article property from all the details
|
|
301
|
+
**Get the minimum of the article property from all the details**:
|
|
241
302
|
|
|
242
303
|
```sh
|
|
243
304
|
jexp '.details.min(p=> p.article )' ./data/orders.json
|
|
244
305
|
```
|
|
245
306
|
|
|
246
|
-
Result
|
|
307
|
+
*Result*:
|
|
247
308
|
|
|
248
309
|
```json
|
|
249
310
|
"Apple"
|
|
250
311
|
```
|
|
251
312
|
|
|
252
|
-
Get the maximum "unitPrice * p.qty" from all the details
|
|
313
|
+
**Get the maximum "unitPrice * p.qty" from all the details**:
|
|
253
314
|
|
|
254
315
|
```sh
|
|
255
316
|
jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
256
317
|
```
|
|
257
318
|
|
|
258
|
-
Result
|
|
319
|
+
*Result*:
|
|
259
320
|
|
|
260
321
|
```json
|
|
261
322
|
3.98
|
|
262
323
|
```
|
|
263
324
|
|
|
264
|
-
Get the middle value "unitPrice * p.qty" from all the details
|
|
325
|
+
**Get the middle value "unitPrice * p.qty" from all the details**:
|
|
265
326
|
|
|
266
327
|
```sh
|
|
267
328
|
jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
268
329
|
```
|
|
269
330
|
|
|
270
|
-
Result
|
|
331
|
+
*Result*:
|
|
271
332
|
|
|
272
333
|
```json
|
|
273
|
-
2.
|
|
334
|
+
2.3440000000000003
|
|
274
335
|
```
|
|
275
336
|
|
|
276
|
-
Gets the sum of the total property
|
|
337
|
+
**Gets the sum of the total property**:
|
|
277
338
|
|
|
278
339
|
```sh
|
|
279
340
|
jexp '.sum(p=> p.total )' ./data/orders.json
|
|
280
341
|
```
|
|
281
342
|
|
|
282
|
-
Result
|
|
343
|
+
*Result*:
|
|
283
344
|
|
|
284
345
|
```json
|
|
285
346
|
0
|
|
286
347
|
```
|
|
287
348
|
|
|
288
|
-
Get the sum "unitPrice * p.qty" of the details of item 1 of the list
|
|
349
|
+
**Get the sum "unitPrice * p.qty" of the details of item 1 of the list**:
|
|
289
350
|
|
|
290
351
|
```sh
|
|
291
352
|
jexp '.[1].details.sum(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
292
353
|
```
|
|
293
354
|
|
|
294
|
-
Result
|
|
355
|
+
*Result*:
|
|
295
356
|
|
|
296
357
|
```json
|
|
297
358
|
7.91
|
|
298
359
|
```
|
|
299
360
|
|
|
300
|
-
Get the number of details where "unitPrice * p.qty " is less than 3
|
|
361
|
+
**Get the number of details where "unitPrice * p.qty " is less than 3**:
|
|
301
362
|
|
|
302
363
|
```sh
|
|
303
364
|
jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
304
365
|
```
|
|
305
366
|
|
|
306
|
-
Result
|
|
367
|
+
*Result*:
|
|
307
368
|
|
|
308
369
|
```json
|
|
309
|
-
|
|
370
|
+
8
|
|
310
371
|
```
|
|
311
372
|
|
|
312
|
-
Get the first article property of all details where "unitPrice * p.qty" is less than 3
|
|
373
|
+
**Get the first article property of all details where "unitPrice * p.qty" is less than 3**:
|
|
313
374
|
|
|
314
375
|
```sh
|
|
315
376
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
316
377
|
```
|
|
317
378
|
|
|
318
|
-
Result
|
|
379
|
+
*Result*:
|
|
319
380
|
|
|
320
381
|
```json
|
|
321
382
|
"Banana"
|
|
322
383
|
```
|
|
323
384
|
|
|
324
|
-
Get the last article property of all details where "unitPrice * p.qty" is less than 3
|
|
385
|
+
**Get the last article property of all details where "unitPrice * p.qty" is less than 3**:
|
|
325
386
|
|
|
326
387
|
```sh
|
|
327
388
|
jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
328
389
|
```
|
|
329
390
|
|
|
330
|
-
Result
|
|
391
|
+
*Result*:
|
|
331
392
|
|
|
332
393
|
```json
|
|
333
|
-
"
|
|
394
|
+
"White grape"
|
|
334
395
|
```
|
|
335
396
|
|
|
336
|
-
Get the first detail where "unitPrice * p.qty" is less than 3 in beautiful format
|
|
397
|
+
**Get the first detail where "unitPrice * p.qty" is less than 3 in beautiful format**:
|
|
337
398
|
|
|
338
399
|
```sh
|
|
339
400
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json -b
|
|
340
401
|
```
|
|
341
402
|
|
|
342
|
-
Result
|
|
403
|
+
*Result*:
|
|
343
404
|
|
|
344
405
|
```json
|
|
345
406
|
{
|
|
@@ -349,157 +410,157 @@ Result:
|
|
|
349
410
|
}
|
|
350
411
|
```
|
|
351
412
|
|
|
352
|
-
Get the sum "unitPrice * p.qty" of the details of item 1 of the list using pipeline
|
|
413
|
+
**Get the sum "unitPrice * p.qty" of the details of item 1 of the list using pipeline**:
|
|
353
414
|
|
|
354
415
|
```sh
|
|
355
416
|
curl -s https://raw.githubusercontent.com/FlavioLionelRita/jexp/main/data/orders.json | jexp '.details.sum(p=> p.unitPrice * p.qty )'
|
|
356
417
|
```
|
|
357
418
|
|
|
358
|
-
Result
|
|
419
|
+
*Result*:
|
|
359
420
|
|
|
360
421
|
```json
|
|
361
422
|
15.49
|
|
362
423
|
```
|
|
363
424
|
|
|
364
|
-
Get the smallest article
|
|
425
|
+
**Get the smallest article**:
|
|
365
426
|
|
|
366
427
|
```sh
|
|
367
428
|
jexp '.details.min(p=> p.article )' ./data/orders.json
|
|
368
429
|
```
|
|
369
430
|
|
|
370
|
-
Result
|
|
431
|
+
*Result*:
|
|
371
432
|
|
|
372
433
|
```json
|
|
373
434
|
"Apple"
|
|
374
435
|
```
|
|
375
436
|
|
|
376
|
-
Get the total of all the details
|
|
437
|
+
**Get the total of all the details**:
|
|
377
438
|
|
|
378
439
|
```sh
|
|
379
440
|
jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
380
441
|
```
|
|
381
442
|
|
|
382
|
-
Result
|
|
443
|
+
*Result*:
|
|
383
444
|
|
|
384
445
|
```json
|
|
385
446
|
3.98
|
|
386
447
|
```
|
|
387
448
|
|
|
388
|
-
Get the mean value of all details
|
|
449
|
+
**Get the mean value of all details**:
|
|
389
450
|
|
|
390
451
|
```sh
|
|
391
452
|
jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
392
453
|
```
|
|
393
454
|
|
|
394
|
-
Result
|
|
455
|
+
*Result*:
|
|
395
456
|
|
|
396
457
|
```json
|
|
397
|
-
2.
|
|
458
|
+
2.3440000000000003
|
|
398
459
|
```
|
|
399
460
|
|
|
400
|
-
Get the total of the details of order 1
|
|
461
|
+
**Get the total of the details of order 1**:
|
|
401
462
|
|
|
402
463
|
```sh
|
|
403
464
|
jexp '.[1].details.sum(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
404
465
|
```
|
|
405
466
|
|
|
406
|
-
Result
|
|
467
|
+
*Result*:
|
|
407
468
|
|
|
408
469
|
```json
|
|
409
470
|
7.91
|
|
410
471
|
```
|
|
411
472
|
|
|
412
|
-
Gets the number of details where the subtotal is less than 3
|
|
473
|
+
**Gets the number of details where the subtotal is less than 3**:
|
|
413
474
|
|
|
414
475
|
```sh
|
|
415
476
|
jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
416
477
|
```
|
|
417
478
|
|
|
418
|
-
Result
|
|
479
|
+
*Result*:
|
|
419
480
|
|
|
420
481
|
```json
|
|
421
|
-
|
|
482
|
+
8
|
|
422
483
|
```
|
|
423
484
|
|
|
424
|
-
Get the article of the first detail where the subtotal is less than 3
|
|
485
|
+
**Get the article of the first detail where the subtotal is less than 3**:
|
|
425
486
|
|
|
426
487
|
```sh
|
|
427
488
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
428
489
|
```
|
|
429
490
|
|
|
430
|
-
Result
|
|
491
|
+
*Result*:
|
|
431
492
|
|
|
432
493
|
```json
|
|
433
494
|
"Banana"
|
|
434
495
|
```
|
|
435
496
|
|
|
436
|
-
Get the article of the last detail where the subtotal is less than 3
|
|
497
|
+
**Get the article of the last detail where the subtotal is less than 3**:
|
|
437
498
|
|
|
438
499
|
```sh
|
|
439
500
|
jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
440
501
|
```
|
|
441
502
|
|
|
442
|
-
Result
|
|
503
|
+
*Result*:
|
|
443
504
|
|
|
444
505
|
```json
|
|
445
|
-
"
|
|
506
|
+
"White grape"
|
|
446
507
|
```
|
|
447
508
|
|
|
448
|
-
Get the first detail where the subtotal is less than 3
|
|
509
|
+
**Get the first detail where the subtotal is less than 3**:
|
|
449
510
|
|
|
450
511
|
```sh
|
|
451
512
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
452
513
|
```
|
|
453
514
|
|
|
454
|
-
Result
|
|
515
|
+
*Result*:
|
|
455
516
|
|
|
456
517
|
```json
|
|
457
518
|
{"article":"Banana","unitPrice":1.99,"qty":1}
|
|
458
519
|
```
|
|
459
520
|
|
|
460
|
-
Calculate the total for each order
|
|
521
|
+
**Calculate the total for each order**:
|
|
461
522
|
|
|
462
523
|
```sh
|
|
463
524
|
jexp '.each(p=>p.total=p.details.sum(q=>q.qty*q.unitPrice)).map(p=>{nro:p.number,total:p.total})' ./data/orders.json
|
|
464
525
|
```
|
|
465
526
|
|
|
466
|
-
Result
|
|
527
|
+
*Result*:
|
|
467
528
|
|
|
468
529
|
```json
|
|
469
|
-
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
|
|
530
|
+
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91},{"nro":"20003","total":7.949999999999999}]
|
|
470
531
|
```
|
|
471
532
|
|
|
472
|
-
Calculate the subtotal for each order
|
|
533
|
+
**Calculate the subtotal for each order**:
|
|
473
534
|
|
|
474
535
|
```sh
|
|
475
536
|
jexp '.details.foreach(p=>p.subtotal=p.qty*p.unitPrice).subtotal' ./data/orders.json
|
|
476
537
|
```
|
|
477
538
|
|
|
478
|
-
Result
|
|
539
|
+
*Result*:
|
|
479
540
|
|
|
480
541
|
```json
|
|
481
|
-
[3.56,1.99,2.03,2.15,3.98,1.78]
|
|
542
|
+
[3.56,1.99,2.03,2.15,3.98,1.78,2.15,1.99,1.78,2.03]
|
|
482
543
|
```
|
|
483
544
|
|
|
484
|
-
calculates the total of all the details
|
|
545
|
+
**calculates the total of all the details**:
|
|
485
546
|
|
|
486
547
|
```sh
|
|
487
548
|
jexp '.details.foreach(p=>total=nvl(total,0)+p.qty*p.unitPrice);total' ./data/orders.json
|
|
488
549
|
```
|
|
489
550
|
|
|
490
|
-
Result
|
|
551
|
+
*Result*:
|
|
491
552
|
|
|
492
553
|
```json
|
|
493
|
-
|
|
554
|
+
23.44
|
|
494
555
|
```
|
|
495
556
|
|
|
496
|
-
Get the list of items without repeating
|
|
557
|
+
**Get the list of items without repeating**:
|
|
497
558
|
|
|
498
559
|
```sh
|
|
499
560
|
jexp '.details.distinct(p=>p.article)' ./data/orders.json -b
|
|
500
561
|
```
|
|
501
562
|
|
|
502
|
-
Result
|
|
563
|
+
*Result*:
|
|
503
564
|
|
|
504
565
|
```json
|
|
505
566
|
[
|
|
@@ -510,104 +571,110 @@ Result:
|
|
|
510
571
|
]
|
|
511
572
|
```
|
|
512
573
|
|
|
513
|
-
Get the list of items and quantity without repeating
|
|
574
|
+
**Get the list of items and quantity without repeating**:
|
|
514
575
|
|
|
515
576
|
```sh
|
|
516
|
-
jexp '.details.distinct(p=>{article:p.article,qty:p.qty})' ./data/orders.json
|
|
577
|
+
jexp '.details.distinct(p=>{article:p.article,qty:p.qty}) -b' ./data/orders.json
|
|
517
578
|
```
|
|
518
579
|
|
|
519
|
-
Result
|
|
580
|
+
*Result*:
|
|
520
581
|
|
|
521
582
|
```json
|
|
522
|
-
|
|
583
|
+
null
|
|
523
584
|
```
|
|
524
585
|
|
|
525
|
-
Get the total and amount of each item
|
|
586
|
+
**Get the total and amount of each item**:
|
|
526
587
|
|
|
527
588
|
```sh
|
|
528
589
|
jexp '.details.map(p=>{article:p.article,count:count(1),total:sum(p.qty * p.unitPrice)})' ./data/orders.json -b
|
|
529
590
|
```
|
|
530
591
|
|
|
531
|
-
Result
|
|
592
|
+
*Result*:
|
|
532
593
|
|
|
533
594
|
```json
|
|
534
595
|
[
|
|
535
596
|
{
|
|
536
597
|
"article": "Pear",
|
|
537
|
-
"count":
|
|
538
|
-
"total":
|
|
598
|
+
"count": 3,
|
|
599
|
+
"total": 7.12
|
|
539
600
|
},
|
|
540
601
|
{
|
|
541
602
|
"article": "Banana",
|
|
542
|
-
"count":
|
|
543
|
-
"total":
|
|
603
|
+
"count": 3,
|
|
604
|
+
"total": 7.96
|
|
544
605
|
},
|
|
545
606
|
{
|
|
546
607
|
"article": "White grape",
|
|
547
|
-
"count":
|
|
548
|
-
"total":
|
|
608
|
+
"count": 2,
|
|
609
|
+
"total": 4.06
|
|
549
610
|
},
|
|
550
611
|
{
|
|
551
612
|
"article": "Apple",
|
|
552
|
-
"count":
|
|
553
|
-
"total":
|
|
613
|
+
"count": 2,
|
|
614
|
+
"total": 4.3
|
|
554
615
|
}
|
|
555
616
|
]
|
|
556
617
|
```
|
|
557
618
|
|
|
558
|
-
Get the total of the first order
|
|
619
|
+
**Get the total of the first order**:
|
|
559
620
|
|
|
560
621
|
```sh
|
|
561
622
|
jexp '{total:.[0].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json
|
|
562
623
|
```
|
|
563
624
|
|
|
564
|
-
Result
|
|
625
|
+
*Result*:
|
|
565
626
|
|
|
566
627
|
```json
|
|
567
628
|
{"total":7.58}
|
|
568
629
|
```
|
|
569
630
|
|
|
570
|
-
Get the total of the last order
|
|
631
|
+
**Get the total of the last order**:
|
|
571
632
|
|
|
572
633
|
```sh
|
|
573
634
|
jexp '{total:.[.length()-1].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json -b
|
|
574
635
|
```
|
|
575
636
|
|
|
576
|
-
Result
|
|
637
|
+
*Result*:
|
|
577
638
|
|
|
578
639
|
```json
|
|
579
640
|
{
|
|
580
|
-
"total": 7.
|
|
641
|
+
"total": 7.949999999999999
|
|
581
642
|
}
|
|
582
643
|
```
|
|
583
644
|
|
|
584
|
-
List the orders with their totals
|
|
645
|
+
**List the orders with their totals**:
|
|
585
646
|
|
|
586
647
|
```sh
|
|
587
648
|
jexp '.map(p=>{nro:p.number,total:p.details.sum(q=>q.qty * q.unitPrice)})' ./data/orders.json
|
|
588
649
|
```
|
|
589
650
|
|
|
590
|
-
Result
|
|
651
|
+
*Result*:
|
|
591
652
|
|
|
592
653
|
```json
|
|
593
|
-
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
|
|
654
|
+
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91},{"nro":"20003","total":7.949999999999999}]
|
|
594
655
|
```
|
|
595
656
|
|
|
596
657
|
## js-expression
|
|
597
658
|
|
|
598
|
-
[Js-expression](https://www.npmjs.com/package/js-expressions) is an extensible expression evaluator and parser.
|
|
599
|
-
|
|
659
|
+
> [Js-expression](https://www.npmjs.com/package/js-expressions) is an extensible expression evaluator and parser.
|
|
660
|
+
>
|
|
661
|
+
> Besides the operators, functions, variables, objects and arrays that are supported.
|
|
600
662
|
|
|
601
663
|
### Documentation
|
|
602
664
|
|
|
603
|
-
- [
|
|
604
|
-
- [Assignment](https://github.com/FlavioLionelRita/js-expressions/wiki/Assignment)
|
|
605
|
-
- [Bitwise](https://github.com/FlavioLionelRita/js-expressions/wiki/Bitwise)
|
|
665
|
+
- [Arithmetic](https://github.com/FlavioLionelRita/js-expressions/wiki/Arithmetic)
|
|
606
666
|
- [Comparison](https://github.com/FlavioLionelRita/js-expressions/wiki/Comparison)
|
|
607
|
-
- [Control flows](https://github.com/FlavioLionelRita/js-expressions/wiki/Flows)
|
|
608
|
-
- [Datetime](https://github.com/FlavioLionelRita/js-expressions/wiki/Datetime)
|
|
609
|
-
- [Extend](https://github.com/FlavioLionelRita/js-expressions/wiki/Extend)
|
|
610
667
|
- [Logical](https://github.com/FlavioLionelRita/js-expressions/wiki/Logical)
|
|
611
|
-
- [
|
|
668
|
+
- [Bitwise](https://github.com/FlavioLionelRita/js-expressions/wiki/Bitwise)
|
|
612
669
|
- [Numeric](https://github.com/FlavioLionelRita/js-expressions/wiki/Numeric)
|
|
613
670
|
- [String](https://github.com/FlavioLionelRita/js-expressions/wiki/String)
|
|
671
|
+
- [Datetime](https://github.com/FlavioLionelRita/js-expressions/wiki/Datetime)
|
|
672
|
+
- [Nullable](https://github.com/FlavioLionelRita/js-expressions/wiki/Nullable)
|
|
673
|
+
- [Conversion](https://github.com/FlavioLionelRita/js-expressions/wiki/Conversion)
|
|
674
|
+
- [Assignment](https://github.com/FlavioLionelRita/js-expressions/wiki/Assignment)
|
|
675
|
+
- [Array](https://github.com/FlavioLionelRita/js-expressions/wiki/Array)
|
|
676
|
+
- [Arrow](https://github.com/FlavioLionelRita/js-expressions/wiki/Arrow)
|
|
677
|
+
- [Group](https://github.com/FlavioLionelRita/js-expressions/wiki/Group)
|
|
678
|
+
- [Sets](https://github.com/FlavioLionelRita/js-expressions/wiki/Sets)
|
|
679
|
+
- [Control flows](https://github.com/FlavioLionelRita/js-expressions/wiki/Flows)
|
|
680
|
+
- [Extend](https://github.com/FlavioLionelRita/js-expressions/wiki/Extend)
|
package/index.js
CHANGED
|
@@ -16,7 +16,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
const js_expressions_1 = require("js-expressions");
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
18
|
const { program, Option } = require('commander');
|
|
19
|
-
const colorize = require('json-colorizer');
|
|
20
19
|
const yaml = require('js-yaml');
|
|
21
20
|
const run = (expression, source, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
21
|
let data = {};
|
|
@@ -51,12 +50,7 @@ const run = (expression, source, options) => __awaiter(void 0, void 0, void 0, f
|
|
|
51
50
|
}
|
|
52
51
|
else {
|
|
53
52
|
const formatted = options.beautiful ? JSON.stringify(result, null, 2) : JSON.stringify(result);
|
|
54
|
-
|
|
55
|
-
console.log(colorize(formatted));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
console.log(formatted);
|
|
59
|
-
}
|
|
53
|
+
console.log(formatted);
|
|
60
54
|
}
|
|
61
55
|
});
|
|
62
56
|
const getInput = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -81,7 +75,6 @@ function main() {
|
|
|
81
75
|
.argument('[source]')
|
|
82
76
|
.addOption(new Option('-o, --output <format>', 'Force output').choices(['json', 'yaml']))
|
|
83
77
|
.option('-b, --beautiful', 'Beautiful output', false)
|
|
84
|
-
.option('-d, --decorate', 'Decorate output', false)
|
|
85
78
|
.option('-q, --query-file <path>', 'query file')
|
|
86
79
|
.action((expression, source, options) => __awaiter(this, void 0, void 0, function* () {
|
|
87
80
|
try {
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mDAA2D;AAC3D,gDAAuB;AACvB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAChD,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mDAA2D;AAC3D,gDAAuB;AACvB,MAAM,EAAE,OAA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CAAC,UAAU,CAAC;aACpB,SAAS,CAAC,IAAI,MAAM,CAAC,uBAAuB,EAAE,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;aACxF,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,KAAK,CAAC;aACpD,MAAM,CAAC,yBAAyB,EAAE,YAAY,CAAC;aAC/C,MAAM,CAAC,CAAO,UAAiB,EAAE,MAAU,EAAE,OAAW,EAAE,EAAE;YAC5D,IAAI;gBACH,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,QAAQ,EAAS,CAAA;gBACtE,MAAM,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;aACpC;YAAC,OAAO,KAAS,EAAE;gBACnB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;aAC5B;QACF,CAAC,CAAA,CAAC,CAAA;QACH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC;CAAA;AACD,IAAI,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jexp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Parser and evaluator of expressions by line of commands. The expressions correspond to the package js-expressions",
|
|
5
5
|
"author": "Flavio Lionel Rita <flaviolrita@hotmail.com>",
|
|
6
6
|
"license": "Apache-2.0 License",
|
|
@@ -18,9 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"commander": "^9.4.0",
|
|
21
|
-
"js-expressions": "1.0
|
|
22
|
-
"js-yaml": "^4.1.0"
|
|
23
|
-
"json-colorizer": "^2.2.2"
|
|
21
|
+
"js-expressions": "1.1.0",
|
|
22
|
+
"js-yaml": "^4.1.0"
|
|
24
23
|
},
|
|
25
24
|
"keywords": [
|
|
26
25
|
"cli",
|