jexp 0.1.4 → 0.1.7
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 +161 -83
- package/index.js +1 -8
- package/index.js.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -79,7 +79,6 @@ curl -s https://raw.githubusercontent.com/FlavioLionelRita/jexp/main/data/orders
|
|
|
79
79
|
|-------------------|--------------|----------------|-----------|
|
|
80
80
|
|--output <format> |-o |Force output | json, yaml|
|
|
81
81
|
|--beautiful |-b |Beautiful output| |
|
|
82
|
-
|--decorate |-d |Decorate output | |
|
|
83
82
|
|
|
84
83
|
## Examples
|
|
85
84
|
|
|
@@ -110,49 +109,49 @@ file orders.js
|
|
|
110
109
|
]
|
|
111
110
|
```
|
|
112
111
|
|
|
113
|
-
Return the entire content of the file
|
|
112
|
+
**Return the entire content of the file**:
|
|
114
113
|
|
|
115
114
|
```sh
|
|
116
115
|
jexp '.' ./data/orders.json
|
|
117
116
|
```
|
|
118
117
|
|
|
119
|
-
Result
|
|
118
|
+
*Result*:
|
|
120
119
|
|
|
121
120
|
```json
|
|
122
121
|
[{"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}]}]
|
|
123
122
|
```
|
|
124
123
|
|
|
125
|
-
Returns the number property of the list
|
|
124
|
+
**Returns the number property of the list**:
|
|
126
125
|
|
|
127
126
|
```sh
|
|
128
127
|
jexp '.number' ./data/orders.json
|
|
129
128
|
```
|
|
130
129
|
|
|
131
|
-
Result
|
|
130
|
+
*Result*:
|
|
132
131
|
|
|
133
132
|
```json
|
|
134
133
|
["20001","20002"]
|
|
135
134
|
```
|
|
136
135
|
|
|
137
|
-
Concatenates two properties and capitalizes the first one
|
|
136
|
+
**Concatenates two properties and capitalizes the first one**:
|
|
138
137
|
|
|
139
138
|
```sh
|
|
140
139
|
jexp 'concatenate(capitalize(.fruit.name)," ",.fruit.color)' '{"fruit":{"name":"apple","color":"green","price":1.20}}'
|
|
141
140
|
```
|
|
142
141
|
|
|
143
|
-
Result
|
|
142
|
+
*Result*:
|
|
144
143
|
|
|
145
144
|
```json
|
|
146
145
|
"Apple green"
|
|
147
146
|
```
|
|
148
147
|
|
|
149
|
-
Returns the first element of an array from the index in yaml format
|
|
148
|
+
**Returns the first element of an array from the index in yaml format**:
|
|
150
149
|
|
|
151
150
|
```sh
|
|
152
151
|
jexp '.[0]' ./data/orders.json -o yaml
|
|
153
152
|
```
|
|
154
153
|
|
|
155
|
-
Result
|
|
154
|
+
*Result*:
|
|
156
155
|
|
|
157
156
|
```yaml
|
|
158
157
|
number: '20001'
|
|
@@ -173,13 +172,13 @@ details:
|
|
|
173
172
|
|
|
174
173
|
```
|
|
175
174
|
|
|
176
|
-
Returns the details property of the first element in beautiful format
|
|
175
|
+
**Returns the details property of the first element in beautiful format**:
|
|
177
176
|
|
|
178
177
|
```sh
|
|
179
178
|
jexp '.[0].details' ./data/orders.json -b
|
|
180
179
|
```
|
|
181
180
|
|
|
182
|
-
Result
|
|
181
|
+
*Result*:
|
|
183
182
|
|
|
184
183
|
```json
|
|
185
184
|
[
|
|
@@ -201,145 +200,194 @@ Result:
|
|
|
201
200
|
]
|
|
202
201
|
```
|
|
203
202
|
|
|
204
|
-
Returns the details property of the
|
|
203
|
+
**Returns the details property of the first element, as the file is yaml, it returns it in yaml format**:
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
jexp '.[0].details' ./data/orders.yaml
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
*Result*:
|
|
210
|
+
|
|
211
|
+
```yaml
|
|
212
|
+
- article: Pear
|
|
213
|
+
unitPrice: 1.78
|
|
214
|
+
qty: 2
|
|
215
|
+
- article: Banana
|
|
216
|
+
unitPrice: 1.99
|
|
217
|
+
qty: 1
|
|
218
|
+
- article: White grape
|
|
219
|
+
unitPrice: 2.03
|
|
220
|
+
qty: 1
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Returns the details property of the first element, although the file is yaml it forces the output in json format**:
|
|
225
|
+
|
|
226
|
+
```sh
|
|
227
|
+
jexp '.[0].details' ./data/orders.yaml -b -o json
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
*Result*:
|
|
231
|
+
|
|
232
|
+
```json
|
|
233
|
+
[
|
|
234
|
+
{
|
|
235
|
+
"article": "Pear",
|
|
236
|
+
"unitPrice": 1.78,
|
|
237
|
+
"qty": 2
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"article": "Banana",
|
|
241
|
+
"unitPrice": 1.99,
|
|
242
|
+
"qty": 1
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"article": "White grape",
|
|
246
|
+
"unitPrice": 2.03,
|
|
247
|
+
"qty": 1
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Returns the details property of the listing**:
|
|
205
253
|
|
|
206
254
|
```sh
|
|
207
255
|
jexp '.details' ./data/orders.json
|
|
208
256
|
```
|
|
209
257
|
|
|
210
|
-
Result
|
|
258
|
+
*Result*:
|
|
211
259
|
|
|
212
260
|
```json
|
|
213
261
|
[{"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}]
|
|
214
262
|
```
|
|
215
263
|
|
|
216
|
-
Returns the article property of the list of details of each element of the list
|
|
264
|
+
**Returns the article property of the list of details of each element of the list**:
|
|
217
265
|
|
|
218
266
|
```sh
|
|
219
267
|
jexp '.details.article' ./data/orders.json
|
|
220
268
|
```
|
|
221
269
|
|
|
222
|
-
Result
|
|
270
|
+
*Result*:
|
|
223
271
|
|
|
224
272
|
```json
|
|
225
273
|
["Pear","Banana","White grape","Apple","Banana","Pear"]
|
|
226
274
|
```
|
|
227
275
|
|
|
228
|
-
Get the minimum of the total property
|
|
276
|
+
**Get the minimum of the total property**:
|
|
229
277
|
|
|
230
278
|
```sh
|
|
231
279
|
jexp '.min(p=> p.total)' ./data/orders.json
|
|
232
280
|
```
|
|
233
281
|
|
|
234
|
-
Result
|
|
282
|
+
*Result*:
|
|
235
283
|
|
|
236
284
|
```json
|
|
237
285
|
null
|
|
238
286
|
```
|
|
239
287
|
|
|
240
|
-
Get the minimum of the article property from all the details
|
|
288
|
+
**Get the minimum of the article property from all the details**:
|
|
241
289
|
|
|
242
290
|
```sh
|
|
243
291
|
jexp '.details.min(p=> p.article )' ./data/orders.json
|
|
244
292
|
```
|
|
245
293
|
|
|
246
|
-
Result
|
|
294
|
+
*Result*:
|
|
247
295
|
|
|
248
296
|
```json
|
|
249
297
|
"Apple"
|
|
250
298
|
```
|
|
251
299
|
|
|
252
|
-
Get the maximum "unitPrice * p.qty" from all the details
|
|
300
|
+
**Get the maximum "unitPrice * p.qty" from all the details**:
|
|
253
301
|
|
|
254
302
|
```sh
|
|
255
303
|
jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
256
304
|
```
|
|
257
305
|
|
|
258
|
-
Result
|
|
306
|
+
*Result*:
|
|
259
307
|
|
|
260
308
|
```json
|
|
261
309
|
3.98
|
|
262
310
|
```
|
|
263
311
|
|
|
264
|
-
Get the middle value "unitPrice * p.qty" from all the details
|
|
312
|
+
**Get the middle value "unitPrice * p.qty" from all the details**:
|
|
265
313
|
|
|
266
314
|
```sh
|
|
267
315
|
jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
268
316
|
```
|
|
269
317
|
|
|
270
|
-
Result
|
|
318
|
+
*Result*:
|
|
271
319
|
|
|
272
320
|
```json
|
|
273
321
|
2.5816666666666666
|
|
274
322
|
```
|
|
275
323
|
|
|
276
|
-
Gets the sum of the total property
|
|
324
|
+
**Gets the sum of the total property**:
|
|
277
325
|
|
|
278
326
|
```sh
|
|
279
327
|
jexp '.sum(p=> p.total )' ./data/orders.json
|
|
280
328
|
```
|
|
281
329
|
|
|
282
|
-
Result
|
|
330
|
+
*Result*:
|
|
283
331
|
|
|
284
332
|
```json
|
|
285
333
|
0
|
|
286
334
|
```
|
|
287
335
|
|
|
288
|
-
Get the sum "unitPrice * p.qty" of the details of item 1 of the list
|
|
336
|
+
**Get the sum "unitPrice * p.qty" of the details of item 1 of the list**:
|
|
289
337
|
|
|
290
338
|
```sh
|
|
291
339
|
jexp '.[1].details.sum(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
292
340
|
```
|
|
293
341
|
|
|
294
|
-
Result
|
|
342
|
+
*Result*:
|
|
295
343
|
|
|
296
344
|
```json
|
|
297
345
|
7.91
|
|
298
346
|
```
|
|
299
347
|
|
|
300
|
-
Get the number of details where "unitPrice * p.qty " is less than 3
|
|
348
|
+
**Get the number of details where "unitPrice * p.qty " is less than 3**:
|
|
301
349
|
|
|
302
350
|
```sh
|
|
303
351
|
jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
304
352
|
```
|
|
305
353
|
|
|
306
|
-
Result
|
|
354
|
+
*Result*:
|
|
307
355
|
|
|
308
356
|
```json
|
|
309
357
|
4
|
|
310
358
|
```
|
|
311
359
|
|
|
312
|
-
Get the first article property of all details where "unitPrice * p.qty" is less than 3
|
|
360
|
+
**Get the first article property of all details where "unitPrice * p.qty" is less than 3**:
|
|
313
361
|
|
|
314
362
|
```sh
|
|
315
363
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
316
364
|
```
|
|
317
365
|
|
|
318
|
-
Result
|
|
366
|
+
*Result*:
|
|
319
367
|
|
|
320
368
|
```json
|
|
321
369
|
"Banana"
|
|
322
370
|
```
|
|
323
371
|
|
|
324
|
-
Get the last article property of all details where "unitPrice * p.qty" is less than 3
|
|
372
|
+
**Get the last article property of all details where "unitPrice * p.qty" is less than 3**:
|
|
325
373
|
|
|
326
374
|
```sh
|
|
327
375
|
jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
328
376
|
```
|
|
329
377
|
|
|
330
|
-
Result
|
|
378
|
+
*Result*:
|
|
331
379
|
|
|
332
380
|
```json
|
|
333
381
|
"Pear"
|
|
334
382
|
```
|
|
335
383
|
|
|
336
|
-
Get the first detail where "unitPrice * p.qty" is less than 3 in beautiful format
|
|
384
|
+
**Get the first detail where "unitPrice * p.qty" is less than 3 in beautiful format**:
|
|
337
385
|
|
|
338
386
|
```sh
|
|
339
387
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json -b
|
|
340
388
|
```
|
|
341
389
|
|
|
342
|
-
Result
|
|
390
|
+
*Result*:
|
|
343
391
|
|
|
344
392
|
```json
|
|
345
393
|
{
|
|
@@ -349,215 +397,245 @@ Result:
|
|
|
349
397
|
}
|
|
350
398
|
```
|
|
351
399
|
|
|
352
|
-
Get the sum "unitPrice * p.qty" of the details of item 1 of the list using pipeline
|
|
400
|
+
**Get the sum "unitPrice * p.qty" of the details of item 1 of the list using pipeline**:
|
|
353
401
|
|
|
354
402
|
```sh
|
|
355
403
|
curl -s https://raw.githubusercontent.com/FlavioLionelRita/jexp/main/data/orders.json | jexp '.details.sum(p=> p.unitPrice * p.qty )'
|
|
356
404
|
```
|
|
357
405
|
|
|
358
|
-
Result
|
|
406
|
+
*Result*:
|
|
359
407
|
|
|
360
408
|
```json
|
|
361
|
-
|
|
409
|
+
15.49
|
|
362
410
|
```
|
|
363
411
|
|
|
364
|
-
Get the smallest article
|
|
412
|
+
**Get the smallest article**:
|
|
365
413
|
|
|
366
414
|
```sh
|
|
367
415
|
jexp '.details.min(p=> p.article )' ./data/orders.json
|
|
368
416
|
```
|
|
369
417
|
|
|
370
|
-
Result
|
|
418
|
+
*Result*:
|
|
371
419
|
|
|
372
420
|
```json
|
|
373
421
|
"Apple"
|
|
374
422
|
```
|
|
375
423
|
|
|
376
|
-
Get the total of all the details
|
|
424
|
+
**Get the total of all the details**:
|
|
377
425
|
|
|
378
426
|
```sh
|
|
379
427
|
jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
380
428
|
```
|
|
381
429
|
|
|
382
|
-
Result
|
|
430
|
+
*Result*:
|
|
383
431
|
|
|
384
432
|
```json
|
|
385
433
|
3.98
|
|
386
434
|
```
|
|
387
435
|
|
|
388
|
-
Get the mean value of all details
|
|
436
|
+
**Get the mean value of all details**:
|
|
389
437
|
|
|
390
438
|
```sh
|
|
391
439
|
jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
392
440
|
```
|
|
393
441
|
|
|
394
|
-
Result
|
|
442
|
+
*Result*:
|
|
395
443
|
|
|
396
444
|
```json
|
|
397
445
|
2.5816666666666666
|
|
398
446
|
```
|
|
399
447
|
|
|
400
|
-
Get the total of the details of order 1
|
|
448
|
+
**Get the total of the details of order 1**:
|
|
401
449
|
|
|
402
450
|
```sh
|
|
403
|
-
jexp '[1].details.sum(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
451
|
+
jexp '.[1].details.sum(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
404
452
|
```
|
|
405
453
|
|
|
406
|
-
Result
|
|
454
|
+
*Result*:
|
|
407
455
|
|
|
408
456
|
```json
|
|
409
|
-
|
|
457
|
+
7.91
|
|
410
458
|
```
|
|
411
459
|
|
|
412
|
-
Gets the number of details where the subtotal is less than 3
|
|
460
|
+
**Gets the number of details where the subtotal is less than 3**:
|
|
413
461
|
|
|
414
462
|
```sh
|
|
415
463
|
jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
416
464
|
```
|
|
417
465
|
|
|
418
|
-
Result
|
|
466
|
+
*Result*:
|
|
419
467
|
|
|
420
468
|
```json
|
|
421
469
|
4
|
|
422
470
|
```
|
|
423
471
|
|
|
424
|
-
Get the article of the first detail where the subtotal is less than 3
|
|
472
|
+
**Get the article of the first detail where the subtotal is less than 3**:
|
|
425
473
|
|
|
426
474
|
```sh
|
|
427
475
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
428
476
|
```
|
|
429
477
|
|
|
430
|
-
Result
|
|
478
|
+
*Result*:
|
|
431
479
|
|
|
432
480
|
```json
|
|
433
481
|
"Banana"
|
|
434
482
|
```
|
|
435
483
|
|
|
436
|
-
Get the article of the last detail where the subtotal is less than 3
|
|
484
|
+
**Get the article of the last detail where the subtotal is less than 3**:
|
|
437
485
|
|
|
438
486
|
```sh
|
|
439
|
-
jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article
|
|
487
|
+
jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
440
488
|
```
|
|
441
489
|
|
|
442
|
-
Result
|
|
490
|
+
*Result*:
|
|
443
491
|
|
|
444
492
|
```json
|
|
445
|
-
|
|
493
|
+
"Pear"
|
|
446
494
|
```
|
|
447
495
|
|
|
448
|
-
Get the first detail where the subtotal is less than 3
|
|
496
|
+
**Get the first detail where the subtotal is less than 3**:
|
|
449
497
|
|
|
450
498
|
```sh
|
|
451
499
|
jexp '.details.first(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
452
500
|
```
|
|
453
501
|
|
|
454
|
-
Result
|
|
502
|
+
*Result*:
|
|
455
503
|
|
|
456
504
|
```json
|
|
457
505
|
{"article":"Banana","unitPrice":1.99,"qty":1}
|
|
458
506
|
```
|
|
459
507
|
|
|
460
|
-
Calculate the total for each order
|
|
508
|
+
**Calculate the total for each order**:
|
|
461
509
|
|
|
462
510
|
```sh
|
|
463
511
|
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
512
|
```
|
|
465
513
|
|
|
466
|
-
Result
|
|
514
|
+
*Result*:
|
|
467
515
|
|
|
468
516
|
```json
|
|
469
517
|
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
|
|
470
518
|
```
|
|
471
519
|
|
|
472
|
-
Calculate the subtotal for each order
|
|
520
|
+
**Calculate the subtotal for each order**:
|
|
473
521
|
|
|
474
522
|
```sh
|
|
475
523
|
jexp '.details.foreach(p=>p.subtotal=p.qty*p.unitPrice).subtotal' ./data/orders.json
|
|
476
524
|
```
|
|
477
525
|
|
|
478
|
-
Result
|
|
526
|
+
*Result*:
|
|
479
527
|
|
|
480
528
|
```json
|
|
481
529
|
[3.56,1.99,2.03,2.15,3.98,1.78]
|
|
482
530
|
```
|
|
483
531
|
|
|
484
|
-
calculates the total of all the details
|
|
532
|
+
**calculates the total of all the details**:
|
|
485
533
|
|
|
486
534
|
```sh
|
|
487
535
|
jexp '.details.foreach(p=>total=nvl(total,0)+p.qty*p.unitPrice);total' ./data/orders.json
|
|
488
536
|
```
|
|
489
537
|
|
|
490
|
-
Result
|
|
538
|
+
*Result*:
|
|
491
539
|
|
|
492
540
|
```json
|
|
493
541
|
15.49
|
|
494
542
|
```
|
|
495
543
|
|
|
496
|
-
Get the list of items without repeating
|
|
544
|
+
**Get the list of items without repeating**:
|
|
497
545
|
|
|
498
546
|
```sh
|
|
499
|
-
jexp '.details.distinct(p=>p.article)' ./data/orders.json
|
|
547
|
+
jexp '.details.distinct(p=>p.article)' ./data/orders.json -b
|
|
500
548
|
```
|
|
501
549
|
|
|
502
|
-
Result
|
|
550
|
+
*Result*:
|
|
503
551
|
|
|
504
552
|
```json
|
|
505
|
-
[
|
|
553
|
+
[
|
|
554
|
+
"Pear",
|
|
555
|
+
"Banana",
|
|
556
|
+
"White grape",
|
|
557
|
+
"Apple"
|
|
558
|
+
]
|
|
506
559
|
```
|
|
507
560
|
|
|
508
|
-
Get the list of items and quantity without repeating
|
|
561
|
+
**Get the list of items and quantity without repeating**:
|
|
509
562
|
|
|
510
563
|
```sh
|
|
511
|
-
jexp '.details.distinct(p=>{article:p.article,qty:p.qty})' ./data/orders.json
|
|
564
|
+
jexp '.details.distinct(p=>{article:p.article,qty:p.qty}) -b' ./data/orders.json
|
|
512
565
|
```
|
|
513
566
|
|
|
514
|
-
Result
|
|
567
|
+
*Result*:
|
|
515
568
|
|
|
516
569
|
```json
|
|
517
|
-
|
|
570
|
+
null
|
|
518
571
|
```
|
|
519
572
|
|
|
573
|
+
**Get the total and amount of each item**:
|
|
574
|
+
|
|
520
575
|
```sh
|
|
521
|
-
jexp '.details.map(p=>{article:p.article,count:count(1),total:sum(p.qty * p.unitPrice)})' ./data/orders.json
|
|
576
|
+
jexp '.details.map(p=>{article:p.article,count:count(1),total:sum(p.qty * p.unitPrice)})' ./data/orders.json -b
|
|
522
577
|
```
|
|
523
578
|
|
|
524
|
-
Result
|
|
579
|
+
*Result*:
|
|
525
580
|
|
|
526
581
|
```json
|
|
527
|
-
[
|
|
582
|
+
[
|
|
583
|
+
{
|
|
584
|
+
"article": "Pear",
|
|
585
|
+
"count": 2,
|
|
586
|
+
"total": 5.34
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
"article": "Banana",
|
|
590
|
+
"count": 2,
|
|
591
|
+
"total": 5.97
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
"article": "White grape",
|
|
595
|
+
"count": 1,
|
|
596
|
+
"total": 2.03
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
"article": "Apple",
|
|
600
|
+
"count": 1,
|
|
601
|
+
"total": 2.15
|
|
602
|
+
}
|
|
603
|
+
]
|
|
528
604
|
```
|
|
529
605
|
|
|
530
|
-
Get the total of the first order
|
|
606
|
+
**Get the total of the first order**:
|
|
531
607
|
|
|
532
608
|
```sh
|
|
533
609
|
jexp '{total:.[0].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json
|
|
534
610
|
```
|
|
535
611
|
|
|
536
|
-
Result
|
|
612
|
+
*Result*:
|
|
537
613
|
|
|
538
614
|
```json
|
|
539
615
|
{"total":7.58}
|
|
540
616
|
```
|
|
541
617
|
|
|
542
|
-
Get the total of the last order
|
|
618
|
+
**Get the total of the last order**:
|
|
543
619
|
|
|
544
620
|
```sh
|
|
545
|
-
jexp '{total:.[.length()-1].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json
|
|
621
|
+
jexp '{total:.[.length()-1].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json -b
|
|
546
622
|
```
|
|
547
623
|
|
|
548
|
-
Result
|
|
624
|
+
*Result*:
|
|
549
625
|
|
|
550
626
|
```json
|
|
551
|
-
{
|
|
627
|
+
{
|
|
628
|
+
"total": 7.91
|
|
629
|
+
}
|
|
552
630
|
```
|
|
553
631
|
|
|
554
|
-
List the orders with their totals
|
|
632
|
+
**List the orders with their totals**:
|
|
555
633
|
|
|
556
634
|
```sh
|
|
557
635
|
jexp '.map(p=>{nro:p.number,total:p.details.sum(q=>q.qty * q.unitPrice)})' ./data/orders.json
|
|
558
636
|
```
|
|
559
637
|
|
|
560
|
-
Result
|
|
638
|
+
*Result*:
|
|
561
639
|
|
|
562
640
|
```json
|
|
563
641
|
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
|
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,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAChD,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAE/B,MAAM,GAAG,GAAG,CAAO,UAAiB,EAAE,MAAa,EAAE,OAAW,EAAE,EAAE;IACnE,IAAI,IAAI,GAAO,EAAE,CAAA;IACjB,IAAI,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AAY,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.7",
|
|
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",
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"commander": "^9.4.0",
|
|
21
21
|
"js-expressions": "1.0.11",
|
|
22
|
-
"js-yaml": "^4.1.0"
|
|
23
|
-
"json-colorizer": "^2.2.2"
|
|
22
|
+
"js-yaml": "^4.1.0"
|
|
24
23
|
},
|
|
25
24
|
"keywords": [
|
|
26
25
|
"cli",
|