1ls 0.1.12 → 0.1.14
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 +285 -11
- package/dist/browser/constants.d.ts +1 -1
- package/dist/browser/index.js +11 -11
- package/dist/cli/constants.d.ts +1 -1
- package/dist/{utils → cli}/stream.d.ts +1 -1
- package/dist/completions/1ls.bash +11 -19
- package/dist/completions/1ls.zsh +146 -40
- package/dist/completions/constants.d.ts +124 -0
- package/dist/completions/constants.ts +41 -0
- package/dist/completions/index.d.ts +17 -0
- package/dist/completions/index.ts +197 -0
- package/dist/completions/install-completions.sh +8 -7
- package/dist/{shared/constants.d.ts → constants.d.ts} +1 -1
- package/dist/expression/constants.d.ts +2 -0
- package/dist/expression/index.d.ts +3 -12
- package/dist/expression/utils.d.ts +14 -1
- package/dist/file/constants.d.ts +4 -0
- package/dist/file/filters.d.ts +7 -0
- package/dist/file/grep.d.ts +10 -0
- package/dist/file/index.d.ts +7 -0
- package/dist/file/info.d.ts +4 -0
- package/dist/file/io.d.ts +5 -0
- package/dist/{utils → file}/types.d.ts +0 -17
- package/dist/file/walk.d.ts +4 -0
- package/dist/formats/index.d.ts +1 -1
- package/dist/formats/types.d.ts +1 -0
- package/dist/formats/yaml/index.d.ts +2 -0
- package/dist/formats/yaml/types.d.ts +8 -0
- package/dist/formats/yaml/utils.d.ts +28 -0
- package/dist/index.js +82 -65
- package/dist/interactive/builder/constants.d.ts +14 -0
- package/dist/interactive/{builder.d.ts → builder/index.d.ts} +1 -1
- package/dist/interactive/builder/types.d.ts +4 -0
- package/dist/interactive/builder/utils.d.ts +7 -0
- package/dist/interactive/methods/constants.d.ts +10 -0
- package/dist/interactive/methods/index.d.ts +4 -0
- package/dist/interactive/methods/types.d.ts +8 -0
- package/dist/interactive/preview/constants.d.ts +4 -0
- package/dist/interactive/preview/index.d.ts +5 -0
- package/dist/interactive/preview/types.d.ts +6 -0
- package/dist/interactive/tooltip/constants.d.ts +3 -0
- package/dist/interactive/tooltip/index.d.ts +20 -0
- package/dist/interactive/tooltip/types.d.ts +13 -0
- package/dist/interactive/types.d.ts +5 -7
- package/dist/{utils/logger.d.ts → logger.d.ts} +10 -1
- package/dist/navigator/builtins/constants.d.ts +62 -0
- package/dist/navigator/builtins/index.d.ts +6 -0
- package/dist/navigator/builtins/types.d.ts +3 -0
- package/dist/navigator/builtins/utils.d.ts +12 -0
- package/dist/navigator/json/constants.d.ts +2 -0
- package/dist/navigator/json/index.d.ts +22 -0
- package/dist/navigator/json/types.d.ts +3 -0
- package/dist/navigator/json/utils.d.ts +14 -0
- package/dist/shortcuts/constants.d.ts +15 -0
- package/dist/shortcuts/index.d.ts +9 -0
- package/dist/shortcuts/types.d.ts +6 -0
- package/dist/types.d.ts +21 -2
- package/dist/version.d.ts +1 -1
- package/package.json +18 -10
- package/dist/formats/yaml.d.ts +0 -3
- package/dist/interactive/methods.d.ts +0 -12
- package/dist/navigator/json.d.ts +0 -31
- package/dist/utils/constants.d.ts +0 -12
- package/dist/utils/file.d.ts +0 -27
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/shortcuts.d.ts +0 -8
package/README.md
CHANGED
|
@@ -6,18 +6,17 @@
|
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://github.com/yowainwright/1ls)
|
|
8
8
|
|
|
9
|
-
>
|
|
9
|
+
> Minimal syntax. Maximum formats.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
```bash
|
|
12
|
+
# full
|
|
13
|
+
echo '[1,2,3]' | 1ls '.filter(x => x > 1).map(x => x * 2)'
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
# shortened
|
|
16
|
+
echo '[1,2,3]' | 1ls '.fl(x => x > 1).mp(x => x * 2)'
|
|
17
|
+
```
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
And, it is compiled with QuickJs for binary builds.
|
|
19
|
-
This means you get good speed compared to jq and fx but it's still, just JS,
|
|
20
|
-
the language y'all know.
|
|
19
|
+
JavaScript syntax with shortcuts. JSON, YAML, TOML, XML, CSV, INI, ENV, NDJSON. Zero dependencies.
|
|
21
20
|
|
|
22
21
|
## Why 1ls?
|
|
23
22
|
|
|
@@ -28,6 +27,69 @@ the language y'all know.
|
|
|
28
27
|
- **Powerful**: Full support for array methods, arrow functions, and object operations
|
|
29
28
|
- **Shortcuts**: Built-in shortcuts for common operations (e.g., `.mp` for `.map`)
|
|
30
29
|
|
|
30
|
+
## jq vs fx vs 1ls
|
|
31
|
+
|
|
32
|
+
**Filter and map:**
|
|
33
|
+
```bash
|
|
34
|
+
# jq
|
|
35
|
+
echo '[{"age":25},{"age":35}]' | jq '[.[] | select(.age > 30) | .age]'
|
|
36
|
+
|
|
37
|
+
# fx
|
|
38
|
+
echo '[{"age":25},{"age":35}]' | fx '.filter(x => x.age > 30).map(x => x.age)'
|
|
39
|
+
|
|
40
|
+
# 1ls
|
|
41
|
+
echo '[{"age":25},{"age":35}]' | 1ls '.filter(x => x.age > 30).map(x => x.age)'
|
|
42
|
+
echo '[{"age":25},{"age":35}]' | 1ls '.fl(x => x.age > 30).mp(x => x.age)'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**First matching item:**
|
|
46
|
+
```bash
|
|
47
|
+
# jq
|
|
48
|
+
echo '[{"id":1},{"id":2}]' | jq '[.[] | select(.id == 2)] | first'
|
|
49
|
+
|
|
50
|
+
# fx
|
|
51
|
+
echo '[{"id":1},{"id":2}]' | fx '.find(x => x.id === 2)'
|
|
52
|
+
|
|
53
|
+
# 1ls
|
|
54
|
+
echo '[{"id":1},{"id":2}]' | 1ls '.find(x => x.id === 2)'
|
|
55
|
+
echo '[{"id":1},{"id":2}]' | 1ls '.fd(x => x.id === 2)'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Get array length:**
|
|
59
|
+
```bash
|
|
60
|
+
# jq
|
|
61
|
+
echo '[1,2,3,4,5]' | jq 'length'
|
|
62
|
+
|
|
63
|
+
# fx
|
|
64
|
+
echo '[1,2,3,4,5]' | fx '.length'
|
|
65
|
+
|
|
66
|
+
# 1ls
|
|
67
|
+
echo '[1,2,3,4,5]' | 1ls '.length'
|
|
68
|
+
echo '[1,2,3,4,5]' | 1ls '.ln'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**YAML input:**
|
|
72
|
+
```bash
|
|
73
|
+
# jq - not supported
|
|
74
|
+
|
|
75
|
+
# fx
|
|
76
|
+
echo 'name: Ada' | fx --yaml '.name'
|
|
77
|
+
|
|
78
|
+
# 1ls (auto-detects format)
|
|
79
|
+
echo 'name: Ada' | 1ls '.name'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Convert between forms:**
|
|
83
|
+
```bash
|
|
84
|
+
# shorten
|
|
85
|
+
1ls --shorten '.filter(x => x > 1).map(x => x * 2)'
|
|
86
|
+
# → .fl(x => x > 1).mp(x => x * 2)
|
|
87
|
+
|
|
88
|
+
# expand
|
|
89
|
+
1ls --expand '.fl(x => x > 1).mp(x => x * 2)'
|
|
90
|
+
# → .filter(x => x > 1).map(x => x * 2)
|
|
91
|
+
```
|
|
92
|
+
|
|
31
93
|
## Installation
|
|
32
94
|
|
|
33
95
|
```bash
|
|
@@ -42,6 +104,14 @@ brew install yowainwright/tap/1ls
|
|
|
42
104
|
curl -fsSL https://raw.githubusercontent.com/yowainwright/1ls/main/scripts/install.sh | bash
|
|
43
105
|
```
|
|
44
106
|
|
|
107
|
+
### Shell Completions (zsh)
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
bash <(curl -fsSL https://raw.githubusercontent.com/yowainwright/1ls/main/dist/completions/install-completions.sh)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> TODO: bash and fish shell completions are not yet supported.
|
|
114
|
+
|
|
45
115
|
## Quick Start
|
|
46
116
|
|
|
47
117
|
```bash
|
|
@@ -287,6 +357,8 @@ echo '["a", "b"]' | 1ls '.jn(",")' # Short for .join()
|
|
|
287
357
|
| `--pretty` | `-p` | Pretty print output (default) |
|
|
288
358
|
| `--compact` | `-c` | Compact single-line output |
|
|
289
359
|
| `--type` | `-t` | Show type of result |
|
|
360
|
+
| `--slurp` | `-S` | Read all inputs into an array |
|
|
361
|
+
| `--null-input` | `-N` | Use null as input (for generating data) |
|
|
290
362
|
|
|
291
363
|
### Format Options
|
|
292
364
|
|
|
@@ -326,6 +398,25 @@ echo '["a", "b"]' | 1ls '.jn(",")' # Short for .join()
|
|
|
326
398
|
- `.[start:end]` - Array slice
|
|
327
399
|
- `.[]` - Array spread
|
|
328
400
|
|
|
401
|
+
### jq-compatible Operators
|
|
402
|
+
- `..` - Recursive descent (collect all nested values)
|
|
403
|
+
- `.foo?` - Optional access (returns null on error instead of failing)
|
|
404
|
+
- `.foo ?? default` - Null coalescing (provide fallback for null/undefined)
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
# Recursive descent - get all values from nested structure
|
|
408
|
+
echo '{"a": {"b": 1}, "c": [2, 3]}' | 1ls '..'
|
|
409
|
+
# Output: [{"a": {"b": 1}, "c": [2, 3]}, {"b": 1}, 1, [2, 3], 2, 3]
|
|
410
|
+
|
|
411
|
+
# Optional access - safe navigation
|
|
412
|
+
echo '{"user": null}' | 1ls '.user?.name'
|
|
413
|
+
# Output: null (instead of error)
|
|
414
|
+
|
|
415
|
+
# Null coalescing - default values
|
|
416
|
+
echo '{"name": null}' | 1ls '.name ?? "anonymous"'
|
|
417
|
+
# Output: "anonymous"
|
|
418
|
+
```
|
|
419
|
+
|
|
329
420
|
### Object Operations
|
|
330
421
|
- `.{keys}` - Get object keys
|
|
331
422
|
- `.{values}` - Get object values
|
|
@@ -351,6 +442,97 @@ All standard JavaScript array methods are supported:
|
|
|
351
442
|
- `.substring()`, `.charAt()`
|
|
352
443
|
- `.match()`, `.split()`
|
|
353
444
|
|
|
445
|
+
### Builtin Functions (jq-compatible)
|
|
446
|
+
|
|
447
|
+
**Array Operations:**
|
|
448
|
+
- `head()` / `hd()` - First element
|
|
449
|
+
- `last()` / `lst()` - Last element
|
|
450
|
+
- `tail()` / `tl()` - All but first element
|
|
451
|
+
- `take(n)` / `tk(n)` - Take first n elements
|
|
452
|
+
- `drop(n)` / `drp(n)` - Drop first n elements
|
|
453
|
+
- `uniq()` / `unq()` - Remove duplicates
|
|
454
|
+
- `flatten()` / `fltn()` - Flatten nested arrays
|
|
455
|
+
- `rev()` - Reverse array
|
|
456
|
+
- `chunk(n)` / `chnk(n)` - Split into chunks of size n
|
|
457
|
+
- `compact()` / `cmpct()` - Remove falsy values
|
|
458
|
+
- `nth(n)` - Get element at index n
|
|
459
|
+
- `add()` - Sum numbers or concatenate arrays/strings
|
|
460
|
+
|
|
461
|
+
**Object Operations:**
|
|
462
|
+
- `keys()` / `ks()` - Get object keys
|
|
463
|
+
- `vals()` - Get object values
|
|
464
|
+
- `pick(k1, k2, ...)` / `pk()` - Pick specific keys
|
|
465
|
+
- `omit(k1, k2, ...)` / `omt()` - Omit specific keys
|
|
466
|
+
- `merge(obj)` / `mrg()` - Shallow merge objects
|
|
467
|
+
- `deepMerge(obj)` / `dMrg()` - Deep merge objects
|
|
468
|
+
- `fromPairs()` / `frPrs()` - Convert pairs to object
|
|
469
|
+
- `toPairs()` / `toPrs()` - Convert object to pairs
|
|
470
|
+
- `has(key)` / `hs()` - Check if key exists
|
|
471
|
+
- `pluck(key)` / `plk()` - Extract property from array of objects
|
|
472
|
+
|
|
473
|
+
**Grouping & Sorting:**
|
|
474
|
+
- `groupBy(fn)` / `grpBy()` - Group by key function
|
|
475
|
+
- `sortBy(fn)` / `srtBy()` - Sort by key function
|
|
476
|
+
|
|
477
|
+
**Math & Aggregation:**
|
|
478
|
+
- `sum()` - Sum of numbers
|
|
479
|
+
- `mean()` / `avg()` - Average of numbers
|
|
480
|
+
- `min()` - Minimum value
|
|
481
|
+
- `max()` - Maximum value
|
|
482
|
+
- `floor()` / `flr()` - Floor number
|
|
483
|
+
- `ceil()` / `cl()` - Ceiling number
|
|
484
|
+
- `round()` / `rnd()` - Round number
|
|
485
|
+
- `abs()` - Absolute value
|
|
486
|
+
|
|
487
|
+
**String Operations:**
|
|
488
|
+
- `split(sep)` / `spl()` - Split string by separator
|
|
489
|
+
- `join(sep)` / `jn()` - Join array with separator
|
|
490
|
+
- `startswith(s)` / `stw()` - Check if starts with string
|
|
491
|
+
- `endswith(s)` / `edw()` - Check if ends with string
|
|
492
|
+
- `ltrimstr(s)` / `ltrm()` - Remove prefix
|
|
493
|
+
- `rtrimstr(s)` / `rtrm()` - Remove suffix
|
|
494
|
+
- `tostring()` / `tstr()` - Convert to string
|
|
495
|
+
- `tonumber()` / `tnum()` - Convert to number
|
|
496
|
+
|
|
497
|
+
**Type & Inspection:**
|
|
498
|
+
- `type()` / `typ()` - Get value type
|
|
499
|
+
- `len()` - Get length
|
|
500
|
+
- `count()` / `cnt()` - Count items
|
|
501
|
+
- `isEmpty()` / `emp()` - Check if empty
|
|
502
|
+
- `isNil()` / `nil()` - Check if null/undefined
|
|
503
|
+
- `contains(val)` / `ctns()` - Check if contains value
|
|
504
|
+
|
|
505
|
+
**Path Operations:**
|
|
506
|
+
- `path()` / `pth()` - Get all paths in structure
|
|
507
|
+
- `getpath(path)` / `gpth()` - Get value at path
|
|
508
|
+
- `setpath(path)` / `spth()` - Set value at path
|
|
509
|
+
- `recurse()` / `rec()` - Recursively collect all values
|
|
510
|
+
|
|
511
|
+
**Control Flow:**
|
|
512
|
+
- `select(fn)` / `sel()` - Filter by predicate (jq-style)
|
|
513
|
+
- `empty()` - Return nothing
|
|
514
|
+
- `error(msg)` - Throw error
|
|
515
|
+
- `debug()` / `dbg()` - Debug output
|
|
516
|
+
- `not()` - Boolean negation
|
|
517
|
+
- `range(n)` / `rng()` - Generate range [0, n)
|
|
518
|
+
|
|
519
|
+
**Composition:**
|
|
520
|
+
- `pipe(expr1, expr2, ...)` - Apply expressions left-to-right
|
|
521
|
+
- `compose(expr1, expr2, ...)` - Apply expressions right-to-left
|
|
522
|
+
- `id()` - Identity function
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
# Builtin examples
|
|
526
|
+
echo '[1, 2, 3, 4, 5]' | 1ls 'head()' # 1
|
|
527
|
+
echo '[1, 2, 3, 4, 5]' | 1ls 'take(3)' # [1, 2, 3]
|
|
528
|
+
echo '[1, 2, 2, 3]' | 1ls 'uniq()' # [1, 2, 3]
|
|
529
|
+
echo '{"a": 1, "b": 2}' | 1ls 'keys()' # ["a", "b"]
|
|
530
|
+
echo '[1, 2, 3]' | 1ls 'sum()' # 6
|
|
531
|
+
echo '"hello"' | 1ls 'split("")' # ["h", "e", "l", "l", "o"]
|
|
532
|
+
echo '42' | 1ls 'type()' # "number"
|
|
533
|
+
echo 'null' | 1ls 'range(5)' # [0, 1, 2, 3, 4]
|
|
534
|
+
```
|
|
535
|
+
|
|
354
536
|
### Arrow Functions
|
|
355
537
|
Full support for arrow functions in method calls:
|
|
356
538
|
```bash
|
|
@@ -453,13 +635,105 @@ MIT © Jeff Wainwright
|
|
|
453
635
|
| Feature | 1ls | jq | fx |
|
|
454
636
|
|---------|-----|----|----|
|
|
455
637
|
| Syntax | JavaScript | DSL | JavaScript |
|
|
456
|
-
|
|
|
638
|
+
| Implementation | Bun/TS | C | Go |
|
|
457
639
|
| Learning Curve | Easy | Steep | Easy |
|
|
458
|
-
| Multi-format | ✓ | x |
|
|
640
|
+
| Multi-format | ✓ (12+) | x | ✓ (JSON/YAML/TOML) |
|
|
641
|
+
| Auto-detect Format | ✓ | x | x |
|
|
459
642
|
| Interactive Mode | ✓ | x | ✓ |
|
|
460
643
|
| Shortcuts | ✓ | x | x |
|
|
461
644
|
| Arrow Functions | ✓ | x | ✓ |
|
|
462
645
|
| File Operations | ✓ | x | x |
|
|
646
|
+
| jq Builtins | ✓ | ✓ | x |
|
|
647
|
+
| Recursive Descent (`..`) | ✓ | ✓ | x |
|
|
648
|
+
| Null Coalescing (`??`) | ✓ | ✓ | x |
|
|
649
|
+
|
|
650
|
+
<!-- BENCHMARKS:START -->
|
|
651
|
+
|
|
652
|
+
## Benchmarks
|
|
653
|
+
|
|
654
|
+
Comparing 1ls with jq and fx across various operations and data sizes.
|
|
655
|
+
|
|
656
|
+
- **Runs per test:** 5
|
|
657
|
+
- **Data sizes:** 1000, 10000, 100000 records
|
|
658
|
+
- **Environment:** Docker (debian:bookworm-slim)
|
|
659
|
+
|
|
660
|
+
### Summary
|
|
661
|
+
|
|
662
|
+
| Tool | Avg Time (ms) | vs 1ls |
|
|
663
|
+
|------|---------------|--------|
|
|
664
|
+
| **1ls** | **0.62** | **1x** |
|
|
665
|
+
| jq | 103.17 | 166x slower |
|
|
666
|
+
| fx | 171.61 | 276x slower |
|
|
667
|
+
|
|
668
|
+
**1ls is 166x faster than jq and 276x faster than fx on average.**
|
|
669
|
+
|
|
670
|
+
Lower is better. Times in milliseconds (ms).
|
|
671
|
+
|
|
672
|
+
### Basic Operations (ms)
|
|
673
|
+
|
|
674
|
+
| Operation | Size | jq | fx | 1ls |
|
|
675
|
+
|-----------|------|----|----|-----|
|
|
676
|
+
| First element | 1000 | 21.26 | 7.79 | 0.60 |
|
|
677
|
+
| Length | 1000 | 21.26 | 6.91 | 0.53 |
|
|
678
|
+
| Last element | 1000 | 46.02 | 7.67 | 0.47 |
|
|
679
|
+
| First element | 10000 | 32.22 | 41.50 | 0.47 |
|
|
680
|
+
| Length | 10000 | 31.58 | 38.55 | 0.47 |
|
|
681
|
+
| Last element | 10000 | 31.16 | 39.53 | 0.50 |
|
|
682
|
+
| First element | 100000 | 158.56 | 382.21 | 0.64 |
|
|
683
|
+
| Length | 100000 | 188.74 | 351.79 | 0.56 |
|
|
684
|
+
| Last element | 100000 | 159.04 | 355.60 | 0.52 |
|
|
685
|
+
|
|
686
|
+
### Filter & Map (ms)
|
|
687
|
+
|
|
688
|
+
| Operation | Size | jq | fx | 1ls |
|
|
689
|
+
|-----------|------|----|----|-----|
|
|
690
|
+
| Filter | 1000 | 20.73 | 9.49 | 0.47 |
|
|
691
|
+
| Map | 1000 | 19.28 | 5.89 | 0.43 |
|
|
692
|
+
| Filter+Map | 1000 | 19.78 | 6.28 | 0.54 |
|
|
693
|
+
| Filter | 10000 | 47.02 | 65.21 | 0.48 |
|
|
694
|
+
| Map | 10000 | 34.35 | 44.06 | 0.53 |
|
|
695
|
+
| Filter+Map | 10000 | 37.52 | 44.58 | 0.56 |
|
|
696
|
+
| Filter | 100000 | 294.43 | 824.56 | 0.68 |
|
|
697
|
+
| Map | 100000 | 208.42 | 395.50 | 0.76 |
|
|
698
|
+
| Filter+Map | 100000 | 208.05 | 401.71 | 0.54 |
|
|
699
|
+
|
|
700
|
+
### Aggregation (ms)
|
|
701
|
+
|
|
702
|
+
| Operation | Size | jq | fx | 1ls |
|
|
703
|
+
|-----------|------|----|----|-----|
|
|
704
|
+
| Sum | 1000 | 20.90 | 6.21 | 0.59 |
|
|
705
|
+
| Min | 1000 | 20.66 | 7.21 | 0.61 |
|
|
706
|
+
| Max | 1000 | 20.90 | 7.37 | 0.57 |
|
|
707
|
+
| Sum | 10000 | 36.98 | 43.53 | 0.46 |
|
|
708
|
+
| Min | 10000 | 35.86 | 44.54 | 0.54 |
|
|
709
|
+
| Max | 10000 | 36.44 | 44.45 | 0.71 |
|
|
710
|
+
| Sum | 100000 | 227.80 | 397.98 | 0.65 |
|
|
711
|
+
| Min | 100000 | 205.29 | 396.93 | 0.50 |
|
|
712
|
+
| Max | 100000 | 194.16 | 388.88 | 0.49 |
|
|
713
|
+
|
|
714
|
+
### Builtin Functions (ms)
|
|
715
|
+
|
|
716
|
+
| Operation | Size | jq | fx | 1ls |
|
|
717
|
+
|-----------|------|----|----|-----|
|
|
718
|
+
| head() | 1000 | 19.93 | 6.55 | 0.49 |
|
|
719
|
+
| last() | 1000 | 19.88 | 5.92 | 0.46 |
|
|
720
|
+
| take(10) | 1000 | 19.97 | 5.62 | 0.44 |
|
|
721
|
+
| uniq() | 1000 | 20.79 | 8.34 | 0.42 |
|
|
722
|
+
| flatten() | 1000 | 21.53 | 9.90 | 0.46 |
|
|
723
|
+
| head() | 10000 | 31.34 | 40.23 | 0.48 |
|
|
724
|
+
| last() | 10000 | 31.81 | 38.05 | 0.54 |
|
|
725
|
+
| take(10) | 10000 | 31.00 | 37.69 | 0.46 |
|
|
726
|
+
| uniq() | 10000 | 47.00 | 61.05 | 0.48 |
|
|
727
|
+
| flatten() | 10000 | 52.07 | 88.38 | 0.62 |
|
|
728
|
+
| head() | 100000 | 171.62 | 353.11 | 0.49 |
|
|
729
|
+
| last() | 100000 | 158.29 | 359.10 | 0.59 |
|
|
730
|
+
| take(10) | 100000 | 151.69 | 351.13 | 0.49 |
|
|
731
|
+
| uniq() | 100000 | 355.20 | 576.73 | 0.53 |
|
|
732
|
+
| flatten() | 100000 | 370.08 | 760.43 | 0.51 |
|
|
733
|
+
|
|
734
|
+
Run `bun run test:bench` to regenerate benchmarks.
|
|
735
|
+
|
|
736
|
+
<!-- BENCHMARKS:END -->
|
|
463
737
|
|
|
464
738
|
## Troubleshooting
|
|
465
739
|
|
package/dist/browser/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,"\r"];function v(t,e,n){return{type:t,value:e,position:n}}class _{input;position=0;current;constructor(t){this.input=t,this.current=this.input[0]||""}tokenize(){let t=[];while(this.position<this.input.length){if(this.skipWhitespace(),this.position>=this.input.length)break;let e=this.nextToken();if(e)t.push(e)}return t.push(v("EOF","",this.position)),t}nextToken(){let t=this.position,e=q[this.current];if(e){let h=this.current;return this.advance(),v(e,h,t)}if(this.current==="="&&this.peek()===">")return this.advance(),this.advance(),v("ARROW","=>",t);if(this.current==='"'||this.current==="'")return this.readString();let s=this.isDigit(this.current),o=this.current==="-"&&this.isDigit(this.peek());if(s||o)return this.readNumber();if(this.isIdentifierStart(this.current))return this.readIdentifier();if(this.isOperator(this.current))return this.readOperator();return this.advance(),null}readString(){let t=this.position,e=this.current,n=[];this.advance();while(this.current!==e&&this.position<this.input.length){if(this.current==="\\"){if(this.advance(),this.position<this.input.length)n.push(this.current),this.advance();continue}n.push(this.current),this.advance()}if(this.current===e)this.advance();return v("STRING",n.join(""),t)}readNumber(){let t=this.position,e="";if(this.current==="-")e+=this.current,this.advance();while(this.isDigit(this.current))e+=this.current,this.advance();if(this.current==="."&&this.isDigit(this.peek())){e+=this.current,this.advance();while(this.isDigit(this.current))e+=this.current,this.advance()}return v("NUMBER",e,t)}readIdentifier(){let t=this.position,e="";while(this.isIdentifierChar(this.current))e+=this.current,this.advance();return v("IDENTIFIER",e,t)}readOperator(){let t=this.position,e="";while(this.isOperator(this.current))e+=this.current,this.advance();return v("OPERATOR",e,t)}skipWhitespace(){while(this.isWhitespace(this.current))this.advance()}advance(){this.position++,this.current=this.input[this.position]||""}peek(){return this.input[this.position+1]||""}isWhitespace(t){return tt.includes(t)}isDigit(t){return t>="0"&&t<="9"}isIdentifierStart(t){let e=t>="a"&&t<="z",n=t>="A"&&t<="Z";return e||n||t==="_"||t==="$"}isIdentifierChar(t){return this.isIdentifierStart(t)||this.isDigit(t)}isOperator(t){return Z.includes(t)}}var T=(t)=>{return{type:"Literal",value:t}},P=(t)=>{if(t==="true")return T(!0);if(t==="false")return T(!1);if(t==="null")return T(null);return};function E(t,e){return`${e} at position ${t.position} (got ${t.type}: "${t.value}")`}function b(t,e){return{type:"PropertyAccess",property:t,object:e}}function ft(t,e){return{type:"IndexAccess",index:t,object:e}}function mt(t,e,n){return{type:"SliceAccess",start:t,end:e,object:n}}function et(t,e,n){return{type:"MethodCall",method:t,args:e,object:n}}function At(t,e){return{type:"ObjectOperation",operation:t,object:e}}function yt(t){return{type:"ArraySpread",object:t}}function gt(t,e){return{type:"ArrowFunction",params:t,body:e}}function k(t){return{type:"Root",expression:t}}var nt=["keys","values","entries","length"];function Tt(t){return nt.includes(t)}class M{tokens;position=0;current;constructor(t){this.tokens=t,this.current=this.tokens[0]}parse(){if(this.current.type==="EOF")return k();let e=this.parseExpression();return k(e)}parseExpression(){return this.parsePrimary()}parsePrimary(){let t=this.parsePrimaryNode();return this.parsePostfix(t)}parsePrimaryNode(){let t=this.current.type;if(t==="DOT"){if(this.advance(),this.current.type==="EOF")return k();return this.parseAccessChain()}if(t==="LEFT_BRACKET")return this.parseArrayAccess();if(t==="IDENTIFIER")return this.parseIdentifierOrFunction();if(t==="STRING"){let e=this.current.value;return this.advance(),T(e)}if(t==="NUMBER"){let e=Number(this.current.value);return this.advance(),T(e)}if(t==="LEFT_PAREN"){let e=this.parseFunctionParams();return this.parseArrowFunction(e)}throw Error(E(this.current,"Unexpected token"))}parseAccessChain(t){let e=this.current.type;if(e==="IDENTIFIER"){let n=this.current.value;return this.advance(),b(n,t)}if(e==="LEFT_BRACKET")return this.parseBracketAccess(t);if(e==="LEFT_BRACE")return this.parseObjectOperation(t);throw Error(E(this.current,"Expected property name after dot"))}parseBracketAccess(t){if(this.advance(),this.current.type==="RIGHT_BRACKET")return this.advance(),yt(t);if(this.current.type==="STRING"){let a=this.current.value;return this.advance(),this.expect("RIGHT_BRACKET"),b(a,t)}let r=this.current.type==="NUMBER",s=this.current.type==="OPERATOR"&&this.current.value==="-",o=this.current.type==="COLON";if(r||s||o)return this.parseNumericIndexOrSlice(t);throw Error(E(this.current,"Unexpected token in bracket access"))}parseNumericIndexOrSlice(t){if(this.current.type==="COLON")return this.parseSliceFromColon(void 0,t);let n=this.parseNumber();if(this.advance(),this.current.type==="COLON")return this.parseSliceFromColon(n,t);return this.expect("RIGHT_BRACKET"),ft(n,t)}parseSliceFromColon(t,e){this.advance();let n=this.current.type==="NUMBER",r=this.current.type==="OPERATOR"&&this.current.value==="-",s=n||r,o=s?this.parseNumber():void 0;if(s)this.advance();return this.expect("RIGHT_BRACKET"),mt(t,o,e)}parseArrayAccess(){return this.parseBracketAccess()}parseObjectOperation(t){if(this.advance(),this.current.type!=="IDENTIFIER")throw Error(E(this.current,"Expected operation name after {"));let n=this.current.value;if(!Tt(n)){let r=nt.join(", ");throw Error(E(this.current,`Invalid object operation "${n}". Valid operations: ${r}`))}return this.advance(),this.expect("RIGHT_BRACE"),At(n,t)}parseIdentifierOrFunction(){let t=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([t]);let n=P(t);if(n)return n;return b(t)}parseArrowFunction(t){this.expect("ARROW");let e=this.parseFunctionBody();return gt(t,e)}parseFunctionBody(){if(this.current.type==="LEFT_BRACE"){this.advance();let e=this.parseBinaryExpression();return this.expect("RIGHT_BRACE"),e}return this.parseBinaryExpression()}parseBinaryExpression(){let t=this.parseFunctionTerm();while(this.current.type==="OPERATOR"){let e=this.current.value;this.advance();let n=this.parseFunctionTerm();t=et(`__operator_${e}__`,[n],t)}return t}parseFunctionTerm(){let t=this.current.type;if(t==="IDENTIFIER")return this.parseIdentifierChain();if(t==="NUMBER"){let e=Number(this.current.value);return this.advance(),T(e)}if(t==="STRING"){let e=this.current.value;return this.advance(),T(e)}if(t==="LEFT_PAREN"){this.advance();let e=this.parseBinaryExpression();return this.expect("RIGHT_PAREN"),e}throw Error(E(this.current,"Unexpected token in function body"))}parseIdentifierChain(){let t=this.current.value;this.advance();let e=P(t);if(e)return e;let n=b(t),r=()=>this.current.type==="DOT",s=()=>this.current.type==="IDENTIFIER",o=()=>this.current.type==="LEFT_PAREN";while(r()||o()){if(o()){let a=n,u=a.property,h=a.object;n=this.parseMethodCall(h?h:k(),u);continue}if(this.advance(),!s())break;let i=this.current.value;this.advance(),n=b(i,n)}return n}parseMethodCall(t,e){this.expect("LEFT_PAREN");let n=this.parseMethodArguments();return this.expect("RIGHT_PAREN"),et(e,n,t)}parseMethodArguments(){let t=[];while(this.current.type!=="RIGHT_PAREN"&&this.current.type!=="EOF"){let e=this.parseMethodArgument();if(t.push(e),this.current.type==="COMMA")this.advance()}return t}parseMethodArgument(){let t=this.current.type;if(t==="LEFT_PAREN"){let e=this.parseFunctionParams();return this.parseArrowFunction(e)}if(t==="IDENTIFIER"){let e=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([e]);return b(e)}if(t==="NUMBER"){let e=Number(this.current.value);return this.advance(),T(e)}if(t==="STRING"){let e=this.current.value;return this.advance(),T(e)}return this.parseExpression()}parseFunctionParams(){this.expect("LEFT_PAREN");let t=[];while(this.current.type!=="RIGHT_PAREN"&&this.current.type!=="EOF"){if(this.current.type==="IDENTIFIER")t.push(this.current.value),this.advance();if(this.current.type==="COMMA")this.advance()}return this.expect("RIGHT_PAREN"),t}parsePostfix(t){let e=t;while(!0){let n=this.current.type;if(n==="DOT"){e=this.parsePostfixDot(e);continue}if(n==="LEFT_BRACKET"){e=this.parseBracketAccess(e);continue}if(n==="LEFT_PAREN"){if(e.type==="PropertyAccess"&&!e.object){let o=e.property;e=this.parseMethodCall(k(),o);continue}}break}return e}parsePostfixDot(t){this.advance();let e=this.current.type;if(e==="IDENTIFIER"){let n=this.current.value;if(this.advance(),this.current.type==="LEFT_PAREN")return this.parseMethodCall(t,n);return b(n,t)}if(e==="LEFT_BRACKET")return this.parseBracketAccess(t);if(e==="LEFT_BRACE")return this.parseObjectOperation(t);throw Error(E(this.current,"Expected property name after dot"))}parseNumber(){let t=this.current.value==="-";if(t)this.advance();if(this.current.type!=="NUMBER")throw Error(E(this.current,"Expected number after minus sign"));let n=Number(this.current.value);return t?-n:n}advance(){if(this.position++,this.position<this.tokens.length)this.current=this.tokens[this.position]}expect(t){if(this.current.type!==t)throw Error(E(this.current,`Expected ${t} but got ${this.current.type}`));this.advance()}}var Nt={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,">":(t,e)=>t>e,"<":(t,e)=>t<e,">=":(t,e)=>t>=e,"<=":(t,e)=>t<=e,"==":(t,e)=>t==e,"===":(t,e)=>t===e,"!=":(t,e)=>t!=e,"!==":(t,e)=>t!==e,"&&":(t,e)=>t&&e,"||":(t,e)=>t||e};function rt(t){return t.startsWith("__operator_")&&t.endsWith("__")}function st(t){return t.slice(11,-2)}function ot(t,e,n){let r=Nt[e];if(!r)throw Error(`Unknown operator: ${e}`);return r(t,n)}function Et(t,e){return Object.fromEntries(t.map((n,r)=>[n,e[r]]))}function j(t){return Object.values(t)[0]}function ct(t){return t!==null&&typeof t==="object"}function B(t,e){if(!ct(t))return;return t[e]}function D(t,e){return t<0?e+t:t}function xt(t,e){if(!Array.isArray(t))return;let n=D(e,t.length);return t[n]}function Ot(t,e,n){if(!Array.isArray(t))return;let r=t.length,s=e!==void 0?D(e,r):0,o=n!==void 0?D(n,r):r;return t.slice(s,o)}function vt(t,e){if(!ct(t))return;switch(e){case"keys":return Object.keys(t);case"values":return Object.values(t);case"entries":return Object.entries(t);case"length":return Array.isArray(t)?t.length:Object.keys(t).length}}var bt=(t,e)=>{if(t===null||t===void 0)return!1;return typeof t[e]==="function"},St=(t)=>t instanceof Error?t.message:String(t);function it(t,e,n){if(!bt(t,e))throw Error(`Method ${e} does not exist on ${typeof t}`);try{return t[e].call(t,...n)}catch(s){let o=St(s);throw Error(`Error executing method ${e}: ${o}`)}}class G{options;constructor(t={}){this.options=t}evaluate(t,e){switch(t.type){case"Root":return t.expression?this.evaluate(t.expression,e):e;case"PropertyAccess":return this.evaluatePropertyAccess(t,e);case"IndexAccess":return xt(t.object?this.evaluate(t.object,e):e,t.index);case"SliceAccess":return Ot(t.object?this.evaluate(t.object,e):e,t.start,t.end);case"ArraySpread":return t.object?this.evaluate(t.object,e):e;case"MethodCall":return this.evaluateMethodCall(t,e);case"ObjectOperation":return vt(t.object?this.evaluate(t.object,e):e,t.operation);case"Literal":return t.value;case"ArrowFunction":return this.createFunction(t);default:throw Error(`Unknown AST node type: ${t.type}`)}}evaluatePropertyAccess(t,e){let n=t.object?this.evaluate(t.object,e):e,r=B(n,t.property);if(this.options.strict&&r===void 0){let s=t.property;throw Error(`Property "${s}" is undefined`)}return r}evaluateArg(t,e){return t.type==="ArrowFunction"?this.createFunction(t):this.evaluate(t,e)}evaluateMethodCall(t,e){let n=t.object?this.evaluate(t.object,e):e;if(rt(t.method)){let o=st(t.method),i=this.evaluate(t.args[0],e);return ot(n,o,i)}let s=t.args.map((o)=>this.evaluateArg(o,e));return it(n,t.method,s)}createFunction(t){return(...e)=>{let n=Et(t.params,e);return this.evaluateFunctionBody(t.body,n)}}evaluateFunctionBody(t,e){switch(t.type){case"PropertyAccess":return this.evaluatePropertyAccessInFunction(t,e);case"MethodCall":return this.evaluateMethodCallInFunction(t,e);case"Literal":return t.value;case"Root":return t.expression?this.evaluateFunctionBody(t.expression,e):e;default:return this.evaluate(t,j(e))}}evaluatePropertyAccessInFunction(t,e){if(t.object!==void 0){let o=this.evaluateFunctionBody(t.object,e);return B(o,t.property)}if(Object.prototype.hasOwnProperty.call(e,t.property))return e[t.property];let s=j(e);return B(s,t.property)}evaluateMethodCallInFunction(t,e){let n=t.object?this.evaluateFunctionBody(t.object,e):j(e);if(rt(t.method)){let o=st(t.method),i=this.evaluateFunctionBody(t.args[0],e);return ot(n,o,i)}let s=t.args.map((o)=>this.evaluateFunctionBody(o,e));return it(n,t.method,s)}}var U=[{short:".mp",full:".map",description:"Transform each element",type:"array"},{short:".flt",full:".filter",description:"Filter elements",type:"array"},{short:".rd",full:".reduce",description:"Reduce to single value",type:"array"},{short:".fnd",full:".find",description:"Find first match",type:"array"},{short:".sm",full:".some",description:"Test if any match",type:"array"},{short:".evr",full:".every",description:"Test if all match",type:"array"},{short:".srt",full:".sort",description:"Sort elements",type:"array"},{short:".rvs",full:".reverse",description:"Reverse order",type:"array"},{short:".jn",full:".join",description:"Join to string",type:"array"},{short:".slc",full:".slice",description:"Extract portion",type:"array"},{short:".kys",full:".{keys}",description:"Get object keys",type:"object"},{short:".vls",full:".{values}",description:"Get object values",type:"object"},{short:".ents",full:".{entries}",description:"Get object entries",type:"object"},{short:".len",full:".{length}",description:"Get length/size",type:"object"},{short:".lc",full:".toLowerCase",description:"Convert to lowercase",type:"string"},{short:".uc",full:".toUpperCase",description:"Convert to uppercase",type:"string"},{short:".trm",full:".trim",description:"Remove whitespace",type:"string"},{short:".splt",full:".split",description:"Split string to array",type:"string"},{short:".incl",full:".includes",description:"Check if includes",type:"array"}];var W=(t,e)=>{let r=U.filter((s)=>s.type===t).map((s)=>` ${s.short.padEnd(6)} -> ${s.full.padEnd(14)} ${s.description}`);return`${e}:
|
|
1
|
+
var xe={".":"DOT","[":"LEFT_BRACKET","]":"RIGHT_BRACKET","{":"LEFT_BRACE","}":"RIGHT_BRACE","(":"LEFT_PAREN",")":"RIGHT_PAREN",":":"COLON",",":"COMMA"},Re="+-*/%<>!&|=",we=[" ","\t",`
|
|
2
|
+
`,"\r"];function N(e,t,n){return{type:e,value:t,position:n}}class ${input;position=0;current;constructor(e){this.input=e,this.current=this.input[0]||""}tokenize(){let e=[];while(this.position<this.input.length){if(this.skipWhitespace(),this.position>=this.input.length)break;let t=this.nextToken();if(t)e.push(t)}return e.push(N("EOF","",this.position)),e}nextToken(){let e=this.position;if(this.current==="."&&this.peek()===".")return this.advance(),this.advance(),N("DOUBLE_DOT","..",e);if(this.current==="?"&&this.peek()==="?")return this.advance(),this.advance(),N("DOUBLE_QUESTION","??",e);if(this.current==="?")return this.advance(),N("QUESTION","?",e);let s=xe[this.current];if(s){let m=this.current;return this.advance(),N(s,m,e)}if(this.current==="="&&this.peek()===">")return this.advance(),this.advance(),N("ARROW","=>",e);if(this.current==='"'||this.current==="'")return this.readString();let c=this.isDigit(this.current),a=this.current==="-"&&this.isDigit(this.peek());if(c||a)return this.readNumber();if(this.isIdentifierStart(this.current))return this.readIdentifier();if(this.isOperator(this.current))return this.readOperator();return this.advance(),null}readString(){let e=this.position,t=this.current,n=[];this.advance();while(this.current!==t&&this.position<this.input.length){if(this.current==="\\"){if(this.advance(),this.position<this.input.length)n.push(this.current),this.advance();continue}n.push(this.current),this.advance()}if(this.current===t)this.advance();return N("STRING",n.join(""),e)}readNumber(){let e=this.position,t="";if(this.current==="-")t+=this.current,this.advance();while(this.isDigit(this.current))t+=this.current,this.advance();if(this.current==="."&&this.isDigit(this.peek())){t+=this.current,this.advance();while(this.isDigit(this.current))t+=this.current,this.advance()}return N("NUMBER",t,e)}readIdentifier(){let e=this.position,t="";while(this.isIdentifierChar(this.current))t+=this.current,this.advance();return N("IDENTIFIER",t,e)}readOperator(){let e=this.position,t="";while(this.isOperator(this.current))t+=this.current,this.advance();return N("OPERATOR",t,e)}skipWhitespace(){while(this.isWhitespace(this.current))this.advance()}advance(){this.position++,this.current=this.input[this.position]||""}peek(){return this.input[this.position+1]||""}isWhitespace(e){return we.includes(e)}isDigit(e){return e>="0"&&e<="9"}isIdentifierStart(e){let t=e>="a"&&e<="z",n=e>="A"&&e<="Z";return t||n||e==="_"||e==="$"}isIdentifierChar(e){return this.isIdentifierStart(e)||this.isDigit(e)}isOperator(e){return Re.includes(e)}}var x=["keys","values","entries","length"];var T=(e)=>({type:"Literal",value:e}),Q=(e)=>{if(e==="true")return T(!0);if(e==="false")return T(!1);if(e==="null")return T(null);return},y=(e,t)=>`${t} at position ${e.position} (got ${e.type}: "${e.value}")`,E=(e,t)=>({type:"PropertyAccess",property:e,object:t}),Y=(e,t)=>({type:"IndexAccess",index:e,object:t}),J=(e,t,n)=>({type:"SliceAccess",start:e,end:t,object:n}),k=(e,t,n)=>({type:"MethodCall",method:e,args:t,object:n}),z=(e,t)=>({type:"ObjectOperation",operation:e,object:t}),X=(e)=>({type:"ArraySpread",object:e}),q=(e,t)=>({type:"ArrowFunction",params:e,body:t}),O=(e)=>({type:"Root",expression:e}),C=(e)=>({type:"RecursiveDescent",object:e}),Z=(e,t)=>({type:"OptionalAccess",expression:e,object:t}),ee=(e,t)=>({type:"NullCoalescing",left:e,right:t}),te=(e)=>x.includes(e);class ne{tokens;position=0;current;constructor(e){this.tokens=e,this.current=this.tokens[0]}parse(){if(this.current.type==="EOF")return O();let t=this.parseExpression();return O(t)}parseExpression(){return this.parsePrimary()}parsePrimary(){let e=this.parsePrimaryNode();return this.parsePostfix(e)}parsePrimaryNode(){let e=this.current.type;if(e==="DOUBLE_DOT")return this.advance(),C();if(e==="DOT"){if(this.advance(),this.current.type==="EOF")return O();return this.parseAccessChain()}if(e==="LEFT_BRACKET")return this.parseArrayAccess();if(e==="IDENTIFIER")return this.parseIdentifierOrFunction();if(e==="STRING"){let s=this.current.value;return this.advance(),T(s)}if(e==="NUMBER"){let s=Number(this.current.value);return this.advance(),T(s)}if(e==="LEFT_PAREN"){let s=this.parseFunctionParams();return this.parseArrowFunction(s)}throw Error(y(this.current,"Unexpected token"))}parseAccessChain(e){let t=this.current.type;if(t==="IDENTIFIER"){let n=this.current.value;return this.advance(),E(n,e)}if(t==="LEFT_BRACKET")return this.parseBracketAccess(e);if(t==="LEFT_BRACE")return this.parseObjectOperation(e);throw Error(y(this.current,"Expected property name after dot"))}parseBracketAccess(e){if(this.advance(),this.current.type==="RIGHT_BRACKET")return this.advance(),X(e);if(this.current.type==="STRING"){let c=this.current.value;return this.advance(),this.expect("RIGHT_BRACKET"),E(c,e)}let r=this.current.type==="NUMBER",s=this.current.type==="OPERATOR"&&this.current.value==="-",o=this.current.type==="COLON";if(r||s||o)return this.parseNumericIndexOrSlice(e);throw Error(y(this.current,"Unexpected token in bracket access"))}parseNumericIndexOrSlice(e){if(this.current.type==="COLON")return this.parseSliceFromColon(void 0,e);let n=this.parseNumber();if(this.advance(),this.current.type==="COLON")return this.parseSliceFromColon(n,e);return this.expect("RIGHT_BRACKET"),Y(n,e)}parseSliceFromColon(e,t){this.advance();let n=this.current.type==="NUMBER",r=this.current.type==="OPERATOR"&&this.current.value==="-",s=n||r,o=s?this.parseNumber():void 0;if(s)this.advance();return this.expect("RIGHT_BRACKET"),J(e,o,t)}parseArrayAccess(){return this.parseBracketAccess()}parseObjectOperation(e){if(this.advance(),this.current.type!=="IDENTIFIER")throw Error(y(this.current,"Expected operation name after {"));let n=this.current.value;if(!te(n)){let r=x.join(", ");throw Error(y(this.current,`Invalid object operation "${n}". Valid operations: ${r}`))}return this.advance(),this.expect("RIGHT_BRACE"),z(n,e)}parseIdentifierOrFunction(){let e=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([e]);let n=Q(e);if(n)return n;return E(e)}parseArrowFunction(e){this.expect("ARROW");let t=this.parseFunctionBody();return q(e,t)}parseFunctionBody(){if(this.current.type==="LEFT_BRACE"){this.advance();let t=this.parseBinaryExpression();return this.expect("RIGHT_BRACE"),t}return this.parseBinaryExpression()}parseBinaryExpression(){let e=this.parseFunctionTerm();while(this.current.type==="OPERATOR"){let t=this.current.value;this.advance();let n=this.parseFunctionTerm();e=k(`__operator_${t}__`,[n],e)}return e}parseFunctionTerm(){let e=this.current.type;if(e==="IDENTIFIER")return this.parseIdentifierChain();if(e==="NUMBER"){let t=Number(this.current.value);return this.advance(),T(t)}if(e==="STRING"){let t=this.current.value;return this.advance(),T(t)}if(e==="LEFT_PAREN"){this.advance();let t=this.parseBinaryExpression();return this.expect("RIGHT_PAREN"),t}throw Error(y(this.current,"Unexpected token in function body"))}parseIdentifierChain(){let e=this.current.value;this.advance();let t=Q(e);if(t)return t;let n=E(e),r=()=>this.current.type==="DOT",s=()=>this.current.type==="IDENTIFIER",o=()=>this.current.type==="LEFT_PAREN";while(r()||o()){if(o()){let c=n,a=c.property,l=c.object;n=this.parseMethodCall(l?l:O(),a);continue}if(this.advance(),!s())break;let i=this.current.value;this.advance(),n=E(i,n)}return n}parseMethodCall(e,t){this.expect("LEFT_PAREN");let n=this.parseMethodArguments();return this.expect("RIGHT_PAREN"),k(t,n,e)}parseMethodArguments(){let e=[];while(this.current.type!=="RIGHT_PAREN"&&this.current.type!=="EOF"){let t=this.parseMethodArgument();if(e.push(t),this.current.type==="COMMA")this.advance()}return e}parseMethodArgument(){let e=this.current.type;if(e==="LEFT_PAREN"){let t=this.parseFunctionParams();return this.parseArrowFunction(t)}if(e==="IDENTIFIER"){let t=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([t]);return E(t)}if(e==="NUMBER"){let t=Number(this.current.value);return this.advance(),T(t)}if(e==="STRING"){let t=this.current.value;return this.advance(),T(t)}return this.parseExpression()}parseFunctionParams(){this.expect("LEFT_PAREN");let e=[];while(this.current.type!=="RIGHT_PAREN"&&this.current.type!=="EOF"){if(this.current.type==="IDENTIFIER")e.push(this.current.value),this.advance();if(this.current.type==="COMMA")this.advance()}return this.expect("RIGHT_PAREN"),e}parsePostfix(e){let t=e;while(!0){let n=this.current.type;if(n==="DOUBLE_DOT"){this.advance(),t=C(t);continue}if(n==="DOT"){t=this.parsePostfixDot(t);continue}if(n==="LEFT_BRACKET"){t=this.parseBracketAccess(t);continue}if(n==="QUESTION"){this.advance(),t=Z(t);continue}if(n==="DOUBLE_QUESTION"){this.advance();let l=this.parsePrimary();t=ee(t,l);continue}if(n==="LEFT_PAREN"){if(t.type==="PropertyAccess"&&!t.object){let d=t.property;t=this.parseMethodCall(O(),d);continue}}break}return t}parsePostfixDot(e){this.advance();let t=this.current.type;if(t==="IDENTIFIER"){let n=this.current.value;if(this.advance(),this.current.type==="LEFT_PAREN")return this.parseMethodCall(e,n);return E(n,e)}if(t==="LEFT_BRACKET")return this.parseBracketAccess(e);if(t==="LEFT_BRACE")return this.parseObjectOperation(e);throw Error(y(this.current,"Expected property name after dot"))}parseNumber(){let e=this.current.value==="-";if(e)this.advance();if(this.current.type!=="NUMBER")throw Error(y(this.current,"Expected number after minus sign"));let n=Number(this.current.value);return e?-n:n}advance(){if(this.position++,this.position<this.tokens.length)this.current=this.tokens[this.position]}expect(e){if(this.current.type!==e)throw Error(y(this.current,`Expected ${e} but got ${this.current.type}`));this.advance()}}var L=Symbol("empty"),u={PIPE:"pipe",COMPOSE:"compose",HEAD:"head",LAST:"last",TAIL:"tail",TAKE:"take",DROP:"drop",UNIQ:"uniq",FLATTEN:"flatten",REVERSE:"rev",GROUPBY:"groupBy",SORTBY:"sortBy",CHUNK:"chunk",COMPACT:"compact",PICK:"pick",OMIT:"omit",KEYS:"keys",VALUES:"vals",MERGE:"merge",DEEPMERGE:"deepMerge",FROMPAIRS:"fromPairs",TOPAIRS:"toPairs",SUM:"sum",MEAN:"mean",MIN:"min",MAX:"max",LEN:"len",COUNT:"count",ISEMPTY:"isEmpty",ISNIL:"isNil",IDENTITY:"id",PLUCK:"pluck",TYPE:"type",RANGE:"range",HAS:"has",NTH:"nth",CONTAINS:"contains",ADD:"add",PATH:"path",GETPATH:"getpath",SETPATH:"setpath",RECURSE:"recurse",SPLIT:"split",JOIN:"join",STARTSWITH:"startswith",ENDSWITH:"endswith",LTRIMSTR:"ltrimstr",RTRIMSTR:"rtrimstr",TOSTRING:"tostring",TONUMBER:"tonumber",FLOOR:"floor",CEIL:"ceil",ROUND:"round",ABS:"abs",NOT:"not",SELECT:"select",EMPTY:"empty",ERROR:"error",DEBUG:"debug"};var p=(e)=>Array.isArray(e),f=(e)=>e!==null&&typeof e==="object"&&!Array.isArray(e),R=(e)=>e===null||e===void 0,A=(e)=>typeof e==="string",b=(e)=>typeof e==="number",ve=(e)=>{if(e===null)return"null";if(p(e))return"array";return typeof e},re=(e,t)=>Object.keys(t).reduce((n,r)=>{let s=e[r],o=t[r],i=f(s)&&f(o);return{...n,[r]:i?re(s,o):o}},{...e}),P=(e,t)=>{if(e===t)return!0;if(p(e)&&p(t))return t.every((s)=>e.some((o)=>P(o,s)));if(f(e)&&f(t)){let s=e;return Object.entries(t).every(([o,i])=>(o in s)&&P(s[o],i))}return!1},Ie=(e,t)=>t.reduce((n,r)=>{if(R(n))return;if(p(n)&&typeof r==="number")return n[r];if(f(n)&&typeof r==="string")return n[r];return},e),se=(e,t,n)=>{if(t.length===0)return n;let[r,...s]=t,o=s.length===0?n:se(p(e)&&typeof r==="number"?e[r]:f(e)&&typeof r==="string"?e[r]:void 0,s,n);if(p(e)&&typeof r==="number")return e.map((i,c)=>c===r?o:i);if(f(e)&&typeof r==="string")return{...e,[r]:o};if(typeof r==="number")return Array.from({length:r+1},(i,c)=>c===r?o:void 0);return{[r]:o}},M=(e)=>{let t=[e],n=p(e)?e.flatMap(M):f(e)?Object.values(e).flatMap(M):[];return[...t,...n]},F=(e,t)=>{let n=[t];if(p(e)){let r=e.flatMap((s,o)=>F(s,[...t,o]));return[...n,...r]}if(f(e)){let r=Object.keys(e).flatMap((s)=>F(e[s],[...t,s]));return[...n,...r]}return n};var ke={[u.HEAD]:(e)=>p(e)?e[0]:void 0,[u.LAST]:(e)=>p(e)?e[e.length-1]:void 0,[u.TAIL]:(e)=>p(e)?e.slice(1):[],[u.TAKE]:(e,[t])=>p(e)?e.slice(0,t):[],[u.DROP]:(e,[t])=>p(e)?e.slice(t):[],[u.UNIQ]:(e)=>p(e)?[...new Set(e)]:[],[u.FLATTEN]:(e)=>p(e)?e.flat(1/0):[],[u.REVERSE]:(e)=>p(e)?[...e].reverse():[],[u.GROUPBY]:(e,[t])=>{if(!p(e))return{};let n=t;return e.reduce((r,s)=>{let o=String(n(s)),i=r[o]||[];return{...r,[o]:[...i,s]}},{})},[u.SORTBY]:(e,[t])=>{if(!p(e))return[];let n=t;return[...e].sort((r,s)=>{let o=n(r),i=n(s),c=o<i,a=o>i;if(c)return-1;if(a)return 1;return 0})},[u.CHUNK]:(e,[t])=>{if(!p(e))return[];let n=t,r=Math.ceil(e.length/n);return Array.from({length:r},(s,o)=>e.slice(o*n,(o+1)*n))},[u.COMPACT]:(e)=>p(e)?e.filter(Boolean):[],[u.PLUCK]:(e,[t])=>{if(!p(e))return[];return e.map((n)=>f(n)?n[t]:void 0)},[u.PICK]:(e,t)=>{if(!f(e))return{};return(t.length===1&&p(t[0])?t[0]:t).reduce((s,o)=>{let i=o;return i in e?{...s,[i]:e[i]}:s},{})},[u.OMIT]:(e,t)=>{if(!f(e))return{};let r=t.length===1&&p(t[0])?t[0]:t,s=new Set(r);return Object.fromEntries(Object.entries(e).filter(([o])=>!s.has(o)))},[u.KEYS]:(e)=>f(e)?Object.keys(e):[],[u.VALUES]:(e)=>f(e)?Object.values(e):[],[u.MERGE]:(e,t)=>{if(!f(e))return{};return t.reduce((n,r)=>{return{...n,...r}},e)},[u.DEEPMERGE]:(e,t)=>{if(!f(e))return{};return t.reduce((n,r)=>{return f(r)?re(n,r):n},e)},[u.FROMPAIRS]:(e)=>{if(!p(e))return{};return Object.fromEntries(e)},[u.TOPAIRS]:(e)=>f(e)?Object.entries(e):[],[u.SUM]:(e)=>{if(!p(e))return 0;return e.reduce((t,n)=>t+n,0)},[u.MEAN]:(e)=>{if(!p(e)||e.length===0)return 0;return e.reduce((r,s)=>r+s,0)/e.length},[u.MIN]:(e)=>{if(!p(e))return;return Math.min(...e)},[u.MAX]:(e)=>{if(!p(e))return;return Math.max(...e)},[u.LEN]:(e)=>{if(p(e))return e.length;if(f(e))return Object.keys(e).length;if(A(e))return e.length;return 0},[u.COUNT]:(e)=>{if(p(e))return e.length;if(f(e))return Object.keys(e).length;if(A(e))return e.length;return 0},[u.ISEMPTY]:(e)=>{if(R(e))return!0;if(p(e))return e.length===0;if(f(e))return Object.keys(e).length===0;if(A(e))return e.length===0;return!1},[u.ISNIL]:(e)=>R(e),[u.IDENTITY]:(e)=>e,[u.TYPE]:(e)=>ve(e),[u.RANGE]:(e,t)=>{let[n,r,s=1]=t,o=r===void 0,i=o?0:n,c=o?n:r,a=s,l=Math.max(0,Math.ceil((c-i)/a));return Array.from({length:l},(h,d)=>i+d*a)},[u.HAS]:(e,[t])=>{if(f(e))return t in e;if(p(e)){let n=t;return n>=0&&n<e.length}return!1},[u.NTH]:(e,[t])=>{if(!p(e))return;let n=t,s=n<0?e.length+n:n;return e[s]},[u.CONTAINS]:(e,[t])=>P(e,t),[u.ADD]:(e)=>{if(!p(e))return e;if(e.length===0)return null;let n=A(e[0]),r=p(e[0]);if(n)return e.join("");if(r)return e.flat();return e.reduce((s,o)=>s+o,0)},[u.PATH]:(e)=>F(e,[]),[u.GETPATH]:(e,[t])=>Ie(e,t),[u.SETPATH]:(e,[t,n])=>se(e,t,n),[u.RECURSE]:(e)=>M(e),[u.SPLIT]:(e,[t])=>{if(!A(e))return[];let n=t;return e.split(n)},[u.JOIN]:(e,[t])=>{if(!p(e))return"";let n=t;return e.join(n)},[u.STARTSWITH]:(e,[t])=>{if(!A(e))return!1;let n=t;return e.startsWith(n)},[u.ENDSWITH]:(e,[t])=>{if(!A(e))return!1;let n=t;return e.endsWith(n)},[u.LTRIMSTR]:(e,[t])=>{if(!A(e))return e;let n=t;return e.startsWith(n)?e.slice(n.length):e},[u.RTRIMSTR]:(e,[t])=>{if(!A(e))return e;let n=t;return e.endsWith(n)?e.slice(0,-n.length):e},[u.TOSTRING]:(e)=>{if(A(e))return e;if(R(e))return String(e);return JSON.stringify(e)},[u.TONUMBER]:(e)=>{if(b(e))return e;if(A(e)){let t=Number(e);return!Number.isNaN(t)?t:null}return null},[u.FLOOR]:(e)=>b(e)?Math.floor(e):null,[u.CEIL]:(e)=>b(e)?Math.ceil(e):null,[u.ROUND]:(e)=>b(e)?Math.round(e):null,[u.ABS]:(e)=>b(e)?Math.abs(e):null,[u.NOT]:(e)=>!e,[u.SELECT]:(e,[t])=>{return t(e)?e:L},[u.EMPTY]:()=>L,[u.ERROR]:(e,[t])=>{throw Error(t||"error")},[u.DEBUG]:(e)=>{return console.error("DEBUG:",e),e}},Ce=(e)=>(e in ke),Le=(e,t,n)=>{let r=ke[e];if(!r)throw Error(`Unknown builtin: ${e}`);return r(t,n)};var oe={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t)=>e%t,">":(e,t)=>e>t,"<":(e,t)=>e<t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t,"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,"&&":(e,t)=>e&&t,"||":(e,t)=>e||t};var j=(e)=>e.startsWith("__operator_")&&e.endsWith("__"),D=(e)=>e.slice(11,-2),B=(e,t,n)=>{let r=oe[t];if(!r)throw Error(`Unknown operator: ${t}`);return r(e,n)},ie=(e,t)=>Object.fromEntries(e.map((n,r)=>[n,t[r]])),w=(e)=>{return Object.values(e)[0]},ce=(e)=>e!==null&&typeof e==="object",v=(e,t)=>{if(!ce(e))return;return e[t]},_=(e,t)=>e<0?t+e:e,ue=(e,t)=>{if(!Array.isArray(e))return;let n=_(t,e.length);return e[n]},ae=(e,t,n)=>{if(!Array.isArray(e))return;let r=e.length,s=t!==void 0?_(t,r):0,o=n!==void 0?_(n,r):r;return e.slice(s,o)},le=(e,t)=>{if(!ce(e))return;switch(t){case"keys":return Object.keys(e);case"values":return Object.values(e);case"entries":return Object.entries(e);case"length":return Array.isArray(e)?e.length:Object.keys(e).length}};var Qe=(e,t)=>{if(e===null||e===void 0)return!1;return typeof e[t]==="function"},Ye=(e)=>e instanceof Error?e.message:String(e),V=(e,t,n)=>{if(!Qe(e,t))throw Error(`Method ${t} does not exist on ${typeof e}`);try{return e[t].call(e,...n)}catch(s){let o=Ye(s);throw Error(`Error executing method ${t}: ${o}`)}};class pe{options;constructor(e={}){this.options=e}evaluate(e,t){switch(e.type){case"Root":return e.expression?this.evaluate(e.expression,t):t;case"PropertyAccess":return this.evaluatePropertyAccess(e,t);case"IndexAccess":return ue(e.object?this.evaluate(e.object,t):t,e.index);case"SliceAccess":return ae(e.object?this.evaluate(e.object,t):t,e.start,e.end);case"ArraySpread":return e.object?this.evaluate(e.object,t):t;case"MethodCall":return this.evaluateMethodCall(e,t);case"ObjectOperation":return le(e.object?this.evaluate(e.object,t):t,e.operation);case"Literal":return e.value;case"ArrowFunction":return this.createFunction(e);case"RecursiveDescent":return this.evaluateRecursiveDescent(e,t);case"OptionalAccess":return this.evaluateOptionalAccess(e,t);case"NullCoalescing":return this.evaluateNullCoalescing(e,t);default:throw Error(`Unknown AST node type: ${e.type}`)}}evaluatePropertyAccess(e,t){let n=e.object?this.evaluate(e.object,t):t,r=v(n,e.property);if(this.options.strict&&r===void 0){let s=e.property;throw Error(`Property "${s}" is undefined`)}return r}evaluateArg(e,t){return e.type==="ArrowFunction"?this.createFunction(e):this.evaluate(e,t)}evaluateMethodCall(e,t){if(e.method===u.PIPE)return this.evaluatePipe(e.args,t);if(e.method===u.COMPOSE)return this.evaluatePipe([...e.args].reverse(),t);let n=e.object?this.evaluate(e.object,t):t;if(Ce(e.method)){let o=e.args.map((i)=>this.evaluateArg(i,t));return Le(e.method,n,o)}if(j(e.method)){let o=D(e.method),i=this.evaluate(e.args[0],t);return B(n,o,i)}let s=e.args.map((o)=>this.evaluateArg(o,t));return V(n,e.method,s)}evaluatePipe(e,t){return e.reduce((n,r)=>this.evaluate(r,n),t)}evaluateRecursiveDescent(e,t){let n=e.object?this.evaluate(e.object,t):t;return this.collectAllValues(n)}collectAllValues(e,t=[]){if(t.push(e),Array.isArray(e))e.forEach((n)=>this.collectAllValues(n,t));else if(e!==null&&typeof e==="object")Object.values(e).forEach((n)=>this.collectAllValues(n,t));return t}evaluateOptionalAccess(e,t){try{return this.evaluate(e.expression,t)}catch{return null}}evaluateNullCoalescing(e,t){let n=this.evaluate(e.left,t);return n===null||n===void 0?this.evaluate(e.right,t):n}createFunction(e){return(...t)=>{let n=ie(e.params,t);return this.evaluateFunctionBody(e.body,n)}}evaluateFunctionBody(e,t){switch(e.type){case"PropertyAccess":return this.evaluatePropertyAccessInFunction(e,t);case"MethodCall":return this.evaluateMethodCallInFunction(e,t);case"Literal":return e.value;case"Root":return e.expression?this.evaluateFunctionBody(e.expression,t):t;default:return this.evaluate(e,w(t))}}evaluatePropertyAccessInFunction(e,t){if(e.object!==void 0){let o=this.evaluateFunctionBody(e.object,t);return v(o,e.property)}if(Object.prototype.hasOwnProperty.call(t,e.property))return t[e.property];let s=w(t);return v(s,e.property)}evaluateMethodCallInFunction(e,t){let n=e.object?this.evaluateFunctionBody(e.object,t):w(t);if(j(e.method)){let o=D(e.method),i=this.evaluateFunctionBody(e.args[0],t);return B(n,o,i)}let s=e.args.map((o)=>this.evaluateFunctionBody(o,t));return V(n,e.method,s)}}var de=[{short:".mp",full:".map",description:"Transform each element",type:"array"},{short:".flt",full:".filter",description:"Filter elements",type:"array"},{short:".rd",full:".reduce",description:"Reduce to single value",type:"array"},{short:".fnd",full:".find",description:"Find first match",type:"array"},{short:".sm",full:".some",description:"Test if any match",type:"array"},{short:".evr",full:".every",description:"Test if all match",type:"array"},{short:".srt",full:".sort",description:"Sort elements",type:"array"},{short:".rvs",full:".reverse",description:"Reverse order",type:"array"},{short:".jn",full:".join",description:"Join to string",type:"array"},{short:".slc",full:".slice",description:"Extract portion",type:"array"},{short:".kys",full:".{keys}",description:"Get object keys",type:"object"},{short:".vls",full:".{values}",description:"Get object values",type:"object"},{short:".ents",full:".{entries}",description:"Get object entries",type:"object"},{short:".len",full:".{length}",description:"Get length/size",type:"object"},{short:".lc",full:".toLowerCase",description:"Convert to lowercase",type:"string"},{short:".uc",full:".toUpperCase",description:"Convert to uppercase",type:"string"},{short:".trm",full:".trim",description:"Remove whitespace",type:"string"},{short:".splt",full:".split",description:"Split string to array",type:"string"},{short:".incl",full:".includes",description:"Check if includes",type:"array"}];var he=(e,t)=>{let r=de.filter((s)=>s.type===e).map((s)=>` ${s.short.padEnd(6)} -> ${s.full.padEnd(14)} ${s.description}`);return`${t}:
|
|
3
3
|
${r.join(`
|
|
4
|
-
`)}`},
|
|
4
|
+
`)}`},cn=`Expression Shortcuts:
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${he("array","Array Methods")}
|
|
7
7
|
|
|
8
|
-
${
|
|
8
|
+
${he("object","Object Methods")}
|
|
9
9
|
|
|
10
|
-
${
|
|
11
|
-
`;var
|
|
12
|
-
`):
|
|
13
|
-
`),n={},
|
|
14
|
-
`);if(n.length===0)return[];let r=
|
|
15
|
-
`),n={},r=n,s=[];return
|
|
10
|
+
${he("string","String Methods")}
|
|
11
|
+
`;var Pe=/[.*+?^${}()|[\]\\]/g,fe=de;var Je=/^-?\d+$/,ze=/^[+-]?\d+$/,Xe=/^-?\d+\.\d+$/,qe=/^[+-]?\d+\.\d+$/;var me={INTEGER:Je,FLOAT:Xe},ge={INTEGER:ze,FLOAT:qe};var Ze=["true","yes","on"],et=["false","no","off"],tt=["null","~",""],nt=(e)=>Ze.includes(e),rt=(e)=>et.includes(e),st=(e)=>tt.includes(e),U=(e)=>{if(nt(e))return!0;if(rt(e))return!1;return},G=(e)=>{if(st(e))return null;return},Me=(e)=>{if(e==="")return;let t=Number(e);return isNaN(t)?void 0:t};var H=(e)=>e.length-e.trimStart().length,ot=(e)=>(e.match(/["']/g)||[]).length,it=(e,t)=>{let n=e.substring(0,t);return ot(n)%2===0},I=(e)=>{let t=e.indexOf("#");if(t<0)return e;return it(e,t)?e.substring(0,t):e},Ae=(e)=>["|",">","|+",">-","|-",">+"].includes(e),ye=(e)=>e==="---"||e==="...",Ne=(e)=>e.startsWith("- ")||e==="-",Fe=(e)=>e==="-"?"":e.substring(2).trim(),_e=(e)=>{let t=e.indexOf(":");if(t<=0)return!1;let n=e.substring(0,t),r=!n.includes(" "),s=n.startsWith('"')||n.startsWith("'");return r||s},Te=(e)=>{let t=e.indexOf(":");if(t<=0)return null;return{key:e.substring(0,t).trim(),value:e.substring(t+1).trim()}},je=(e)=>{if(!e.startsWith("&"))return{anchorName:null,cleanValue:e};let n=e.indexOf(" ");return n>0?{anchorName:e.substring(1,n),cleanValue:e.substring(n+1)}:{anchorName:e.substring(1),cleanValue:""}},De=(e)=>{if(!e.includes(" &"))return{cleanKey:e,anchorName:null};let[n,r]=e.split(" &");return{cleanKey:n,anchorName:r}},ct=(e)=>{if(!e.startsWith("!!"))return{tag:null,content:e};let n=e.indexOf(" ");if(!(n>0))return{tag:null,content:e};return{tag:e.substring(2,n),content:e.substring(n+1)}},ut=(e)=>{let t=e.startsWith('"')&&e.endsWith('"'),n=e.startsWith("'")&&e.endsWith("'");return t||n?e.slice(1,-1):null},at=(e)=>{if(!(e.startsWith("[")&&e.endsWith("]")))return null;return e.slice(1,-1).split(",").map((n)=>S(n.trim()))},lt=(e)=>{if(!(e.startsWith("{")&&e.endsWith("}")))return null;return e.slice(1,-1).split(",").map((n)=>n.split(":").map((r)=>r.trim())).filter(([n,r])=>n&&r).reduce((n,[r,s])=>({...n,[r]:S(s)}),{})},S=(e)=>{let{tag:t,content:n}=ct(e);if(t==="str")return n;let r=ut(n);if(r!==null)return r;let s=U(n);if(s!==void 0)return s;let o=G(n);if(o!==void 0)return o;if(me.INTEGER.test(n))return parseInt(n,10);if(me.FLOAT.test(n))return parseFloat(n);let a=at(n);if(a!==null)return a;let l=lt(n);if(l!==null)return l;return n},Ee=(e,t)=>Array.from({length:t},(n,r)=>t-1-r).reduce((n,r)=>{if(n!==null)return n;let o=I(e[r]).trim();if(!o||o.startsWith("-")||!o.includes(":"))return null;let c=Te(o);if(!c)return null;return!c.value||Ae(c.value)?c.key:null},null),Be=(e,t,n)=>{let r=e.slice(t).reduce((o,i,c)=>{if(o.done)return o;if(!i.trim())return{...o,contentLines:[...o.contentLines,""],endIdx:t+c};if(H(i)<=n)return{...o,done:!0};let h=i.substring(n+2);return{...o,contentLines:[...o.contentLines,h],endIdx:t+c}},{contentLines:[],endIdx:t-1,done:!1});return{contentLines:r.contentLines.reduceRight((o,i)=>o.length===0&&i===""?o:[i,...o],[]),endIdx:r.endIdx}},Ve=(e,t)=>t==="|"?e.join(`
|
|
12
|
+
`):e.join(" ").replace(/\s+/g," ").trim();var pt=(e,t)=>{let n=e.substring(1);return t[n]!==void 0?t[n]:e},ht=(e,t)=>{let n=e.substring(1),r=t[n];return typeof r==="object"&&r!==null&&!Array.isArray(r)?r:null},Oe=(e,t)=>{if(typeof e==="string"&&e.startsWith("*"))return pt(e,t);if(Array.isArray(e))return e.map((s)=>Oe(s,t));if(!(typeof e==="object"&&e!==null))return e;return Object.entries(e).reduce((s,[o,i])=>{let c=o==="<<",a=typeof i==="string"&&i.startsWith("*");if(!(c&&a))return{...s,[o]:Oe(i,t)};let h=ht(i,t);return h?{...s,...h}:s},{})},dt=(e)=>e.find((t)=>{let n=I(t).trim();return n&&!ye(n)}),ft=(e)=>{return dt(e)?.trim().startsWith("- ")?[]:{}},W=(e)=>e[e.length-1],Ge=(e,t)=>{while(e.length>1&&t(W(e)))e.pop()},Ue=(e,t,n,r,s)=>{if(_e(e)){let c=e.indexOf(":"),a=e.substring(0,c).trim(),l=e.substring(c+1).trim(),{cleanKey:h,anchorName:d}=De(a),m=l?S(l):null,g={[h]:m};if(t.push(g),d)s[d]=g;n.push({container:g,indent:r+2});return}if(e){t.push(S(e));return}let i={};t.push(i),n.push({container:i,indent:r+2})},mt=(e,t,n,r,s,o)=>{let i=Fe(e);Ge(s,(h)=>h.indent>t||h.indent>=t&&!Array.isArray(h.container));let c=W(s);if(Array.isArray(c.container)&&(c.indent===t||c.indent===-1&&t===0)){if(c.indent===-1)c.indent=t;Ue(i,c.container,s,t,o);return}let l=[];if(c.pendingKey)c.container[c.pendingKey]=l,c.pendingKey=void 0;else if(!Array.isArray(c.container)){let h=Ee(n,r);if(h)c.container[h]=l}s.push({container:l,indent:t}),Ue(i,l,s,t,o)},gt=(e,t,n,r,s,o,i,c)=>{let a=n.startsWith("|")?"|":">",{contentLines:l,endIdx:h}=Be(r,s+1,o),d=Ve(l,a);if(e[t]=d,c)i[c]=d;return h},At=(e,t,n,r,s,o,i,c)=>{let a=W(o),l=r+1,h=l<n.length,d=h?I(n[l]):"",m=d.trim(),g=h?H(d):-1,Ke=Ne(m)&&g>s,$e=h&&g>s&&m;if(Ke){if(a.pendingKey=t,c)i[c]={};return}if($e){let K={};if(e[t]=K,c)i[c]=K;o.push({container:K,indent:g});return}if(e[t]=null,c)i[c]=null},yt=(e,t,n,r,s,o)=>{let i=Te(e);if(!i)return r;let{anchorName:c,cleanValue:a}=je(i.value);Ge(s,(d)=>d.indent>t||d.indent===t&&Array.isArray(d.container));let l=W(s).container;if(Array.isArray(l))return r;if(Ae(a))return gt(l,i.key,a,n,r,t,o,c);if(a){let d=S(a);if(l[i.key]=d,c)o[c]=d;return r}return At(l,i.key,n,r,t,s,o,c),r},Nt=(e)=>{let t=e.trim().split(`
|
|
13
|
+
`),n={},r=ft(t),s=[{container:r,indent:-1}],o=0;while(o<t.length){let i=I(t[o]),c=i.trim();if(!c||ye(c)){o++;continue}let l=H(i);if(Ne(c)){mt(c,l,t,o,s,n),o++;continue}o=yt(c,l,t,o,s,n)+1}return Oe(r,n)};function He(e,t){let n=[],r="",s=!1,o=e.split("");return o.forEach((i,c)=>{let a=o[c+1];if(i==='"'){if(s&&a==='"'){r+='"',o.splice(c+1,1);return}s=!s;return}if(i===t&&!s){n.push(r),r="";return}r+=i}),n.push(r),n.map((i)=>i.trim())}function Tt(e){let t=e.trim();if(t.startsWith('"')&&t.endsWith('"'))return t.slice(1,-1).replace(/""/g,'"');let r=Me(t);if(r!==void 0)return r;let s=t.toLowerCase(),o=U(s);if(o!==void 0)return o;let i=G(s);if(i!==void 0)return i;return t}function Et(e,t=","){let n=e.trim().split(`
|
|
14
|
+
`);if(n.length===0)return[];let r=He(n[0],t);if(n.length===1)return[];return n.slice(1).reduce((s,o)=>{let i=He(o,t);if(i.length===0)return s;let c=Object.fromEntries(r.map((a,l)=>[a,Tt(i[l]||"")]));return[...s,c]},[])}function Se(e){if(e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1).replace(/\\"/g,'"');if(e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;if(ge.INTEGER.test(e))return parseInt(e,10);if(ge.FLOAT.test(e))return parseFloat(e);if(e.startsWith("[")&&e.endsWith("]"))return e.slice(1,-1).split(",").map((a)=>Se(a.trim()));if(e.startsWith("{")&&e.endsWith("}")){let c={};return e.slice(1,-1).split(",").forEach((l)=>{let[h,d]=l.split("=").map((m)=>m.trim());if(h&&d)c[h]=Se(d)}),c}return e}function Ot(e){let t=e.trim().split(`
|
|
15
|
+
`),n={},r=n,s=[];return t.forEach((o)=>{let i=o,c=i.indexOf("#");if(c>=0){let m=i.substring(0,c);if((m.match(/["']/g)||[]).length%2===0)i=m}let a=i.trim();if(!a)return;if(a.startsWith("[")&&a.endsWith("]")){let m=a.slice(1,-1).split(".");r=n,s=[],m.forEach((g)=>{if(!r[g])r[g]={};r=r[g],s.push(g)});return}let h=a.indexOf("=");if(h>0){let m=a.substring(0,h).trim(),g=a.substring(h+1).trim();r[m]=Se(g)}}),n}function We(e){return e.replace(Pe,"\\$&")}var St=fe.map((e)=>({regex:new RegExp(`${We(e.short)}(?![a-zA-Z])`,"g"),replacement:e.full})).sort((e,t)=>t.replacement.length-e.replacement.length),bt=fe.map((e)=>({regex:new RegExp(`${We(e.full)}(?![a-zA-Z])`,"g"),replacement:e.short})).sort((e,t)=>t.regex.source.length-e.regex.source.length);function xt(e){return St.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function kn(e){return bt.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function Cn(e,t){let n=xt(t),s=new $(n).tokenize(),i=new ne(s).parse();return new pe().evaluate(i,e)}export{kn as shortenExpression,Nt as parseYAML,Ot as parseTOML,Et as parseCSV,xt as expandShortcuts,Cn as evaluate,We as escapeRegExp,$ as Lexer,pe as JsonNavigator,ne as ExpressionParser};
|
package/dist/cli/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataFormat } from "../
|
|
1
|
+
import { DataFormat } from "../formats/types";
|
|
2
2
|
import { CliOptions } from "../types";
|
|
3
3
|
export declare const VALID_OUTPUT_FORMATS: readonly ["json", "yaml", "csv", "table"];
|
|
4
4
|
export declare const VALID_INPUT_FORMATS: DataFormat[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { DataFormat } from "
|
|
1
|
+
import type { DataFormat } from "../formats/types";
|
|
2
2
|
export declare function processInput(format?: DataFormat): Promise<unknown>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
# Bash completion for 1ls
|
|
3
2
|
|
|
4
3
|
_1ls_complete() {
|
|
5
4
|
local cur prev opts
|
|
@@ -7,17 +6,11 @@ _1ls_complete() {
|
|
|
7
6
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
8
7
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
opts="--help --version --raw --pretty --compact --type --format --list --grep --find --recursive --ignore-case --line-numbers --ext --max-depth --shortcuts --shorten --expand readFile"
|
|
12
|
-
|
|
13
|
-
# Format options
|
|
9
|
+
opts="--help -h --version -v --raw -r --pretty -p --compact -c --type -t --format --input-format -if --detect --list -l --grep -g --find -f --recursive -R --ignore-case -i --line-numbers -n --ext --max-depth --shortcuts --shorten --expand --strict -s --slurp -S --null-input -N --interactive readFile"
|
|
14
10
|
format_opts="json yaml csv table"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# Common shorthand methods
|
|
20
|
-
shortcuts=".mp .flt .rd .fnd .sm .evr .srt .rvs .jn .kys .vls .ents .lc .uc .trm"
|
|
11
|
+
json_paths=". .[] .. .{keys} .{values} .{entries} .foo? .foo ?? default"
|
|
12
|
+
shortcuts=".mp .flt .rd .fnd .fndIdx .sm .evr .srt .rvs .jn .slc .splt .psh .pp .shft .unshft .fltMap .flt1 .incl .idxOf .kys .vls .ents .len .lc .uc .trm .trmSt .trmEnd .rpl .rplAll .pdSt .pdEnd .stsWith .endsWith .sbstr .chr .chrCd .mtch .str .json .val"
|
|
13
|
+
builtin_fns="pipe compose head last tail take drop uniq flatten rev groupBy sortBy chunk compact pick omit keys vals merge deepMerge fromPairs toPairs sum mean min max len count isEmpty isNil id pluck type range has nth contains add path getpath setpath recurse split join startswith endswith ltrimstr rtrimstr tostring tonumber floor ceil round abs not select empty error debug hd lst tl tk drp unq fltn grpBy srtBy chnk cmpct pk omt ks mrg dMrg frPrs toPrs avg cnt emp nil plk typ rng hs ctns pth gpth spth rec spl jn stw edw ltrm rtrm tstr tnum flr cl rnd sel dbg"
|
|
21
14
|
|
|
22
15
|
case "${prev}" in
|
|
23
16
|
--format)
|
|
@@ -25,17 +18,14 @@ _1ls_complete() {
|
|
|
25
18
|
return 0
|
|
26
19
|
;;
|
|
27
20
|
--list|--find|readFile)
|
|
28
|
-
# File/directory completion
|
|
29
21
|
COMPREPLY=( $(compgen -f -- ${cur}) )
|
|
30
22
|
return 0
|
|
31
23
|
;;
|
|
32
24
|
--ext)
|
|
33
|
-
# Common extensions
|
|
34
25
|
COMPREPLY=( $(compgen -W "js ts tsx jsx json md txt yml yaml xml html css" -- ${cur}) )
|
|
35
26
|
return 0
|
|
36
27
|
;;
|
|
37
28
|
--shorten|--expand)
|
|
38
|
-
# JSON expressions
|
|
39
29
|
COMPREPLY=( $(compgen -W "${json_paths}" -- ${cur}) )
|
|
40
30
|
return 0
|
|
41
31
|
;;
|
|
@@ -43,21 +33,23 @@ _1ls_complete() {
|
|
|
43
33
|
;;
|
|
44
34
|
esac
|
|
45
35
|
|
|
46
|
-
# If current word starts with -, show options
|
|
47
36
|
if [[ ${cur} == -* ]]; then
|
|
48
37
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
|
49
38
|
return 0
|
|
50
39
|
fi
|
|
51
40
|
|
|
52
|
-
# If current word starts with ., suggest JSON paths and shortcuts
|
|
53
41
|
if [[ ${cur} == .* ]]; then
|
|
54
42
|
all_paths="${json_paths} ${shortcuts}"
|
|
55
43
|
COMPREPLY=( $(compgen -W "${all_paths}" -- ${cur}) )
|
|
56
44
|
return 0
|
|
57
45
|
fi
|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
if [[ ${cur} =~ ^[a-zA-Z] ]]; then
|
|
48
|
+
COMPREPLY=( $(compgen -W "${builtin_fns}" -- ${cur}) )
|
|
49
|
+
return 0
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
COMPREPLY=( $(compgen -W "${opts} ${builtin_fns}" -- ${cur}) )
|
|
61
53
|
}
|
|
62
54
|
|
|
63
|
-
complete -F _1ls_complete 1ls
|
|
55
|
+
complete -F _1ls_complete 1ls
|