jexp 0.1.1 → 0.1.2
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
|
@@ -85,28 +85,26 @@ file orders.js
|
|
|
85
85
|
|
|
86
86
|
```json
|
|
87
87
|
[
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
]
|
|
109
|
-
}
|
|
88
|
+
{
|
|
89
|
+
"number": "20001",
|
|
90
|
+
"customer": { "firstName": "John", "lastName": "Murphy" },
|
|
91
|
+
"orderTime": "2022-07-30T10:15:54",
|
|
92
|
+
"details": [
|
|
93
|
+
{ "article": "Pear", "unitPrice": 1.78, "qty": 2 },
|
|
94
|
+
{ "article": "Banana", "unitPrice": 1.99, "qty": 1 },
|
|
95
|
+
{ "article": "White grape", "unitPrice": 2.03, "qty": 1 }
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"number": "20002",
|
|
100
|
+
"customer": { "firstName": "Paul", "lastName": "Smith" },
|
|
101
|
+
"orderTime": "2022-07-30T12:12:43",
|
|
102
|
+
"details": [
|
|
103
|
+
{ "article": "Apple", "unitPrice": 2.15, "qty": 1 },
|
|
104
|
+
{ "article": "Banana", "unitPrice": 1.99, "qty": 2 },
|
|
105
|
+
{ "article": "Pear", "unitPrice": 1.78, "qty": 1 }
|
|
106
|
+
]
|
|
107
|
+
}
|
|
110
108
|
]
|
|
111
109
|
```
|
|
112
110
|
|
|
@@ -119,7 +117,7 @@ jexp '.' ./data/orders.json
|
|
|
119
117
|
Result:
|
|
120
118
|
|
|
121
119
|
```json
|
|
122
|
-
[{"number":"20001","customer":{"firstName":"John","lastName":"Murphy"},"orderTime":"2022-07-30T10:15:54","
|
|
120
|
+
[{"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
121
|
```
|
|
124
122
|
|
|
125
123
|
Returns the number property of the list
|
|
@@ -154,23 +152,23 @@ jexp '.[0]' ./data/orders.json -o yaml
|
|
|
154
152
|
|
|
155
153
|
Result:
|
|
156
154
|
|
|
157
|
-
```
|
|
155
|
+
```json
|
|
158
156
|
number: '20001'
|
|
159
157
|
customer:
|
|
160
158
|
firstName: John
|
|
161
159
|
lastName: Murphy
|
|
162
160
|
orderTime: '2022-07-30T10:15:54'
|
|
163
|
-
total: 12.19
|
|
164
161
|
details:
|
|
165
|
-
- article:
|
|
166
|
-
unitPrice: 1.
|
|
167
|
-
qty: 5
|
|
168
|
-
- article: Onion
|
|
169
|
-
unitPrice: 1.23
|
|
162
|
+
- article: Pear
|
|
163
|
+
unitPrice: 1.78
|
|
170
164
|
qty: 2
|
|
165
|
+
- article: Banana
|
|
166
|
+
unitPrice: 1.99
|
|
167
|
+
qty: 1
|
|
171
168
|
- article: White grape
|
|
172
169
|
unitPrice: 2.03
|
|
173
170
|
qty: 1
|
|
171
|
+
|
|
174
172
|
```
|
|
175
173
|
|
|
176
174
|
Returns the details property of the first element in beautiful format
|
|
@@ -184,14 +182,14 @@ Result:
|
|
|
184
182
|
```json
|
|
185
183
|
[
|
|
186
184
|
{
|
|
187
|
-
"article": "
|
|
188
|
-
"unitPrice": 1.
|
|
189
|
-
"qty":
|
|
185
|
+
"article": "Pear",
|
|
186
|
+
"unitPrice": 1.78,
|
|
187
|
+
"qty": 2
|
|
190
188
|
},
|
|
191
189
|
{
|
|
192
|
-
"article": "
|
|
193
|
-
"unitPrice": 1.
|
|
194
|
-
"qty":
|
|
190
|
+
"article": "Banana",
|
|
191
|
+
"unitPrice": 1.99,
|
|
192
|
+
"qty": 1
|
|
195
193
|
},
|
|
196
194
|
{
|
|
197
195
|
"article": "White grape",
|
|
@@ -210,7 +208,7 @@ jexp '.details' ./data/orders.json
|
|
|
210
208
|
Result:
|
|
211
209
|
|
|
212
210
|
```json
|
|
213
|
-
[{"article":"
|
|
211
|
+
[{"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
212
|
```
|
|
215
213
|
|
|
216
214
|
Returns the article property of the list of details of each element of the list
|
|
@@ -222,7 +220,7 @@ jexp '.details.article' ./data/orders.json
|
|
|
222
220
|
Result:
|
|
223
221
|
|
|
224
222
|
```json
|
|
225
|
-
["
|
|
223
|
+
["Pear","Banana","White grape","Apple","Banana","Pear"]
|
|
226
224
|
```
|
|
227
225
|
|
|
228
226
|
Get the minimum of the total property
|
|
@@ -234,7 +232,7 @@ jexp '.min(p=> p.total)' ./data/orders.json
|
|
|
234
232
|
Result:
|
|
235
233
|
|
|
236
234
|
```json
|
|
237
|
-
|
|
235
|
+
null
|
|
238
236
|
```
|
|
239
237
|
|
|
240
238
|
Get the minimum of the article property from all the details
|
|
@@ -258,7 +256,7 @@ jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
|
258
256
|
Result:
|
|
259
257
|
|
|
260
258
|
```json
|
|
261
|
-
|
|
259
|
+
3.98
|
|
262
260
|
```
|
|
263
261
|
|
|
264
262
|
Get the middle value "unitPrice * p.qty" from all the details
|
|
@@ -270,7 +268,7 @@ jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
|
270
268
|
Result:
|
|
271
269
|
|
|
272
270
|
```json
|
|
273
|
-
|
|
271
|
+
2.5816666666666666
|
|
274
272
|
```
|
|
275
273
|
|
|
276
274
|
Gets the sum of the total property
|
|
@@ -282,7 +280,7 @@ jexp '.sum(p=> p.total )' ./data/orders.json
|
|
|
282
280
|
Result:
|
|
283
281
|
|
|
284
282
|
```json
|
|
285
|
-
|
|
283
|
+
0
|
|
286
284
|
```
|
|
287
285
|
|
|
288
286
|
Get the sum "unitPrice * p.qty" of the details of item 1 of the list
|
|
@@ -318,7 +316,7 @@ jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
|
318
316
|
Result:
|
|
319
317
|
|
|
320
318
|
```json
|
|
321
|
-
"
|
|
319
|
+
"Banana"
|
|
322
320
|
```
|
|
323
321
|
|
|
324
322
|
Get the last article property of all details where "unitPrice * p.qty" is less than 3
|
|
@@ -343,9 +341,9 @@ Result:
|
|
|
343
341
|
|
|
344
342
|
```json
|
|
345
343
|
{
|
|
346
|
-
"article": "
|
|
347
|
-
"unitPrice": 1.
|
|
348
|
-
"qty":
|
|
344
|
+
"article": "Banana",
|
|
345
|
+
"unitPrice": 1.99,
|
|
346
|
+
"qty": 1
|
|
349
347
|
}
|
|
350
348
|
```
|
|
351
349
|
|
|
@@ -361,6 +359,210 @@ Result:
|
|
|
361
359
|
20.1
|
|
362
360
|
```
|
|
363
361
|
|
|
362
|
+
Get the smallest article
|
|
363
|
+
|
|
364
|
+
```sh
|
|
365
|
+
jexp '.details.min(p=> p.article )' ./data/orders.json
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Result:
|
|
369
|
+
|
|
370
|
+
```json
|
|
371
|
+
"Apple"
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Get the total of all the details
|
|
375
|
+
|
|
376
|
+
```sh
|
|
377
|
+
jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Result:
|
|
381
|
+
|
|
382
|
+
```json
|
|
383
|
+
3.98
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Get the mean value of all details
|
|
387
|
+
|
|
388
|
+
```sh
|
|
389
|
+
jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Result:
|
|
393
|
+
|
|
394
|
+
```json
|
|
395
|
+
2.5816666666666666
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Get the total of the details of order 1
|
|
399
|
+
|
|
400
|
+
```sh
|
|
401
|
+
jexp '[1].details.sum(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
Result:
|
|
405
|
+
|
|
406
|
+
```json
|
|
407
|
+
0
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Gets the number of details where the subtotal is less than 3
|
|
411
|
+
|
|
412
|
+
```sh
|
|
413
|
+
jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
Result:
|
|
417
|
+
|
|
418
|
+
```json
|
|
419
|
+
4
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
Get the article of the first detail where the subtotal is less than 3
|
|
423
|
+
|
|
424
|
+
```sh
|
|
425
|
+
jexp '.details.first(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Result:
|
|
429
|
+
|
|
430
|
+
```json
|
|
431
|
+
"Banana"
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Get the article of the last detail where the subtotal is less than 3
|
|
435
|
+
|
|
436
|
+
```sh
|
|
437
|
+
jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
Result:
|
|
441
|
+
|
|
442
|
+
```json
|
|
443
|
+
/bin/sh: 1: Syntax error: Unterminated quoted string
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
Get the first detail where the subtotal is less than 3
|
|
447
|
+
|
|
448
|
+
```sh
|
|
449
|
+
jexp '.details.first(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Result:
|
|
453
|
+
|
|
454
|
+
```json
|
|
455
|
+
{"article":"Banana","unitPrice":1.99,"qty":1}
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Calculate the total for each order
|
|
459
|
+
|
|
460
|
+
```sh
|
|
461
|
+
jexp '.each(p=>p.total=p.details.sum(q=>q.qty*q.unitPrice)).map(p=>{nro:p.number,total:p.total})' ./data/orders.json
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
Result:
|
|
465
|
+
|
|
466
|
+
```json
|
|
467
|
+
[{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
Calculate the subtotal for each order
|
|
471
|
+
|
|
472
|
+
```sh
|
|
473
|
+
jexp '.details.foreach(p=>p.subtotal=p.qty*p.unitPrice).subtotal' ./data/orders.json
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
Result:
|
|
477
|
+
|
|
478
|
+
```json
|
|
479
|
+
[3.56,1.99,2.03,2.15,3.98,1.78]
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
calculates the total of all the details
|
|
483
|
+
|
|
484
|
+
```sh
|
|
485
|
+
jexp '.details.foreach(p=>total=nvl(total,0)+p.qty*p.unitPrice);total' ./data/orders.json
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
Result:
|
|
489
|
+
|
|
490
|
+
```json
|
|
491
|
+
15.49
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
Get the list of items without repeating
|
|
495
|
+
|
|
496
|
+
```sh
|
|
497
|
+
jexp '.details.distinct(p=>p.article)' ./data/orders.json
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
Result:
|
|
501
|
+
|
|
502
|
+
```json
|
|
503
|
+
["Pear","Banana","White grape","Apple"]
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
Get the list of items and quantity without repeating
|
|
507
|
+
|
|
508
|
+
```sh
|
|
509
|
+
jexp '.details.distinct(p=>{article:p.article,qty:p.qty})' ./data/orders.json
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
Result:
|
|
513
|
+
|
|
514
|
+
```json
|
|
515
|
+
[{"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}]
|
|
516
|
+
```
|
|
517
|
+
|
|
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.2",
|
|
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",
|