jexp 0.1.7 → 0.1.10

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.
Files changed (2) hide show
  1. package/README.md +142 -74
  2. 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
- - Constants, enums, variables, objects and arrays
8
- - Arithmetic, assignment, comparison, Logical and bitwise operators
9
- - Functions and arrow functions
10
- - distinct and group by
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
- expression that is applied to the data source
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,19 +283,19 @@ 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
- **Get the minimum of the total property**:
289
+ **The order with the smallest total**:
277
290
 
278
291
  ```sh
279
- jexp '.min(p=> p.total)' ./data/orders.json
292
+ jexp '.map(p=>{nro:p.number,total:p.details.sum(q=> q.unitPrice * q.qty)}).min(p=> p.total)' ./data/orders.json
280
293
  ```
281
294
 
282
295
  *Result*:
283
296
 
284
297
  ```json
285
- null
298
+ 7.58
286
299
  ```
287
300
 
288
301
  **Get the minimum of the article property from all the details**:
@@ -312,13 +325,13 @@ jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
312
325
  **Get the middle value "unitPrice * p.qty" from all the details**:
313
326
 
314
327
  ```sh
315
- jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
328
+ jexp 'round(.details.avg(p=> p.unitPrice * p.qty),2)' ./data/orders.json
316
329
  ```
317
330
 
318
331
  *Result*:
319
332
 
320
333
  ```json
321
- 2.5816666666666666
334
+ 2.35
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
- 4
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
- "Pear"
394
+ "White grape"
382
395
  ```
383
396
 
384
397
  **Get the first detail where "unitPrice * p.qty" is less than 3 in beautiful format**:
@@ -397,18 +410,6 @@ jexp '.details.first(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json -b
397
410
  }
398
411
  ```
399
412
 
400
- **Get the sum "unitPrice * p.qty" of the details of item 1 of the list using pipeline**:
401
-
402
- ```sh
403
- curl -s https://raw.githubusercontent.com/FlavioLionelRita/jexp/main/data/orders.json | jexp '.details.sum(p=> p.unitPrice * p.qty )'
404
- ```
405
-
406
- *Result*:
407
-
408
- ```json
409
- 15.49
410
- ```
411
-
412
413
  **Get the smallest article**:
413
414
 
414
415
  ```sh
@@ -433,16 +434,16 @@ jexp '.details.max(p=> p.unitPrice * p.qty )' ./data/orders.json
433
434
  3.98
434
435
  ```
435
436
 
436
- **Get the mean value of all details**:
437
+ **Average value of the price of the items purchased in the order 20003**:
437
438
 
438
439
  ```sh
439
- jexp '.details.avg(p=> p.unitPrice * p.qty )' ./data/orders.json
440
+ jexp 'round(.filter(p=> p.number == "20003").details.avg(p=> p.unitPrice),2)' ./data/orders.json
440
441
  ```
441
442
 
442
443
  *Result*:
443
444
 
444
445
  ```json
445
- 2.5816666666666666
446
+ 2
446
447
  ```
447
448
 
448
449
  **Get the total of the details of order 1**:
@@ -466,7 +467,7 @@ jexp '.details.count(p=> p.unitPrice * p.qty < 3 )' ./data/orders.json
466
467
  *Result*:
467
468
 
468
469
  ```json
469
- 4
470
+ 8
470
471
  ```
471
472
 
472
473
  **Get the article of the first detail where the subtotal is less than 3**:
@@ -490,7 +491,7 @@ jexp '.details.last(p=> p.unitPrice * p.qty < 3 ).article' ./data/orders.json
490
491
  *Result*:
491
492
 
492
493
  ```json
493
- "Pear"
494
+ "White grape"
494
495
  ```
495
496
 
496
497
  **Get the first detail where the subtotal is less than 3**:
@@ -514,7 +515,7 @@ jexp '.each(p=>p.total=p.details.sum(q=>q.qty*q.unitPrice)).map(p=>{nro:p.number
514
515
  *Result*:
515
516
 
516
517
  ```json
517
- [{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
518
+ [{"nro":"20001","total":7.58},{"nro":"20002","total":7.91},{"nro":"20003","total":7.949999999999999}]
518
519
  ```
519
520
 
520
521
  **Calculate the subtotal for each order**:
@@ -526,7 +527,7 @@ jexp '.details.foreach(p=>p.subtotal=p.qty*p.unitPrice).subtotal' ./data/orders.
526
527
  *Result*:
527
528
 
528
529
  ```json
529
- [3.56,1.99,2.03,2.15,3.98,1.78]
530
+ [3.56,1.99,2.03,2.15,3.98,1.78,2.15,1.99,1.78,2.03]
530
531
  ```
531
532
 
532
533
  **calculates the total of all the details**:
@@ -538,7 +539,7 @@ jexp '.details.foreach(p=>total=nvl(total,0)+p.qty*p.unitPrice);total' ./data/or
538
539
  *Result*:
539
540
 
540
541
  ```json
541
- 15.49
542
+ 23.44
542
543
  ```
543
544
 
544
545
  **Get the list of items without repeating**:
@@ -558,18 +559,6 @@ jexp '.details.distinct(p=>p.article)' ./data/orders.json -b
558
559
  ]
559
560
  ```
560
561
 
561
- **Get the list of items and quantity without repeating**:
562
-
563
- ```sh
564
- jexp '.details.distinct(p=>{article:p.article,qty:p.qty}) -b' ./data/orders.json
565
- ```
566
-
567
- *Result*:
568
-
569
- ```json
570
- null
571
- ```
572
-
573
562
  **Get the total and amount of each item**:
574
563
 
575
564
  ```sh
@@ -582,23 +571,23 @@ jexp '.details.map(p=>{article:p.article,count:count(1),total:sum(p.qty * p.unit
582
571
  [
583
572
  {
584
573
  "article": "Pear",
585
- "count": 2,
586
- "total": 5.34
574
+ "count": 3,
575
+ "total": 7.12
587
576
  },
588
577
  {
589
578
  "article": "Banana",
590
- "count": 2,
591
- "total": 5.97
579
+ "count": 3,
580
+ "total": 7.96
592
581
  },
593
582
  {
594
583
  "article": "White grape",
595
- "count": 1,
596
- "total": 2.03
584
+ "count": 2,
585
+ "total": 4.06
597
586
  },
598
587
  {
599
588
  "article": "Apple",
600
- "count": 1,
601
- "total": 2.15
589
+ "count": 2,
590
+ "total": 4.3
602
591
  }
603
592
  ]
604
593
  ```
@@ -618,44 +607,123 @@ jexp '{total:.[0].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json
618
607
  **Get the total of the last order**:
619
608
 
620
609
  ```sh
621
- jexp '{total:.[.length()-1].details.sum(p=>p.qty * p.unitPrice)}' ./data/orders.json -b
610
+ jexp '{total:round(.[.length()-1].details.sum(p=>p.qty * p.unitPrice),2)}' ./data/orders.json -b
622
611
  ```
623
612
 
624
613
  *Result*:
625
614
 
626
615
  ```json
627
616
  {
628
- "total": 7.91
617
+ "total": 7.95
629
618
  }
630
619
  ```
631
620
 
632
621
  **List the orders with their totals**:
633
622
 
634
623
  ```sh
635
- jexp '.map(p=>{nro:p.number,total:p.details.sum(q=>q.qty * q.unitPrice)})' ./data/orders.json
624
+ jexp '.map(p=>{nro:p.number,total:round(p.details.sum(q=>q.qty * q.unitPrice),2)})' ./data/orders.json -b
625
+ ```
626
+
627
+ *Result*:
628
+
629
+ ```json
630
+ [
631
+ {
632
+ "nro": "20001",
633
+ "total": 7.6
634
+ },
635
+ {
636
+ "nro": "20002",
637
+ "total": 7.9
638
+ },
639
+ {
640
+ "nro": "20003",
641
+ "total": 7.95
642
+ }
643
+ ]
644
+ ```
645
+
646
+ **All articles that are in orders 20001 and 20003**:
647
+
648
+ ```sh
649
+ jexp '.[0].details.article.union(.[1].details.article)' ./data/orders.json
650
+ ```
651
+
652
+ *Result*:
653
+
654
+ ```json
655
+ ["Pear","Banana","White grape","Apple"]
656
+ ```
657
+
658
+ **The articles in common between order 20001 and 20002**:
659
+
660
+ ```sh
661
+ jexp '.[0].details.article.intersection(.[1].details.article)' ./data/orders.json
662
+ ```
663
+
664
+ *Result*:
665
+
666
+ ```json
667
+ ["Banana","Pear"]
668
+ ```
669
+
670
+ **Articles that are in order 20001 and are not in order 20002**:
671
+
672
+ ```sh
673
+ jexp '.[0].details.article.difference(.[1].details.article)' ./data/orders.json
674
+ ```
675
+
676
+ *Result*:
677
+
678
+ ```json
679
+ ["White grape"]
680
+ ```
681
+
682
+ **Articles of orders 20001 and 20003 that are not shared**:
683
+
684
+ ```sh
685
+ jexp '.[0].details.article.symmetricDifference(.[1].details.article)' ./data/orders.json
636
686
  ```
637
687
 
638
688
  *Result*:
639
689
 
640
690
  ```json
641
- [{"nro":"20001","total":7.58},{"nro":"20002","total":7.91}]
691
+ ["White grape","Apple"]
692
+ ```
693
+
694
+ **Get the sum "unitPrice * p.qty" of the details of item 1 of the list using pipeline**:
695
+
696
+ ```sh
697
+ curl -s https://raw.githubusercontent.com/FlavioLionelRita/jexp/main/data/orders.json | jexp '.details.sum(p=> p.unitPrice * p.qty )'
698
+ ```
699
+
700
+ *Result*:
701
+
702
+ ```json
703
+ 23.44
642
704
  ```
643
705
 
644
706
  ## js-expression
645
707
 
646
- [Js-expression](https://www.npmjs.com/package/js-expressions) is an extensible expression evaluator and parser. \
647
- Besides the operators, functions, variables, objects and arrays that are supported
708
+ > [Js-expression](https://www.npmjs.com/package/js-expressions) is an extensible expression evaluator and parser.
709
+ >
710
+ > Besides the operators, functions, variables, objects and arrays that are supported.
648
711
 
649
712
  ### Documentation
650
713
 
651
- - [Array](https://github.com/FlavioLionelRita/js-expressions/wiki/Array)
652
- - [Assignment](https://github.com/FlavioLionelRita/js-expressions/wiki/Assignment)
653
- - [Bitwise](https://github.com/FlavioLionelRita/js-expressions/wiki/Bitwise)
714
+ - [Arithmetic](https://github.com/FlavioLionelRita/js-expressions/wiki/Arithmetic)
654
715
  - [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
716
  - [Logical](https://github.com/FlavioLionelRita/js-expressions/wiki/Logical)
659
- - [Nullable](https://github.com/FlavioLionelRita/js-expressions/wiki/Nullable)
717
+ - [Bitwise](https://github.com/FlavioLionelRita/js-expressions/wiki/Bitwise)
660
718
  - [Numeric](https://github.com/FlavioLionelRita/js-expressions/wiki/Numeric)
661
719
  - [String](https://github.com/FlavioLionelRita/js-expressions/wiki/String)
720
+ - [Datetime](https://github.com/FlavioLionelRita/js-expressions/wiki/Datetime)
721
+ - [Nullable](https://github.com/FlavioLionelRita/js-expressions/wiki/Nullable)
722
+ - [Conversion](https://github.com/FlavioLionelRita/js-expressions/wiki/Conversion)
723
+ - [Assignment](https://github.com/FlavioLionelRita/js-expressions/wiki/Assignment)
724
+ - [Array](https://github.com/FlavioLionelRita/js-expressions/wiki/Array)
725
+ - [Arrow](https://github.com/FlavioLionelRita/js-expressions/wiki/Arrow)
726
+ - [Group](https://github.com/FlavioLionelRita/js-expressions/wiki/Group)
727
+ - [Sets](https://github.com/FlavioLionelRita/js-expressions/wiki/Sets)
728
+ - [Control flows](https://github.com/FlavioLionelRita/js-expressions/wiki/Flows)
729
+ - [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.7",
3
+ "version": "0.1.10",
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.11",
21
+ "js-expressions": "1.1.0",
22
22
  "js-yaml": "^4.1.0"
23
23
  },
24
24
  "keywords": [