jexp 0.1.1 → 0.1.4
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 +248 -46
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,10 +4,12 @@ Command line application that allows parser and evaluator of json/yaml applying
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- Functions and arrow functions
|
|
8
7
|
- Constants, enums, variables, objects and arrays
|
|
9
8
|
- Arithmetic, assignment, comparison, Logical and bitwise operators
|
|
9
|
+
- Functions and arrow functions
|
|
10
|
+
- distinct and group by
|
|
10
11
|
- Environment variables
|
|
12
|
+
- json and yaml
|
|
11
13
|
|
|
12
14
|
## Global installation
|
|
13
15
|
|
|
@@ -85,28 +87,26 @@ file orders.js
|
|
|
85
87
|
|
|
86
88
|
```json
|
|
87
89
|
[
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
]
|
|
109
|
-
}
|
|
90
|
+
{
|
|
91
|
+
"number": "20001",
|
|
92
|
+
"customer": { "firstName": "John", "lastName": "Murphy" },
|
|
93
|
+
"orderTime": "2022-07-30T10:15:54",
|
|
94
|
+
"details": [
|
|
95
|
+
{ "article": "Pear", "unitPrice": 1.78, "qty": 2 },
|
|
96
|
+
{ "article": "Banana", "unitPrice": 1.99, "qty": 1 },
|
|
97
|
+
{ "article": "White grape", "unitPrice": 2.03, "qty": 1 }
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"number": "20002",
|
|
102
|
+
"customer": { "firstName": "Paul", "lastName": "Smith" },
|
|
103
|
+
"orderTime": "2022-07-30T12:12:43",
|
|
104
|
+
"details": [
|
|
105
|
+
{ "article": "Apple", "unitPrice": 2.15, "qty": 1 },
|
|
106
|
+
{ "article": "Banana", "unitPrice": 1.99, "qty": 2 },
|
|
107
|
+
{ "article": "Pear", "unitPrice": 1.78, "qty": 1 }
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
110
|
]
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -119,7 +119,7 @@ jexp '.' ./data/orders.json
|
|
|
119
119
|
Result:
|
|
120
120
|
|
|
121
121
|
```json
|
|
122
|
-
[{"number":"20001","customer":{"firstName":"John","lastName":"Murphy"},"orderTime":"2022-07-30T10:15:54","
|
|
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}]}]
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
Returns the number property of the list
|
|
@@ -160,17 +160,17 @@ customer:
|
|
|
160
160
|
firstName: John
|
|
161
161
|
lastName: Murphy
|
|
162
162
|
orderTime: '2022-07-30T10:15:54'
|
|
163
|
-
total: 12.19
|
|
164
163
|
details:
|
|
165
|
-
- article:
|
|
166
|
-
unitPrice: 1.
|
|
167
|
-
qty: 5
|
|
168
|
-
- article: Onion
|
|
169
|
-
unitPrice: 1.23
|
|
164
|
+
- article: Pear
|
|
165
|
+
unitPrice: 1.78
|
|
170
166
|
qty: 2
|
|
167
|
+
- article: Banana
|
|
168
|
+
unitPrice: 1.99
|
|
169
|
+
qty: 1
|
|
171
170
|
- article: White grape
|
|
172
171
|
unitPrice: 2.03
|
|
173
172
|
qty: 1
|
|
173
|
+
|
|
174
174
|
```
|
|
175
175
|
|
|
176
176
|
Returns the details property of the first element in beautiful format
|
|
@@ -184,14 +184,14 @@ Result:
|
|
|
184
184
|
```json
|
|
185
185
|
[
|
|
186
186
|
{
|
|
187
|
-
"article": "
|
|
188
|
-
"unitPrice": 1.
|
|
189
|
-
"qty":
|
|
187
|
+
"article": "Pear",
|
|
188
|
+
"unitPrice": 1.78,
|
|
189
|
+
"qty": 2
|
|
190
190
|
},
|
|
191
191
|
{
|
|
192
|
-
"article": "
|
|
193
|
-
"unitPrice": 1.
|
|
194
|
-
"qty":
|
|
192
|
+
"article": "Banana",
|
|
193
|
+
"unitPrice": 1.99,
|
|
194
|
+
"qty": 1
|
|
195
195
|
},
|
|
196
196
|
{
|
|
197
197
|
"article": "White grape",
|
|
@@ -210,7 +210,7 @@ jexp '.details' ./data/orders.json
|
|
|
210
210
|
Result:
|
|
211
211
|
|
|
212
212
|
```json
|
|
213
|
-
[{"article":"
|
|
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}]
|
|
214
214
|
```
|
|
215
215
|
|
|
216
216
|
Returns the article property of the list of details of each element of the list
|
|
@@ -222,7 +222,7 @@ jexp '.details.article' ./data/orders.json
|
|
|
222
222
|
Result:
|
|
223
223
|
|
|
224
224
|
```json
|
|
225
|
-
["
|
|
225
|
+
["Pear","Banana","White grape","Apple","Banana","Pear"]
|
|
226
226
|
```
|
|
227
227
|
|
|
228
228
|
Get the minimum of the total property
|
|
@@ -234,7 +234,7 @@ jexp '.min(p=> p.total)' ./data/orders.json
|
|
|
234
234
|
Result:
|
|
235
235
|
|
|
236
236
|
```json
|
|
237
|
-
|
|
237
|
+
null
|
|
238
238
|
```
|
|
239
239
|
|
|
240
240
|
Get the minimum of the article property from all the details
|
|
@@ -258,7 +258,7 @@ jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
|
258
258
|
Result:
|
|
259
259
|
|
|
260
260
|
```json
|
|
261
|
-
|
|
261
|
+
3.98
|
|
262
262
|
```
|
|
263
263
|
|
|
264
264
|
Get the middle value "unitPrice * p.qty" from all the details
|
|
@@ -270,7 +270,7 @@ jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
|
270
270
|
Result:
|
|
271
271
|
|
|
272
272
|
```json
|
|
273
|
-
|
|
273
|
+
2.5816666666666666
|
|
274
274
|
```
|
|
275
275
|
|
|
276
276
|
Gets the sum of the total property
|
|
@@ -282,7 +282,7 @@ jexp '.sum(p=> p.total )' ./data/orders.json
|
|
|
282
282
|
Result:
|
|
283
283
|
|
|
284
284
|
```json
|
|
285
|
-
|
|
285
|
+
0
|
|
286
286
|
```
|
|
287
287
|
|
|
288
288
|
Get the sum "unitPrice * p.qty" of the details of item 1 of the list
|
|
@@ -318,7 +318,7 @@ jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
|
318
318
|
Result:
|
|
319
319
|
|
|
320
320
|
```json
|
|
321
|
-
"
|
|
321
|
+
"Banana"
|
|
322
322
|
```
|
|
323
323
|
|
|
324
324
|
Get the last article property of all details where "unitPrice * p.qty" is less than 3
|
|
@@ -343,9 +343,9 @@ Result:
|
|
|
343
343
|
|
|
344
344
|
```json
|
|
345
345
|
{
|
|
346
|
-
"article": "
|
|
347
|
-
"unitPrice": 1.
|
|
348
|
-
"qty":
|
|
346
|
+
"article": "Banana",
|
|
347
|
+
"unitPrice": 1.99,
|
|
348
|
+
"qty": 1
|
|
349
349
|
}
|
|
350
350
|
```
|
|
351
351
|
|
|
@@ -361,6 +361,208 @@ Result:
|
|
|
361
361
|
20.1
|
|
362
362
|
```
|
|
363
363
|
|
|
364
|
+
Get the smallest article
|
|
365
|
+
|
|
366
|
+
```sh
|
|
367
|
+
jexp '.details.min(p=> p.article )' ./data/orders.json
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Result:
|
|
371
|
+
|
|
372
|
+
```json
|
|
373
|
+
"Apple"
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Get the total of all the details
|
|
377
|
+
|
|
378
|
+
```sh
|
|
379
|
+
jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Result:
|
|
383
|
+
|
|
384
|
+
```json
|
|
385
|
+
3.98
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Get the mean value of all details
|
|
389
|
+
|
|
390
|
+
```sh
|
|
391
|
+
jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Result:
|
|
395
|
+
|
|
396
|
+
```json
|
|
397
|
+
2.5816666666666666
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Get the total of the details of order 1
|
|
401
|
+
|
|
402
|
+
```sh
|
|
403
|
+
jexp '[1].details.sum(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
Result:
|
|
407
|
+
|
|
408
|
+
```json
|
|
409
|
+
0
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
Gets the number of details where the subtotal is less than 3
|
|
413
|
+
|
|
414
|
+
```sh
|
|
415
|
+
jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Result:
|
|
419
|
+
|
|
420
|
+
```json
|
|
421
|
+
4
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Get the article of the first detail where the subtotal is less than 3
|
|
425
|
+
|
|
426
|
+
```sh
|
|
427
|
+
jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Result:
|
|
431
|
+
|
|
432
|
+
```json
|
|
433
|
+
"Banana"
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
Get the article of the last detail where the subtotal is less than 3
|
|
437
|
+
|
|
438
|
+
```sh
|
|
439
|
+
jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Result:
|
|
443
|
+
|
|
444
|
+
```json
|
|
445
|
+
/bin/sh: 1: Syntax error: Unterminated quoted string
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Get the first detail where the subtotal is less than 3
|
|
449
|
+
|
|
450
|
+
```sh
|
|
451
|
+
jexp '.details.first(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Result:
|
|
455
|
+
|
|
456
|
+
```json
|
|
457
|
+
{"article":"Banana","unitPrice":1.99,"qty":1}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
Calculate the total for each order
|
|
461
|
+
|
|
462
|
+
```sh
|
|
463
|
+
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
|
+
```
|
|
465
|
+
|
|
466
|
+
Result:
|
|
467
|
+
|
|
468
|
+
```json
|
|
469
|
+
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
Calculate the subtotal for each order
|
|
473
|
+
|
|
474
|
+
```sh
|
|
475
|
+
jexp '.details.foreach(p=>p.subtotal=p.qty*p.unitPrice).subtotal' ./data/orders.json
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
Result:
|
|
479
|
+
|
|
480
|
+
```json
|
|
481
|
+
[3.56,1.99,2.03,2.15,3.98,1.78]
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
calculates the total of all the details
|
|
485
|
+
|
|
486
|
+
```sh
|
|
487
|
+
jexp '.details.foreach(p=>total=nvl(total,0)+p.qty*p.unitPrice);total' ./data/orders.json
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Result:
|
|
491
|
+
|
|
492
|
+
```json
|
|
493
|
+
15.49
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Get the list of items without repeating
|
|
497
|
+
|
|
498
|
+
```sh
|
|
499
|
+
jexp '.details.distinct(p=>p.article)' ./data/orders.json
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
Result:
|
|
503
|
+
|
|
504
|
+
```json
|
|
505
|
+
["Pear","Banana","White grape","Apple"]
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
Get the list of items and quantity without repeating
|
|
509
|
+
|
|
510
|
+
```sh
|
|
511
|
+
jexp '.details.distinct(p=>{article:p.article,qty:p.qty})' ./data/orders.json
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
Result:
|
|
515
|
+
|
|
516
|
+
```json
|
|
517
|
+
[{"article":"Pear","qty":2},{"article":"Banana","qty":1},{"article":"White grape","qty":1},{"article":"Apple","qty":1},{"article":"Banana","qty":2},{"article":"Pear","qty":1}]
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
```sh
|
|
521
|
+
jexp '.details.map(p=>{article:p.article,count:count(1),total:sum(p.qty * p.unitPrice)})' ./data/orders.json
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
Result:
|
|
525
|
+
|
|
526
|
+
```json
|
|
527
|
+
[{"article":"Pear","count":2,"total":5.34},{"article":"Banana","count":2,"total":5.97},{"article":"White grape","count":1,"total":2.03},{"article":"Apple","count":1,"total":2.15}]
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
Get the total of the first order
|
|
531
|
+
|
|
532
|
+
```sh
|
|
533
|
+
jexp '{total:.[0].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Result:
|
|
537
|
+
|
|
538
|
+
```json
|
|
539
|
+
{"total":7.58}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
Get the total of the last order
|
|
543
|
+
|
|
544
|
+
```sh
|
|
545
|
+
jexp '{total:.[.length()-1].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
Result:
|
|
549
|
+
|
|
550
|
+
```json
|
|
551
|
+
{"total":7.91}
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
List the orders with their totals
|
|
555
|
+
|
|
556
|
+
```sh
|
|
557
|
+
jexp '.map(p=>{nro:p.number,total:p.details.sum(q=>q.qty * q.unitPrice)})' ./data/orders.json
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
Result:
|
|
561
|
+
|
|
562
|
+
```json
|
|
563
|
+
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
|
|
564
|
+
```
|
|
565
|
+
|
|
364
566
|
## js-expression
|
|
365
567
|
|
|
366
568
|
[Js-expression](https://www.npmjs.com/package/js-expressions) is an extensible expression evaluator and parser. \
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jexp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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",
|