jexp 0.1.5 → 0.1.6

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