jexp 0.1.7 → 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 +61 -42
- package/package.json +2 -2
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
|
|
@@ -105,6 +107,17 @@ file orders.js
|
|
|
105
107
|
{ "article": "Banana", "unitPrice": 1.99, "qty": 2 },
|
|
106
108
|
{ "article": "Pear", "unitPrice": 1.78, "qty": 1 }
|
|
107
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
|
+
]
|
|
108
121
|
}
|
|
109
122
|
]
|
|
110
123
|
```
|
|
@@ -118,7 +131,7 @@ jexp '.' ./data/orders.json
|
|
|
118
131
|
*Result*:
|
|
119
132
|
|
|
120
133
|
```json
|
|
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}]}]
|
|
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}]}]
|
|
122
135
|
```
|
|
123
136
|
|
|
124
137
|
**Returns the number property of the list**:
|
|
@@ -130,7 +143,7 @@ jexp '.number' ./data/orders.json
|
|
|
130
143
|
*Result*:
|
|
131
144
|
|
|
132
145
|
```json
|
|
133
|
-
["20001","20002"]
|
|
146
|
+
["20001","20002","20003"]
|
|
134
147
|
```
|
|
135
148
|
|
|
136
149
|
**Concatenates two properties and capitalizes the first one**:
|
|
@@ -258,7 +271,7 @@ jexp '.details' ./data/orders.json
|
|
|
258
271
|
*Result*:
|
|
259
272
|
|
|
260
273
|
```json
|
|
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}]
|
|
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}]
|
|
262
275
|
```
|
|
263
276
|
|
|
264
277
|
**Returns the article property of the list of details of each element of the list**:
|
|
@@ -270,7 +283,7 @@ jexp '.details.article' ./data/orders.json
|
|
|
270
283
|
*Result*:
|
|
271
284
|
|
|
272
285
|
```json
|
|
273
|
-
["Pear","Banana","White grape","Apple","Banana","Pear"]
|
|
286
|
+
["Pear","Banana","White grape","Apple","Banana","Pear","Apple","Banana","Pear","White grape"]
|
|
274
287
|
```
|
|
275
288
|
|
|
276
289
|
**Get the minimum of the total property**:
|
|
@@ -318,7 +331,7 @@ jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
|
318
331
|
*Result*:
|
|
319
332
|
|
|
320
333
|
```json
|
|
321
|
-
2.
|
|
334
|
+
2.3440000000000003
|
|
322
335
|
```
|
|
323
336
|
|
|
324
337
|
**Gets the sum of the total property**:
|
|
@@ -354,7 +367,7 @@ jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
|
354
367
|
*Result*:
|
|
355
368
|
|
|
356
369
|
```json
|
|
357
|
-
|
|
370
|
+
8
|
|
358
371
|
```
|
|
359
372
|
|
|
360
373
|
**Get the first article property of all details where "unitPrice * p.qty" is less than 3**:
|
|
@@ -378,7 +391,7 @@ jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
|
378
391
|
*Result*:
|
|
379
392
|
|
|
380
393
|
```json
|
|
381
|
-
"
|
|
394
|
+
"White grape"
|
|
382
395
|
```
|
|
383
396
|
|
|
384
397
|
**Get the first detail where "unitPrice * p.qty" is less than 3 in beautiful format**:
|
|
@@ -442,7 +455,7 @@ jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
|
|
|
442
455
|
*Result*:
|
|
443
456
|
|
|
444
457
|
```json
|
|
445
|
-
2.
|
|
458
|
+
2.3440000000000003
|
|
446
459
|
```
|
|
447
460
|
|
|
448
461
|
**Get the total of the details of order 1**:
|
|
@@ -466,7 +479,7 @@ jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
|
|
|
466
479
|
*Result*:
|
|
467
480
|
|
|
468
481
|
```json
|
|
469
|
-
|
|
482
|
+
8
|
|
470
483
|
```
|
|
471
484
|
|
|
472
485
|
**Get the article of the first detail where the subtotal is less than 3**:
|
|
@@ -490,7 +503,7 @@ jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
|
|
|
490
503
|
*Result*:
|
|
491
504
|
|
|
492
505
|
```json
|
|
493
|
-
"
|
|
506
|
+
"White grape"
|
|
494
507
|
```
|
|
495
508
|
|
|
496
509
|
**Get the first detail where the subtotal is less than 3**:
|
|
@@ -514,7 +527,7 @@ jexp '.each(p=>p.total=p.details.sum(q=>q.qty*q.unitPrice)).map(p=>{nro:p.number
|
|
|
514
527
|
*Result*:
|
|
515
528
|
|
|
516
529
|
```json
|
|
517
|
-
[{"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}]
|
|
518
531
|
```
|
|
519
532
|
|
|
520
533
|
**Calculate the subtotal for each order**:
|
|
@@ -526,7 +539,7 @@ jexp '.details.foreach(p=>p.subtotal=p.qty*p.unitPrice).subtotal' ./data/orders.
|
|
|
526
539
|
*Result*:
|
|
527
540
|
|
|
528
541
|
```json
|
|
529
|
-
[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]
|
|
530
543
|
```
|
|
531
544
|
|
|
532
545
|
**calculates the total of all the details**:
|
|
@@ -538,7 +551,7 @@ jexp '.details.foreach(p=>total=nvl(total,0)+p.qty*p.unitPrice);total' ./data/or
|
|
|
538
551
|
*Result*:
|
|
539
552
|
|
|
540
553
|
```json
|
|
541
|
-
|
|
554
|
+
23.44
|
|
542
555
|
```
|
|
543
556
|
|
|
544
557
|
**Get the list of items without repeating**:
|
|
@@ -582,23 +595,23 @@ jexp '.details.map(p=>{article:p.article,count:count(1),total:sum(p.qty * p.unit
|
|
|
582
595
|
[
|
|
583
596
|
{
|
|
584
597
|
"article": "Pear",
|
|
585
|
-
"count":
|
|
586
|
-
"total":
|
|
598
|
+
"count": 3,
|
|
599
|
+
"total": 7.12
|
|
587
600
|
},
|
|
588
601
|
{
|
|
589
602
|
"article": "Banana",
|
|
590
|
-
"count":
|
|
591
|
-
"total":
|
|
603
|
+
"count": 3,
|
|
604
|
+
"total": 7.96
|
|
592
605
|
},
|
|
593
606
|
{
|
|
594
607
|
"article": "White grape",
|
|
595
|
-
"count":
|
|
596
|
-
"total":
|
|
608
|
+
"count": 2,
|
|
609
|
+
"total": 4.06
|
|
597
610
|
},
|
|
598
611
|
{
|
|
599
612
|
"article": "Apple",
|
|
600
|
-
"count":
|
|
601
|
-
"total":
|
|
613
|
+
"count": 2,
|
|
614
|
+
"total": 4.3
|
|
602
615
|
}
|
|
603
616
|
]
|
|
604
617
|
```
|
|
@@ -625,7 +638,7 @@ jexp '{total:.[.length()-1].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.
|
|
|
625
638
|
|
|
626
639
|
```json
|
|
627
640
|
{
|
|
628
|
-
"total": 7.
|
|
641
|
+
"total": 7.949999999999999
|
|
629
642
|
}
|
|
630
643
|
```
|
|
631
644
|
|
|
@@ -638,24 +651,30 @@ jexp '.map(p=>{nro:p.number,total:p.details.sum(q=>q.qty * q.unitPrice)})' ./dat
|
|
|
638
651
|
*Result*:
|
|
639
652
|
|
|
640
653
|
```json
|
|
641
|
-
[{"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}]
|
|
642
655
|
```
|
|
643
656
|
|
|
644
657
|
## js-expression
|
|
645
658
|
|
|
646
|
-
[Js-expression](https://www.npmjs.com/package/js-expressions) is an extensible expression evaluator and parser.
|
|
647
|
-
|
|
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.
|
|
648
662
|
|
|
649
663
|
### Documentation
|
|
650
664
|
|
|
651
|
-
- [
|
|
652
|
-
- [Assignment](https://github.com/FlavioLionelRita/js-expressions/wiki/Assignment)
|
|
653
|
-
- [Bitwise](https://github.com/FlavioLionelRita/js-expressions/wiki/Bitwise)
|
|
665
|
+
- [Arithmetic](https://github.com/FlavioLionelRita/js-expressions/wiki/Arithmetic)
|
|
654
666
|
- [Comparison](https://github.com/FlavioLionelRita/js-expressions/wiki/Comparison)
|
|
655
|
-
- [Control flows](https://github.com/FlavioLionelRita/js-expressions/wiki/Flows)
|
|
656
|
-
- [Datetime](https://github.com/FlavioLionelRita/js-expressions/wiki/Datetime)
|
|
657
|
-
- [Extend](https://github.com/FlavioLionelRita/js-expressions/wiki/Extend)
|
|
658
667
|
- [Logical](https://github.com/FlavioLionelRita/js-expressions/wiki/Logical)
|
|
659
|
-
- [
|
|
668
|
+
- [Bitwise](https://github.com/FlavioLionelRita/js-expressions/wiki/Bitwise)
|
|
660
669
|
- [Numeric](https://github.com/FlavioLionelRita/js-expressions/wiki/Numeric)
|
|
661
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/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,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"commander": "^9.4.0",
|
|
21
|
-
"js-expressions": "1.0
|
|
21
|
+
"js-expressions": "1.1.0",
|
|
22
22
|
"js-yaml": "^4.1.0"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|