1ls 0.1.12 → 0.1.13

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 (61) hide show
  1. package/README.md +277 -11
  2. package/dist/browser/constants.d.ts +1 -1
  3. package/dist/browser/index.js +11 -11
  4. package/dist/cli/constants.d.ts +1 -1
  5. package/dist/{utils → cli}/stream.d.ts +1 -1
  6. package/dist/completions/1ls.bash +10 -18
  7. package/dist/completions/1ls.zsh +69 -7
  8. package/dist/{shared/constants.d.ts → constants.d.ts} +1 -1
  9. package/dist/expression/constants.d.ts +2 -0
  10. package/dist/expression/index.d.ts +3 -12
  11. package/dist/expression/utils.d.ts +14 -1
  12. package/dist/file/constants.d.ts +4 -0
  13. package/dist/file/filters.d.ts +7 -0
  14. package/dist/file/grep.d.ts +10 -0
  15. package/dist/file/index.d.ts +7 -0
  16. package/dist/file/info.d.ts +4 -0
  17. package/dist/file/io.d.ts +5 -0
  18. package/dist/{utils → file}/types.d.ts +0 -17
  19. package/dist/file/walk.d.ts +4 -0
  20. package/dist/formats/index.d.ts +1 -1
  21. package/dist/formats/types.d.ts +1 -0
  22. package/dist/formats/yaml/index.d.ts +2 -0
  23. package/dist/formats/yaml/types.d.ts +8 -0
  24. package/dist/formats/yaml/utils.d.ts +28 -0
  25. package/dist/index.js +82 -65
  26. package/dist/interactive/builder/constants.d.ts +14 -0
  27. package/dist/interactive/{builder.d.ts → builder/index.d.ts} +1 -1
  28. package/dist/interactive/builder/types.d.ts +4 -0
  29. package/dist/interactive/builder/utils.d.ts +7 -0
  30. package/dist/interactive/methods/constants.d.ts +10 -0
  31. package/dist/interactive/methods/index.d.ts +4 -0
  32. package/dist/interactive/methods/types.d.ts +8 -0
  33. package/dist/interactive/preview/constants.d.ts +4 -0
  34. package/dist/interactive/preview/index.d.ts +5 -0
  35. package/dist/interactive/preview/types.d.ts +6 -0
  36. package/dist/interactive/tooltip/constants.d.ts +3 -0
  37. package/dist/interactive/tooltip/index.d.ts +20 -0
  38. package/dist/interactive/tooltip/types.d.ts +13 -0
  39. package/dist/interactive/types.d.ts +5 -7
  40. package/dist/{utils/logger.d.ts → logger.d.ts} +10 -1
  41. package/dist/navigator/builtins/constants.d.ts +62 -0
  42. package/dist/navigator/builtins/index.d.ts +6 -0
  43. package/dist/navigator/builtins/types.d.ts +3 -0
  44. package/dist/navigator/builtins/utils.d.ts +12 -0
  45. package/dist/navigator/json/constants.d.ts +2 -0
  46. package/dist/navigator/json/index.d.ts +22 -0
  47. package/dist/navigator/json/types.d.ts +3 -0
  48. package/dist/navigator/json/utils.d.ts +14 -0
  49. package/dist/shortcuts/constants.d.ts +15 -0
  50. package/dist/shortcuts/index.d.ts +9 -0
  51. package/dist/shortcuts/types.d.ts +6 -0
  52. package/dist/types.d.ts +21 -2
  53. package/dist/version.d.ts +1 -1
  54. package/package.json +3 -1
  55. package/dist/formats/yaml.d.ts +0 -3
  56. package/dist/interactive/methods.d.ts +0 -12
  57. package/dist/navigator/json.d.ts +0 -31
  58. package/dist/utils/constants.d.ts +0 -12
  59. package/dist/utils/file.d.ts +0 -27
  60. package/dist/utils/index.d.ts +0 -7
  61. package/dist/utils/shortcuts.d.ts +0 -8
package/README.md CHANGED
@@ -6,18 +6,17 @@
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
  [![GitHub](https://img.shields.io/badge/GitHub-repo-blue)](https://github.com/yowainwright/1ls)
8
8
 
9
- > One-line script
9
+ > Minimal syntax. Maximum formats.
10
10
 
11
- A 0 dependency, lightweight, fast data processor with familiar JavaScript syntax.
11
+ ```bash
12
+ # full
13
+ echo '[1,2,3]' | 1ls '.filter(x => x > 1).map(x => x * 2)'
12
14
 
13
- This is useful for writing 1ls, one-line scripts, in the terminal or for short scripts
14
- that are as concise as possible in a familiar syntax, JavaScript, with dot notation,
15
- fuzzy matching, and shortening capabilities for maximum efficiency.
15
+ # shortened
16
+ echo '[1,2,3]' | 1ls '.fl(x => x > 1).mp(x => x * 2)'
17
+ ```
16
18
 
17
- On top of that, the library is very small because it has no dependencies.
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
@@ -287,6 +349,8 @@ echo '["a", "b"]' | 1ls '.jn(",")' # Short for .join()
287
349
  | `--pretty` | `-p` | Pretty print output (default) |
288
350
  | `--compact` | `-c` | Compact single-line output |
289
351
  | `--type` | `-t` | Show type of result |
352
+ | `--slurp` | `-S` | Read all inputs into an array |
353
+ | `--null-input` | `-N` | Use null as input (for generating data) |
290
354
 
291
355
  ### Format Options
292
356
 
@@ -326,6 +390,25 @@ echo '["a", "b"]' | 1ls '.jn(",")' # Short for .join()
326
390
  - `.[start:end]` - Array slice
327
391
  - `.[]` - Array spread
328
392
 
393
+ ### jq-compatible Operators
394
+ - `..` - Recursive descent (collect all nested values)
395
+ - `.foo?` - Optional access (returns null on error instead of failing)
396
+ - `.foo ?? default` - Null coalescing (provide fallback for null/undefined)
397
+
398
+ ```bash
399
+ # Recursive descent - get all values from nested structure
400
+ echo '{"a": {"b": 1}, "c": [2, 3]}' | 1ls '..'
401
+ # Output: [{"a": {"b": 1}, "c": [2, 3]}, {"b": 1}, 1, [2, 3], 2, 3]
402
+
403
+ # Optional access - safe navigation
404
+ echo '{"user": null}' | 1ls '.user?.name'
405
+ # Output: null (instead of error)
406
+
407
+ # Null coalescing - default values
408
+ echo '{"name": null}' | 1ls '.name ?? "anonymous"'
409
+ # Output: "anonymous"
410
+ ```
411
+
329
412
  ### Object Operations
330
413
  - `.{keys}` - Get object keys
331
414
  - `.{values}` - Get object values
@@ -351,6 +434,97 @@ All standard JavaScript array methods are supported:
351
434
  - `.substring()`, `.charAt()`
352
435
  - `.match()`, `.split()`
353
436
 
437
+ ### Builtin Functions (jq-compatible)
438
+
439
+ **Array Operations:**
440
+ - `head()` / `hd()` - First element
441
+ - `last()` / `lst()` - Last element
442
+ - `tail()` / `tl()` - All but first element
443
+ - `take(n)` / `tk(n)` - Take first n elements
444
+ - `drop(n)` / `drp(n)` - Drop first n elements
445
+ - `uniq()` / `unq()` - Remove duplicates
446
+ - `flatten()` / `fltn()` - Flatten nested arrays
447
+ - `rev()` - Reverse array
448
+ - `chunk(n)` / `chnk(n)` - Split into chunks of size n
449
+ - `compact()` / `cmpct()` - Remove falsy values
450
+ - `nth(n)` - Get element at index n
451
+ - `add()` - Sum numbers or concatenate arrays/strings
452
+
453
+ **Object Operations:**
454
+ - `keys()` / `ks()` - Get object keys
455
+ - `vals()` - Get object values
456
+ - `pick(k1, k2, ...)` / `pk()` - Pick specific keys
457
+ - `omit(k1, k2, ...)` / `omt()` - Omit specific keys
458
+ - `merge(obj)` / `mrg()` - Shallow merge objects
459
+ - `deepMerge(obj)` / `dMrg()` - Deep merge objects
460
+ - `fromPairs()` / `frPrs()` - Convert pairs to object
461
+ - `toPairs()` / `toPrs()` - Convert object to pairs
462
+ - `has(key)` / `hs()` - Check if key exists
463
+ - `pluck(key)` / `plk()` - Extract property from array of objects
464
+
465
+ **Grouping & Sorting:**
466
+ - `groupBy(fn)` / `grpBy()` - Group by key function
467
+ - `sortBy(fn)` / `srtBy()` - Sort by key function
468
+
469
+ **Math & Aggregation:**
470
+ - `sum()` - Sum of numbers
471
+ - `mean()` / `avg()` - Average of numbers
472
+ - `min()` - Minimum value
473
+ - `max()` - Maximum value
474
+ - `floor()` / `flr()` - Floor number
475
+ - `ceil()` / `cl()` - Ceiling number
476
+ - `round()` / `rnd()` - Round number
477
+ - `abs()` - Absolute value
478
+
479
+ **String Operations:**
480
+ - `split(sep)` / `spl()` - Split string by separator
481
+ - `join(sep)` / `jn()` - Join array with separator
482
+ - `startswith(s)` / `stw()` - Check if starts with string
483
+ - `endswith(s)` / `edw()` - Check if ends with string
484
+ - `ltrimstr(s)` / `ltrm()` - Remove prefix
485
+ - `rtrimstr(s)` / `rtrm()` - Remove suffix
486
+ - `tostring()` / `tstr()` - Convert to string
487
+ - `tonumber()` / `tnum()` - Convert to number
488
+
489
+ **Type & Inspection:**
490
+ - `type()` / `typ()` - Get value type
491
+ - `len()` - Get length
492
+ - `count()` / `cnt()` - Count items
493
+ - `isEmpty()` / `emp()` - Check if empty
494
+ - `isNil()` / `nil()` - Check if null/undefined
495
+ - `contains(val)` / `ctns()` - Check if contains value
496
+
497
+ **Path Operations:**
498
+ - `path()` / `pth()` - Get all paths in structure
499
+ - `getpath(path)` / `gpth()` - Get value at path
500
+ - `setpath(path)` / `spth()` - Set value at path
501
+ - `recurse()` / `rec()` - Recursively collect all values
502
+
503
+ **Control Flow:**
504
+ - `select(fn)` / `sel()` - Filter by predicate (jq-style)
505
+ - `empty()` - Return nothing
506
+ - `error(msg)` - Throw error
507
+ - `debug()` / `dbg()` - Debug output
508
+ - `not()` - Boolean negation
509
+ - `range(n)` / `rng()` - Generate range [0, n)
510
+
511
+ **Composition:**
512
+ - `pipe(expr1, expr2, ...)` - Apply expressions left-to-right
513
+ - `compose(expr1, expr2, ...)` - Apply expressions right-to-left
514
+ - `id()` - Identity function
515
+
516
+ ```bash
517
+ # Builtin examples
518
+ echo '[1, 2, 3, 4, 5]' | 1ls 'head()' # 1
519
+ echo '[1, 2, 3, 4, 5]' | 1ls 'take(3)' # [1, 2, 3]
520
+ echo '[1, 2, 2, 3]' | 1ls 'uniq()' # [1, 2, 3]
521
+ echo '{"a": 1, "b": 2}' | 1ls 'keys()' # ["a", "b"]
522
+ echo '[1, 2, 3]' | 1ls 'sum()' # 6
523
+ echo '"hello"' | 1ls 'split("")' # ["h", "e", "l", "l", "o"]
524
+ echo '42' | 1ls 'type()' # "number"
525
+ echo 'null' | 1ls 'range(5)' # [0, 1, 2, 3, 4]
526
+ ```
527
+
354
528
  ### Arrow Functions
355
529
  Full support for arrow functions in method calls:
356
530
  ```bash
@@ -453,13 +627,105 @@ MIT © Jeff Wainwright
453
627
  | Feature | 1ls | jq | fx |
454
628
  |---------|-----|----|----|
455
629
  | Syntax | JavaScript | DSL | JavaScript |
456
- | Performance | ⚡ Fast (Bun) | Fast | 🚀 Good |
630
+ | Implementation | Bun/TS | C | Go |
457
631
  | Learning Curve | Easy | Steep | Easy |
458
- | Multi-format | ✓ | x | x |
632
+ | Multi-format | ✓ (12+) | x | (JSON/YAML/TOML) |
633
+ | Auto-detect Format | ✓ | x | x |
459
634
  | Interactive Mode | ✓ | x | ✓ |
460
635
  | Shortcuts | ✓ | x | x |
461
636
  | Arrow Functions | ✓ | x | ✓ |
462
637
  | File Operations | ✓ | x | x |
638
+ | jq Builtins | ✓ | ✓ | x |
639
+ | Recursive Descent (`..`) | ✓ | ✓ | x |
640
+ | Null Coalescing (`??`) | ✓ | ✓ | x |
641
+
642
+ <!-- BENCHMARKS:START -->
643
+
644
+ ## Benchmarks
645
+
646
+ Comparing 1ls with jq and fx across various operations and data sizes.
647
+
648
+ - **Runs per test:** 5
649
+ - **Data sizes:** 1000, 10000, 100000 records
650
+ - **Environment:** Docker (debian:bookworm-slim)
651
+
652
+ ### Summary
653
+
654
+ | Tool | Avg Time (ms) | vs 1ls |
655
+ |------|---------------|--------|
656
+ | **1ls** | **0.62** | **1x** |
657
+ | jq | 103.17 | 166x slower |
658
+ | fx | 171.61 | 276x slower |
659
+
660
+ **1ls is 166x faster than jq and 276x faster than fx on average.**
661
+
662
+ Lower is better. Times in milliseconds (ms).
663
+
664
+ ### Basic Operations (ms)
665
+
666
+ | Operation | Size | jq | fx | 1ls |
667
+ |-----------|------|----|----|-----|
668
+ | First element | 1000 | 21.26 | 7.79 | 0.60 |
669
+ | Length | 1000 | 21.26 | 6.91 | 0.53 |
670
+ | Last element | 1000 | 46.02 | 7.67 | 0.47 |
671
+ | First element | 10000 | 32.22 | 41.50 | 0.47 |
672
+ | Length | 10000 | 31.58 | 38.55 | 0.47 |
673
+ | Last element | 10000 | 31.16 | 39.53 | 0.50 |
674
+ | First element | 100000 | 158.56 | 382.21 | 0.64 |
675
+ | Length | 100000 | 188.74 | 351.79 | 0.56 |
676
+ | Last element | 100000 | 159.04 | 355.60 | 0.52 |
677
+
678
+ ### Filter & Map (ms)
679
+
680
+ | Operation | Size | jq | fx | 1ls |
681
+ |-----------|------|----|----|-----|
682
+ | Filter | 1000 | 20.73 | 9.49 | 0.47 |
683
+ | Map | 1000 | 19.28 | 5.89 | 0.43 |
684
+ | Filter+Map | 1000 | 19.78 | 6.28 | 0.54 |
685
+ | Filter | 10000 | 47.02 | 65.21 | 0.48 |
686
+ | Map | 10000 | 34.35 | 44.06 | 0.53 |
687
+ | Filter+Map | 10000 | 37.52 | 44.58 | 0.56 |
688
+ | Filter | 100000 | 294.43 | 824.56 | 0.68 |
689
+ | Map | 100000 | 208.42 | 395.50 | 0.76 |
690
+ | Filter+Map | 100000 | 208.05 | 401.71 | 0.54 |
691
+
692
+ ### Aggregation (ms)
693
+
694
+ | Operation | Size | jq | fx | 1ls |
695
+ |-----------|------|----|----|-----|
696
+ | Sum | 1000 | 20.90 | 6.21 | 0.59 |
697
+ | Min | 1000 | 20.66 | 7.21 | 0.61 |
698
+ | Max | 1000 | 20.90 | 7.37 | 0.57 |
699
+ | Sum | 10000 | 36.98 | 43.53 | 0.46 |
700
+ | Min | 10000 | 35.86 | 44.54 | 0.54 |
701
+ | Max | 10000 | 36.44 | 44.45 | 0.71 |
702
+ | Sum | 100000 | 227.80 | 397.98 | 0.65 |
703
+ | Min | 100000 | 205.29 | 396.93 | 0.50 |
704
+ | Max | 100000 | 194.16 | 388.88 | 0.49 |
705
+
706
+ ### Builtin Functions (ms)
707
+
708
+ | Operation | Size | jq | fx | 1ls |
709
+ |-----------|------|----|----|-----|
710
+ | head() | 1000 | 19.93 | 6.55 | 0.49 |
711
+ | last() | 1000 | 19.88 | 5.92 | 0.46 |
712
+ | take(10) | 1000 | 19.97 | 5.62 | 0.44 |
713
+ | uniq() | 1000 | 20.79 | 8.34 | 0.42 |
714
+ | flatten() | 1000 | 21.53 | 9.90 | 0.46 |
715
+ | head() | 10000 | 31.34 | 40.23 | 0.48 |
716
+ | last() | 10000 | 31.81 | 38.05 | 0.54 |
717
+ | take(10) | 10000 | 31.00 | 37.69 | 0.46 |
718
+ | uniq() | 10000 | 47.00 | 61.05 | 0.48 |
719
+ | flatten() | 10000 | 52.07 | 88.38 | 0.62 |
720
+ | head() | 100000 | 171.62 | 353.11 | 0.49 |
721
+ | last() | 100000 | 158.29 | 359.10 | 0.59 |
722
+ | take(10) | 100000 | 151.69 | 351.13 | 0.49 |
723
+ | uniq() | 100000 | 355.20 | 576.73 | 0.53 |
724
+ | flatten() | 100000 | 370.08 | 760.43 | 0.51 |
725
+
726
+ Run `bun run test:bench` to regenerate benchmarks.
727
+
728
+ <!-- BENCHMARKS:END -->
463
729
 
464
730
  ## Troubleshooting
465
731
 
@@ -1,3 +1,3 @@
1
- import type { ShortcutMapping } from "../utils/types";
1
+ import type { ShortcutMapping } from "../shortcuts";
2
2
  export declare const REGEX_SPECIAL_CHARS: RegExp;
3
3
  export declare const SHORTCUTS: ShortcutMapping[];
@@ -1,15 +1,15 @@
1
- var q={".":"DOT","[":"LEFT_BRACKET","]":"RIGHT_BRACKET","{":"LEFT_BRACE","}":"RIGHT_BRACE","(":"LEFT_PAREN",")":"RIGHT_PAREN",":":"COLON",",":"COMMA"},Z="+-*/%<>!&|=",tt=[" ","\t",`
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){let t=Array.isArray(e),n=e!==null&&typeof e==="object"&&!t,r=[e];if(t){let s=e.flatMap((o)=>this.collectAllValues(o));return[...r,...s]}if(n){let s=Object.values(e).flatMap((o)=>this.collectAllValues(o));return[...r,...s]}return r}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
- `)}`},Ne=`Expression Shortcuts:
4
+ `)}`},cn=`Expression Shortcuts:
5
5
 
6
- ${W("array","Array Methods")}
6
+ ${he("array","Array Methods")}
7
7
 
8
- ${W("object","Object Methods")}
8
+ ${he("object","Object Methods")}
9
9
 
10
- ${W("string","String Methods")}
11
- `;var at=/[.*+?^${}()|[\]\\]/g,V=U;var wt=/^-?\d+$/,Rt=/^[+-]?\d+$/,kt=/^-?\d+\.\d+$/,It=/^[+-]?\d+\.\d+$/;var $={INTEGER:wt,FLOAT:kt},H={INTEGER:Rt,FLOAT:It};var Ct=["true","yes","on"],Ft=["false","no","off"],Lt=["null","~",""],_t=(t)=>Ct.includes(t),Pt=(t)=>Ft.includes(t),Mt=(t)=>Lt.includes(t),C=(t)=>{if(_t(t))return!0;if(Pt(t))return!1;return},F=(t)=>{if(Mt(t))return null;return},ut=(t)=>{if(t==="")return;let e=Number(t);return isNaN(e)?void 0:e};function jt(t){if(t.startsWith("!!")){let e=t.indexOf(" ");if(e>0)return{tag:t.substring(2,e),content:t.substring(e+1)}}return{tag:null,content:t}}function I(t){let{tag:e,content:n}=jt(t);if(e==="str")return n;let r=n.startsWith('"')&&n.endsWith('"'),s=n.startsWith("'")&&n.endsWith("'");if(r||s)return n.slice(1,-1);let i=C(n);if(i!==void 0)return i;let a=F(n);if(a!==void 0)return a;if($.INTEGER.test(n))return parseInt(n,10);if($.FLOAT.test(n))return parseFloat(n);if(n.startsWith("[")&&n.endsWith("]"))return n.slice(1,-1).split(",").map((c)=>I(c.trim()));if(n.startsWith("{")&&n.endsWith("}")){let c={};return n.slice(1,-1).split(",").forEach((J)=>{let[S,y]=J.split(":").map((p)=>p.trim());if(S&&y)c[S]=I(y)}),c}return n}function Bt(t,e){return Array.from({length:e},(r,s)=>e-1-s).reduce((r,s)=>{if(r!==null)return r;let o=t[s],i=o.indexOf("#");if(i>=0){let f=o.substring(0,i);if((f.match(/["']/g)||[]).length%2===0)o=f}let u=o.trim();if(u&&!u.startsWith("-")&&u.includes(":")){let f=u.indexOf(":"),g=u.substring(0,f).trim(),c=u.substring(f+1).trim();if(!c||c==="|"||c===">"||c==="|+"||c===">-")return g}return null},null)}function K(t){let e=t.indexOf("#");if(e<0)return t;let n=t.substring(0,e);return(n.match(/["']/g)||[]).length%2===0?n:t}function Dt(t){let e=t.indexOf(":");if(e<=0)return!1;let n=t.substring(0,e);return!n.includes(" ")||n.startsWith('"')||n.startsWith("'")}function Q(t){return t.length-t.trimStart().length}function Gt(t,e,n,r){let s=[],o=e;while(o<t.length){let a=t[o];if(!a.trim()){s.push(""),o++;continue}if(Q(a)<=n)break;s.push(a.substring(n+2)),o++}while(s.length>0&&s[s.length-1]==="")s.pop();return{value:r==="|"?s.join(`
12
- `):s.join(" ").replace(/\s+/g," ").trim(),endIdx:o-1}}function Y(t,e){if(typeof t==="string"&&t.startsWith("*")){let n=t.substring(1);return e[n]!==void 0?e[n]:t}if(Array.isArray(t))return t.map((n)=>Y(n,e));if(typeof t==="object"&&t!==null){let n={};for(let[r,s]of Object.entries(t))if(r==="<<"&&typeof s==="string"&&s.startsWith("*")){let o=s.substring(1),i=e[o];if(typeof i==="object"&&i!==null&&!Array.isArray(i))Object.assign(n,i)}else n[r]=Y(s,e);return n}return t}function Wt(t){let e=t.trim().split(`
13
- `),n={},o=e.find((h)=>{let f=K(h).trim();return f&&f!=="---"&&f!=="..."})?.trim().startsWith("- ")?[]:{},i=[{container:o,indent:-1}];function a(){return i[i.length-1]}function u(h){while(i.length>1&&h(a()))i.pop()}for(let h=0;h<e.length;h++){let f=e[h],g=K(f),c=g.trim();if(!c||c==="---"||c==="...")continue;let d=Q(g);if(c.startsWith("- ")||c==="-"){let y=c==="-"?"":c.substring(2).trim();u((A)=>A.indent>d||A.indent>=d&&!Array.isArray(A.container));let l,p=a();if(Array.isArray(p.container)&&(p.indent===d||p.indent===-1&&d===0)){if(l=p.container,p.indent===-1)p.indent=d}else{if(l=[],p.pendingKey)p.container[p.pendingKey]=l,p.pendingKey=void 0;else if(!Array.isArray(p.container)){let A=Bt(e,h);if(A)p.container[A]=l}i.push({container:l,indent:d})}if(Dt(y)){let A=y.indexOf(":"),m=y.substring(0,A).trim(),N=y.substring(A+1).trim(),x=null;if(m.includes(" &")){let w=m.split(" &");m=w[0],x=w[1]}let O={[m]:N?I(N):null};if(l.push(O),x)n[x]=O;i.push({container:O,indent:d+2})}else if(y)l.push(I(y));else{let A={};l.push(A),i.push({container:A,indent:d+2})}continue}let S=c.indexOf(":");if(S>0){let y=c.substring(0,S).trim(),l=c.substring(S+1).trim(),p=null;if(l.startsWith("&")){let m=l.indexOf(" ");if(m>0)p=l.substring(1,m),l=l.substring(m+1);else p=l.substring(1),l=""}u((m)=>m.indent>d||m.indent===d&&Array.isArray(m.container));let L=a(),A=L.container;if(Array.isArray(A))continue;if(l==="|"||l===">"||l==="|+"||l===">-"||l==="|-"||l===">+"){let m=l.startsWith("|")?"|":">",{value:N,endIdx:x}=Gt(e,h+1,d,m);if(A[y]=N,p)n[p]=N;h=x}else if(l){let m=I(l);if(A[y]=m,p)n[p]=m}else{let m=h+1,N=m<e.length,x=N?K(e[m]):"",O=x.trim(),w=N?Q(x):-1,ht=O.startsWith("- ")||O==="-",dt=N&&w>d&&O;if(ht&&w>d){if(L.pendingKey=y,p){let R={};n[p]=R}}else if(dt){let R={};if(A[y]=R,p)n[p]=R;i.push({container:R,indent:w})}else if(A[y]=null,p)n[p]=null}}}return Y(o,n)}function pt(t,e){let n=[],r="",s=!1,o=t.split("");return o.forEach((i,a)=>{let u=o[a+1];if(i==='"'){if(s&&u==='"'){r+='"',o.splice(a+1,1);return}s=!s;return}if(i===e&&!s){n.push(r),r="";return}r+=i}),n.push(r),n.map((i)=>i.trim())}function Ut(t){let e=t.trim();if(e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1).replace(/""/g,'"');let r=ut(e);if(r!==void 0)return r;let s=e.toLowerCase(),o=C(s);if(o!==void 0)return o;let i=F(s);if(i!==void 0)return i;return e}function Vt(t,e=","){let n=t.trim().split(`
14
- `);if(n.length===0)return[];let r=pt(n[0],e);if(n.length===1)return[];return n.slice(1).reduce((s,o)=>{let i=pt(o,e);if(i.length===0)return s;let a=Object.fromEntries(r.map((u,h)=>[u,Ut(i[h]||"")]));return[...s,a]},[])}function z(t){if(t.startsWith('"')&&t.endsWith('"'))return t.slice(1,-1).replace(/\\"/g,'"');if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t==="true")return!0;if(t==="false")return!1;if(H.INTEGER.test(t))return parseInt(t,10);if(H.FLOAT.test(t))return parseFloat(t);if(t.startsWith("[")&&t.endsWith("]"))return t.slice(1,-1).split(",").map((u)=>z(u.trim()));if(t.startsWith("{")&&t.endsWith("}")){let a={};return t.slice(1,-1).split(",").forEach((h)=>{let[f,g]=h.split("=").map((c)=>c.trim());if(f&&g)a[f]=z(g)}),a}return t}function $t(t){let e=t.trim().split(`
15
- `),n={},r=n,s=[];return e.forEach((o)=>{let i=o,a=i.indexOf("#");if(a>=0){let c=i.substring(0,a);if((c.match(/["']/g)||[]).length%2===0)i=c}let u=i.trim();if(!u)return;if(u.startsWith("[")&&u.endsWith("]")){let c=u.slice(1,-1).split(".");r=n,s=[],c.forEach((d)=>{if(!r[d])r[d]={};r=r[d],s.push(d)});return}let f=u.indexOf("=");if(f>0){let c=u.substring(0,f).trim(),d=u.substring(f+1).trim();r[c]=z(d)}}),n}function lt(t){return t.replace(at,"\\$&")}var Ht=V.map((t)=>({regex:new RegExp(`${lt(t.short)}(?![a-zA-Z])`,"g"),replacement:t.full})).sort((t,e)=>e.replacement.length-t.replacement.length),Kt=V.map((t)=>({regex:new RegExp(`${lt(t.full)}(?![a-zA-Z])`,"g"),replacement:t.short})).sort((t,e)=>e.regex.source.length-t.regex.source.length);function Qt(t){return Ht.reduce((e,{regex:n,replacement:r})=>e.replace(n,r),t)}function Ge(t){return Kt.reduce((e,{regex:n,replacement:r})=>e.replace(n,r),t)}function We(t,e){let n=Qt(e),s=new _(n).tokenize(),i=new M(s).parse();return new G().evaluate(i,t)}export{Ge as shortenExpression,Wt as parseYAML,$t as parseTOML,Vt as parseCSV,Qt as expandShortcuts,We as evaluate,lt as escapeRegExp,_ as Lexer,G as JsonNavigator,M as ExpressionParser};
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};
@@ -1,4 +1,4 @@
1
- import { DataFormat } from "../utils/types";
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 "./types";
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
- # Main options
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 --version --raw --pretty --compact --type --format --list --grep --find --recursive --ignore-case --line-numbers --ext --max-depth --shortcuts --shorten --expand --slurp --null-input readFile"
14
10
  format_opts="json yaml csv table"
15
-
16
- # Common JSON path starters
17
- json_paths=". .[] .{keys} .{values} .{entries}"
18
-
19
- # Common shorthand methods
11
+ json_paths=". .[] .. .{keys} .{values} .{entries}"
20
12
  shortcuts=".mp .flt .rd .fnd .sm .evr .srt .rvs .jn .kys .vls .ents .lc .uc .trm"
13
+ builtins="head hd last lst tail tl take tk drop drp uniq unq flatten fltn rev groupBy grpBy sortBy srtBy chunk chnk compact cmpct pick pk omit omt keys ks vals merge mrg deepMerge dMrg fromPairs frPrs toPairs toPrs sum mean avg min max len count cnt isEmpty emp isNil nil pluck plk pipe compose id type typ range rng has hs nth contains ctns add path pth getpath gpth setpath spth recurse rec split spl join jn startswith stw endswith edw ltrimstr ltrm rtrimstr rtrm tostring tstr tonumber tnum floor flr ceil cl round rnd abs not select sel empty error debug 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
- # Default to options
60
- COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
47
+ if [[ ${cur} =~ ^[a-zA-Z] ]]; then
48
+ COMPREPLY=( $(compgen -W "${builtins}" -- ${cur}) )
49
+ return 0
50
+ fi
51
+
52
+ COMPREPLY=( $(compgen -W "${opts} ${builtins}" -- ${cur}) )
61
53
  }
62
54
 
63
- complete -F _1ls_complete 1ls
55
+ complete -F _1ls_complete 1ls