1ls 0.0.3 → 0.1.1
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/LICENSE +21 -0
- package/README.md +22 -7
- package/dist/browser/constants.d.ts +3 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.js +15 -0
- package/dist/cli/constants.d.ts +2 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/formats/constants.d.ts +19 -0
- package/dist/formats/ini.d.ts +3 -0
- package/dist/formats/javascript.d.ts +6 -0
- package/dist/formats/json5.d.ts +6 -0
- package/dist/formatter/colors.d.ts +18 -0
- package/dist/index.js +84 -80
- package/dist/interactive/renderer.d.ts +1 -0
- package/dist/interactive/terminal.d.ts +3 -1
- package/dist/navigator/json.d.ts +1 -0
- package/dist/shared/constants.d.ts +6 -0
- package/dist/types.d.ts +1 -0
- package/package.json +29 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jeff Wainwright
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
# 1ls
|
|
1
|
+
# 1ls
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/yowainwright/1ls/actions/workflows/ci.yml)
|
|
4
|
+
[](https://codecov.io/gh/yowainwright/1ls)
|
|
5
|
+
|
|
6
|
+
> One-line script
|
|
7
|
+
|
|
8
|
+
A 0 dependency, lightweight, fast data processor with familiar JavaScript syntax.
|
|
9
|
+
|
|
10
|
+
This is useful for writing 1ls, one-line scripts, in the terminal or for short scripts
|
|
11
|
+
that are as concise as possible in a familiar syntax, JavaScript, with dot notation,
|
|
12
|
+
fuzzy matching, and shortening capabilities for maximum efficiency.
|
|
13
|
+
|
|
14
|
+
On top of that, the library is very small because it has no dependencies.
|
|
15
|
+
And, it is compiled with QuickJs for binary builds.
|
|
16
|
+
This means you get good speed compared to jq and fx but it's still, just JS,
|
|
17
|
+
the language y'all know.
|
|
4
18
|
|
|
5
19
|
## Why 1ls?
|
|
6
20
|
|
|
@@ -14,14 +28,15 @@ A 0 dependency, lightweight, fast data processor with familiar JavaScript syntax
|
|
|
14
28
|
## Installation
|
|
15
29
|
|
|
16
30
|
```bash
|
|
17
|
-
# Using
|
|
18
|
-
|
|
31
|
+
# Using bun (or npm, pnpm, etc)
|
|
32
|
+
# works in the commandline or the web
|
|
33
|
+
bun add -g 1ls
|
|
19
34
|
|
|
35
|
+
# Or via binaries. here you get a QuickJs build
|
|
20
36
|
# Using Homebrew (macOS/Linux)
|
|
21
|
-
brew install yowainwright/
|
|
22
|
-
|
|
37
|
+
brew install yowainwright/1ls/1ls
|
|
23
38
|
# Using curl
|
|
24
|
-
curl -fsSL https://raw.githubusercontent.com/yowainwright/1ls/main/install.sh | bash
|
|
39
|
+
curl -fsSL https://raw.githubusercontent.com/yowainwright/1ls/main/scripts/install.sh | bash
|
|
25
40
|
```
|
|
26
41
|
|
|
27
42
|
## Quick Start
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Lexer } from "../lexer";
|
|
2
|
+
import { ExpressionParser } from "../expression";
|
|
3
|
+
import { JsonNavigator } from "../navigator/json";
|
|
4
|
+
import { parseYAML } from "../formats/yaml";
|
|
5
|
+
import { parseCSV } from "../formats/csv";
|
|
6
|
+
import { parseTOML } from "../formats/toml";
|
|
7
|
+
export { Lexer, ExpressionParser, JsonNavigator };
|
|
8
|
+
export { parseYAML, parseCSV, parseTOML };
|
|
9
|
+
export declare function escapeRegExp(str: string): string;
|
|
10
|
+
export declare function expandShortcuts(expression: string): string;
|
|
11
|
+
export declare function shortenExpression(expression: string): string;
|
|
12
|
+
export declare function evaluate(data: unknown, expression: string): unknown;
|
|
@@ -0,0 +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 I(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 I();let e=this.parseExpression();return I(e)}parseExpression(){return this.parsePrimary()}parsePrimary(){let t=this.parsePrimaryNode();return this.parsePostfix(t)}parsePrimaryNode(){let t=this.current.type;if(t==="DOT")return this.advance(),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:I(),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(I(),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{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;return B(n,t.property)}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}:
|
|
3
|
+
${r.join(`
|
|
4
|
+
`)}`},Ne=`Expression Shortcuts:
|
|
5
|
+
|
|
6
|
+
${W("array","Array Methods")}
|
|
7
|
+
|
|
8
|
+
${W("object","Object Methods")}
|
|
9
|
+
|
|
10
|
+
${W("string","String Methods")}
|
|
11
|
+
`;var at=/[.*+?^${}()|[\]\\]/g,V=U;var wt=/^-?\d+$/,Rt=/^[+-]?\d+$/,kt=/^-?\d+\.\d+$/,It=/^[+-]?\d+\.\d+$/;var H={INTEGER:wt,FLOAT:kt},$={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 k(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(H.INTEGER.test(n))return parseInt(n,10);if(H.FLOAT.test(n))return parseFloat(n);if(n.startsWith("[")&&n.endsWith("]"))return n.slice(1,-1).split(",").map((c)=>k(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]=k(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?k(N):null};if(l.push(O),x)n[x]=O;i.push({container:O,indent:d+2})}else if(y)l.push(k(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=k(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($.INTEGER.test(t))return parseInt(t,10);if($.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 Ht(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 $t=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 $t.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,Ht as parseTOML,Vt as parseCSV,Qt as expandShortcuts,We as evaluate,lt as escapeRegExp,_ as Lexer,G as JsonNavigator,M as ExpressionParser};
|
package/dist/cli/constants.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { DataFormat } from "../utils/types";
|
|
2
|
+
import { CliOptions } from "../types";
|
|
2
3
|
export declare const VALID_OUTPUT_FORMATS: readonly ["json", "yaml", "csv", "table"];
|
|
3
4
|
export declare const VALID_INPUT_FORMATS: DataFormat[];
|
|
5
|
+
export declare const DEFAULT_OPTIONS: CliOptions;
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
+
import { CliOptions } from "../types";
|
|
3
|
+
export declare const getInteractive: () => Promise<typeof import("../interactive/app")>;
|
|
4
|
+
export declare function handleGrepOperation(options: CliOptions): Promise<void>;
|
|
5
|
+
export declare function loadData(options: CliOptions, args: string[]): Promise<unknown>;
|
|
6
|
+
export declare function processExpression(options: CliOptions, jsonData: unknown): Promise<void>;
|
|
2
7
|
export declare function main(args: string[]): Promise<void>;
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
export declare const INTEGER: RegExp;
|
|
2
|
+
export declare const INTEGER_WITH_SIGN: RegExp;
|
|
3
|
+
export declare const FLOAT: RegExp;
|
|
4
|
+
export declare const FLOAT_WITH_SIGN: RegExp;
|
|
5
|
+
export declare const NUMBER: RegExp;
|
|
6
|
+
export declare const ATTRIBUTES: RegExp;
|
|
7
|
+
export declare const SELF_CLOSING: RegExp;
|
|
8
|
+
export declare const OPEN_TAG: RegExp;
|
|
9
|
+
export declare const NESTED_TAGS: RegExp;
|
|
10
|
+
export declare const COMPLETE_TAGS: RegExp;
|
|
11
|
+
export declare const XML_DECLARATION: RegExp;
|
|
12
|
+
export declare const TRAILING_COMMA: RegExp;
|
|
13
|
+
export declare const UNQUOTED_KEY: RegExp;
|
|
14
|
+
export declare const JSON5_FEATURES: RegExp;
|
|
15
|
+
export declare const SECTION_HEADER: RegExp;
|
|
16
|
+
export declare const TOML_SECTION: RegExp;
|
|
17
|
+
export declare const TOML_QUOTED_VALUES: RegExp;
|
|
18
|
+
export declare const TOML_SYNTAX: RegExp;
|
|
19
|
+
export declare const INI_SYNTAX: RegExp;
|
|
1
20
|
export declare const CSV: {
|
|
2
21
|
readonly NUMBER: RegExp;
|
|
3
22
|
};
|
package/dist/formats/ini.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { INIParseState } from "./types";
|
|
1
2
|
export declare function parseINIValue(value: string): unknown;
|
|
3
|
+
export declare function stripINIComments(line: string): string;
|
|
4
|
+
export declare function processINILine(state: INIParseState, line: string): INIParseState;
|
|
2
5
|
export declare function parseINI(input: string): Record<string, unknown>;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { ParseState } from "./types";
|
|
2
|
+
export declare function isQuoteChar(char: string): boolean;
|
|
3
|
+
export declare function findCommentEnd(chars: string[], startIndex: number, endPattern: string): number;
|
|
4
|
+
export declare function findMultiLineCommentEnd(chars: string[], startIndex: number): number;
|
|
5
|
+
export declare function handleStringChar(state: ParseState, char: string, nextChar: string | undefined): ParseState;
|
|
6
|
+
export declare function handleNormalChar(state: ParseState, char: string, nextChar: string | undefined, chars: string[], index: number): ParseState;
|
|
1
7
|
export declare function stripJSComments(input: string): string;
|
|
2
8
|
export declare function parseJavaScript(input: string): unknown;
|
package/dist/formats/json5.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { ParseState } from "./types";
|
|
2
|
+
export declare function isQuoteChar(char: string): boolean;
|
|
3
|
+
export declare function findCommentEnd(chars: string[], startIndex: number, endPattern: string): number;
|
|
4
|
+
export declare function findMultiLineCommentEnd(chars: string[], startIndex: number): number;
|
|
5
|
+
export declare function handleStringChar(state: ParseState, char: string, nextChar: string | undefined): ParseState;
|
|
6
|
+
export declare function handleNormalChar(state: ParseState, char: string, nextChar: string | undefined, chars: string[], index: number): ParseState;
|
|
1
7
|
export declare function stripJSON5Comments(input: string): string;
|
|
2
8
|
export declare function normalizeJSON5(input: string): string;
|
|
3
9
|
export declare function parseJSON5(input: string): unknown;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
export declare const COLORS: {
|
|
2
|
+
reset: string;
|
|
3
|
+
bright: string;
|
|
4
|
+
dim: string;
|
|
5
|
+
black: string;
|
|
6
|
+
red: string;
|
|
7
|
+
green: string;
|
|
8
|
+
yellow: string;
|
|
9
|
+
blue: string;
|
|
10
|
+
magenta: string;
|
|
11
|
+
cyan: string;
|
|
12
|
+
white: string;
|
|
13
|
+
gray: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const COLOR_PATTERNS: {
|
|
16
|
+
regex: RegExp;
|
|
17
|
+
replacement: string;
|
|
18
|
+
}[];
|
|
1
19
|
export declare function colorize(json: string): string;
|
|
2
20
|
export declare function error(message: string): string;
|
|
3
21
|
export declare function success(message: string): string;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,78 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
4
|
-
`);return{result:
|
|
5
|
-
`)
|
|
6
|
-
`),n={},
|
|
7
|
-
`).
|
|
8
|
-
`)
|
|
9
|
-
`);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
`).
|
|
3
|
+
var br=Object.defineProperty;var O=(t,e)=>{for(var n in e)br(t,n,{get:e[n],enumerable:!0,configurable:!0,set:(r)=>e[n]=()=>r})};var x=(t,e)=>()=>(t&&(e=t(t=0)),e);var Sr,wr,Er,Ar,Ne,Tr,Nr,Or,vr,Ir,Cr,Rr,Fr,Mr,Lr,kr,Pr,_r,Br,Ft,Mt,M,Oe,Lt,jr,Dr,Vr,$r,Gr,Wr,E;var V=x(()=>{Sr=/^-?\d+$/,wr=/^[+-]?\d+$/,Er=/^-?\d+\.\d+$/,Ar=/^[+-]?\d+\.\d+$/,Ne=/^-?\d+(\.\d+)?$/,Tr=/(\w+)=["']([^"']+)["']/g,Nr=/^<(\w+)([^>]*?)\/>/,Or=/^<(\w+)([^>]*)>([\s\S]*)<\/\1>$/,vr=/<\w+/,Ir=/<\/\w+>$/,Cr=/^<\?xml[^>]+\?>\s*/,Rr=/,(\s*[}\]])/g,Fr=/(['"])?([a-zA-Z_$][a-zA-Z0-9_$]*)\1?\s*:/g,Mr=/\/\/|\/\*|,\s*[}\]]/,Lr=/^\[[\w.\s]+\]$/m,kr=/^\[[\w.]+\]$/m,Pr=/^\w+\s*=\s*"[^"]*"$/m,_r=/=\s*["[{]/m,Br=/^\w+\s*=\s*.+$/m,Ft={INTEGER:Sr,FLOAT:Er},Mt={INTEGER:wr,FLOAT:Ar},M={NUMBER:Ne,ATTRIBUTES:Tr,SELF_CLOSING:Nr,OPEN_TAG:Or,NESTED_TAGS:vr,COMPLETE_TAGS:Ir,XML_DECLARATION:Cr},Oe={NUMBER:Ne},Lt={TRAILING_COMMA:Rr,UNQUOTED_KEY:Fr},jr=/^\s*export\s+(const|let|var|function|class|default|type|interface|enum)/m,Dr=/:\s*(string|number|boolean|any|unknown|void|never|object|Array|Promise)/,Vr=/^\s*interface\s+\w+/m,$r=/^\s*type\s+\w+\s*=/m,Gr=/^[A-Z_][A-Z0-9_]*\s*=/m,Wr=/^\{.*\}\s*$/m,E={JSON5_FEATURES:Mr,SECTION_HEADER:Lr,TOML_SECTION:kr,TOML_QUOTED_VALUES:Pr,TOML_SYNTAX:_r,INI_SYNTAX:Br,JS_EXPORT:jr,TS_TYPE_ANNOTATION:Dr,TS_INTERFACE:Vr,TS_TYPE_ALIAS:$r,ENV_FEATURES:Gr,NDJSON_FEATURES:Wr}});var ke={};O(ke,{stripJSON5Comments:()=>Me,parseJSON5:()=>Ur,normalizeJSON5:()=>Le,isQuoteChar:()=>ve,handleStringChar:()=>Re,handleNormalChar:()=>Fe,findMultiLineCommentEnd:()=>Ce,findCommentEnd:()=>Ie});function ve(t){return t==='"'||t==="'"}function Ie(t,e,n){let o=t.slice(e).findIndex((i)=>i===n);return o===-1?t.length-e:o}function Ce(t,e){let n=2,r=t.length-e;while(n<r){let o=t[e+n],s=t[e+n+1];if(o==="*"&&s==="/")return n+1;n++}return n}function Re(t,e,n){if(t.result.push(e),e==="\\"&&n)return t.result.push(n),{result:t.result,inString:t.inString,delimiter:t.delimiter,skip:1};if(e===t.delimiter)return{result:t.result,inString:!1,delimiter:"",skip:0};return t}function Fe(t,e,n,r,o){if(ve(e))return t.result.push(e),{result:t.result,inString:!0,delimiter:e,skip:0};if(e==="/"&&n==="/"){let a=Ie(r,o,`
|
|
4
|
+
`);return{result:t.result,inString:t.inString,delimiter:t.delimiter,skip:a}}if(e==="/"&&n==="*"){let a=Ce(r,o);return{result:t.result,inString:t.inString,delimiter:t.delimiter,skip:a}}return t.result.push(e),t}function Me(t){let e=t.split("");return e.reduce((n,r,o)=>{if(n.skip>0)return{result:n.result,inString:n.inString,delimiter:n.delimiter,skip:n.skip-1};let i=e[o+1];return n.inString?Re(n,r,i):Fe(n,r,i,e,o)},{result:[],inString:!1,delimiter:"",skip:0}).result.join("")}function Le(t){let e=Me(t);return e=e.replace(Lt.TRAILING_COMMA,"$1"),e=e.replace(Lt.UNQUOTED_KEY,'"$2":'),e=e.replace(/'/g,'"'),e}function Ur(t){let e=Le(t);return JSON.parse(e)}var Pe=x(()=>{V()});var Jr,zr,Qr,Hr=(t)=>Jr.includes(t),Kr=(t)=>zr.includes(t),Xr=(t)=>Qr.includes(t),Q=(t)=>{if(Hr(t))return!0;if(Kr(t))return!1;return},H=(t)=>{if(Xr(t))return null;return},lt=(t)=>{if(t==="")return;let e=Number(t);return isNaN(e)?void 0:e};var pt=x(()=>{Jr=["true","yes","on"],zr=["false","no","off"],Qr=["null","~",""]});var Be={};O(Be,{parseYAMLValue:()=>K,parseYAML:()=>ts,findPreviousKey:()=>_e});function qr(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 K(t){let{tag:e,content:n}=qr(t);if(e==="str")return n;let r=n.startsWith('"')&&n.endsWith('"'),o=n.startsWith("'")&&n.endsWith("'");if(r||o)return n.slice(1,-1);let i=Q(n);if(i!==void 0)return i;let c=H(n);if(c!==void 0)return c;if(Ft.INTEGER.test(n))return parseInt(n,10);if(Ft.FLOAT.test(n))return parseFloat(n);if(n.startsWith("[")&&n.endsWith("]"))return n.slice(1,-1).split(",").map((d)=>K(d.trim()));if(n.startsWith("{")&&n.endsWith("}")){let d={};return n.slice(1,-1).split(",").forEach((N)=>{let[T,y]=N.split(":").map((b)=>b.trim());if(T&&y)d[T]=K(y)}),d}return n}function _e(t,e){return Array.from({length:e},(r,o)=>e-1-o).reduce((r,o)=>{if(r!==null)return r;let s=t[o],i=s.indexOf("#");if(i>=0){let l=s.substring(0,i);if((l.match(/["']/g)||[]).length%2===0)s=l}let a=s.trim();if(a&&!a.startsWith("-")&&a.includes(":")){let l=a.indexOf(":"),p=a.substring(0,l).trim(),d=a.substring(l+1).trim();if(!d||d==="|"||d===">"||d==="|+"||d===">-")return p}return null},null)}function kt(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 Yr(t){let e=t.indexOf(":");if(e<=0)return!1;let n=t.substring(0,e);return!n.includes(" ")||n.startsWith('"')||n.startsWith("'")}function Pt(t){return t.length-t.trimStart().length}function Zr(t,e,n,r){let o=[],s=e;while(s<t.length){let c=t[s];if(!c.trim()){o.push(""),s++;continue}if(Pt(c)<=n)break;o.push(c.substring(n+2)),s++}while(o.length>0&&o[o.length-1]==="")o.pop();return{value:r==="|"?o.join(`
|
|
5
|
+
`):o.join(" ").replace(/\s+/g," ").trim(),endIdx:s-1}}function _t(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)=>_t(n,e));if(typeof t==="object"&&t!==null){let n={};for(let[r,o]of Object.entries(t))if(r==="<<"&&typeof o==="string"&&o.startsWith("*")){let s=o.substring(1),i=e[s];if(typeof i==="object"&&i!==null&&!Array.isArray(i))Object.assign(n,i)}else n[r]=_t(o,e);return n}return t}function ts(t){let e=t.trim().split(`
|
|
6
|
+
`),n={},s=e.find((u)=>{let l=kt(u).trim();return l&&l!=="---"&&l!=="..."})?.trim().startsWith("- ")?[]:{},i=[{container:s,indent:-1}];function c(){return i[i.length-1]}function a(u){while(i.length>1&&u(c()))i.pop()}for(let u=0;u<e.length;u++){let l=e[u],p=kt(l),d=p.trim();if(!d||d==="---"||d==="...")continue;let h=Pt(p);if(d.startsWith("- ")||d==="-"){let y=d==="-"?"":d.substring(2).trim();a((w)=>w.indent>h||w.indent>=h&&!Array.isArray(w.container));let g,b=c();if(Array.isArray(b.container)&&(b.indent===h||b.indent===-1&&h===0)){if(g=b.container,b.indent===-1)b.indent=h}else{if(g=[],b.pendingKey)b.container[b.pendingKey]=g,b.pendingKey=void 0;else if(!Array.isArray(b.container)){let w=_e(e,u);if(w)b.container[w]=g}i.push({container:g,indent:h})}if(Yr(y)){let w=y.indexOf(":"),S=y.substring(0,w).trim(),F=y.substring(w+1).trim(),_=null;if(S.includes(" &")){let z=S.split(" &");S=z[0],_=z[1]}let D={[S]:F?K(F):null};if(g.push(D),_)n[_]=D;i.push({container:D,indent:h+2})}else if(y)g.push(K(y));else{let w={};g.push(w),i.push({container:w,indent:h+2})}continue}let T=d.indexOf(":");if(T>0){let y=d.substring(0,T).trim(),g=d.substring(T+1).trim(),b=null;if(g.startsWith("&")){let S=g.indexOf(" ");if(S>0)b=g.substring(1,S),g=g.substring(S+1);else b=g.substring(1),g=""}a((S)=>S.indent>h||S.indent===h&&Array.isArray(S.container));let R=c(),w=R.container;if(Array.isArray(w))continue;if(g==="|"||g===">"||g==="|+"||g===">-"||g==="|-"||g===">+"){let S=g.startsWith("|")?"|":">",{value:F,endIdx:_}=Zr(e,u+1,h,S);if(w[y]=F,b)n[b]=F;u=_}else if(g){let S=K(g);if(w[y]=S,b)n[b]=S}else{let S=u+1,F=S<e.length,_=F?kt(e[S]):"",D=_.trim(),z=F?Pt(_):-1,gr=D.startsWith("- ")||D==="-",xr=F&&z>h&&D;if(gr&&z>h){if(R.pendingKey=y,b){let Z={};n[b]=Z}}else if(xr){let Z={};if(w[y]=Z,b)n[b]=Z;i.push({container:Z,indent:z})}else if(w[y]=null,b)n[b]=null}}}return _t(s,n)}var je=x(()=>{V();pt()});var De={};O(De,{parseTOMLValue:()=>dt,parseTOML:()=>es});function dt(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(Mt.INTEGER.test(t))return parseInt(t,10);if(Mt.FLOAT.test(t))return parseFloat(t);if(t.startsWith("[")&&t.endsWith("]"))return t.slice(1,-1).split(",").map((a)=>dt(a.trim()));if(t.startsWith("{")&&t.endsWith("}")){let c={};return t.slice(1,-1).split(",").forEach((u)=>{let[l,p]=u.split("=").map((d)=>d.trim());if(l&&p)c[l]=dt(p)}),c}return t}function es(t){let e=t.trim().split(`
|
|
7
|
+
`),n={},r=n,o=[];return e.forEach((s)=>{let i=s,c=i.indexOf("#");if(c>=0){let d=i.substring(0,c);if((d.match(/["']/g)||[]).length%2===0)i=d}let a=i.trim();if(!a)return;if(a.startsWith("[")&&a.endsWith("]")){let d=a.slice(1,-1).split(".");r=n,o=[],d.forEach((h)=>{if(!r[h])r[h]={};r=r[h],o.push(h)});return}let l=a.indexOf("=");if(l>0){let d=a.substring(0,l).trim(),h=a.substring(l+1).trim();r[d]=dt(h)}}),n}var Ve=x(()=>{V()});var Ge={};O(Ge,{parseXMLValue:()=>tt,parseXMLElement:()=>Bt,parseXMLChildren:()=>$e,parseXMLAttributes:()=>ht,parseXML:()=>ss});function tt(t){let e=t.trim();if(e==="true")return!0;if(e==="false")return!1;if(M.NUMBER.test(e))return parseFloat(e);return e}function ht(t){return Array.from(t.matchAll(M.ATTRIBUTES)).reduce((n,r)=>{let[,o,s]=r;return n[o]=tt(s),n},{})}function Bt(t){let e=t.trim(),n=e.match(M.SELF_CLOSING);if(n){let[,p,d]=n;if(d.trim().length>0)return{[p]:{_attributes:ht(d)}};return{[p]:null}}let r=e.match(M.OPEN_TAG);if(!r)return tt(e);let[,o,s,i]=r,c=i.trim();if(!M.NESTED_TAGS.test(c)){if(s.trim().length>0)return{[o]:{_attributes:ht(s),_text:tt(c)}};return{[o]:tt(c)}}let u=$e(c);if(s.trim().length>0)return{[o]:{_attributes:ht(s),...u}};return{[o]:u}}function ns(t){let e=t.split(""),n=e.reduce((s,i,c)=>{if(s.skip>0)return{elements:s.elements,buffer:s.buffer,depth:s.depth,skip:s.skip-1};if(i==="<"){let N=e[c+1]==="/",y=t.slice(c).match(/^<[^>]+\/>/);if(N)return s.buffer.push(i),{elements:s.elements,buffer:s.buffer,depth:s.depth-1,skip:0};if(y){let g=y[0];if(g.split("").forEach((R)=>s.buffer.push(R)),s.depth===0){let R=s.buffer.join("").trim();s.elements.push(R),s.buffer.length=0}return{elements:s.elements,buffer:s.buffer,depth:s.depth,skip:g.length-1}}return s.buffer.push(i),{elements:s.elements,buffer:s.buffer,depth:s.depth+1,skip:0}}s.buffer.push(i);let l=s.depth===0,p=s.buffer.join("").trim(),d=p.length>0,h=!i.match(/\s/);if(l&&d&&h){if(p.match(M.COMPLETE_TAGS))s.elements.push(p),s.buffer.length=0}return{elements:s.elements,buffer:s.buffer,depth:s.depth,skip:0}},{elements:[],buffer:[],depth:0,skip:0}),r=n.buffer.join("").trim();return r.length>0?[...n.elements,r]:n.elements}function rs(t,e,n){let r=t[e];if(r===void 0){t[e]=n;return}if(Array.isArray(r)){r.push(n);return}t[e]=[r,n]}function $e(t){return ns(t).reduce((n,r)=>{let o=Bt(r);if(typeof o==="object"&&o!==null)Object.entries(o).forEach(([i,c])=>{rs(n,i,c)});return n},{})}function ss(t){let e=t.trim(),n=e.match(M.XML_DECLARATION),r=n?e.slice(n[0].length):e;return Bt(r)}var We=x(()=>{V()});var ze={};O(ze,{stripINIComments:()=>Ue,processINILine:()=>Je,parseINIValue:()=>jt,parseINI:()=>os});function jt(t){let e=t.trim();if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;if(Oe.NUMBER.test(e))return parseFloat(e);return e}function Ue(t){let e=t.indexOf(";"),n=t.indexOf("#");if(!(e>=0||n>=0))return t;let o=e>=0&&n>=0?Math.min(e,n):Math.max(e,n);return t.substring(0,o)}function Je(t,e){let r=Ue(e).trim();if(!r)return t;if(r.startsWith("[")&&r.endsWith("]")){let a=r.slice(1,-1).trim();if(!t.result[a])t.result[a]={};return{result:t.result,currentSection:a}}let i=r.indexOf("=");if(i>0){let a=r.substring(0,i).trim(),u=r.substring(i+1).trim();if(t.currentSection.length>0){let p=t.result[t.currentSection];p[a]=jt(u)}else t.result[a]=jt(u)}return t}function os(t){return t.trim().split(`
|
|
8
|
+
`).reduce((r,o)=>Je(r,o),{result:{},currentSection:""}).result}var Qe=x(()=>{V()});var Vt={};O(Vt,{parseTSV:()=>is,parseCSVValue:()=>He,parseCSVLine:()=>Dt,parseCSV:()=>Ke});function Dt(t,e){let n=[],r="",o=!1,s=t.split("");return s.forEach((i,c)=>{let a=s[c+1];if(i==='"'){if(o&&a==='"'){r+='"',s.splice(c+1,1);return}o=!o;return}if(i===e&&!o){n.push(r),r="";return}r+=i}),n.push(r),n.map((i)=>i.trim())}function He(t){let e=t.trim();if(e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1).replace(/""/g,'"');let r=lt(e);if(r!==void 0)return r;let o=e.toLowerCase(),s=Q(o);if(s!==void 0)return s;let i=H(o);if(i!==void 0)return i;return e}function Ke(t,e=","){let n=t.trim().split(`
|
|
9
|
+
`);if(n.length===0)return[];let r=Dt(n[0],e);if(n.length===1)return[];return n.slice(1).reduce((o,s)=>{let i=Dt(s,e);if(i.length===0)return o;let c=Object.fromEntries(r.map((a,u)=>[a,He(i[u]||"")]));return[...o,c]},[])}function is(t){return Ke(t,"\t")}var $t=x(()=>{pt()});var Xe={};O(Xe,{parseProtobufJSON:()=>as,parseProtobuf:()=>cs});function cs(t){throw Error("Protobuf parsing requires a .proto schema file. Please convert your protobuf to JSON first using protoc: protoc --decode_raw < file.pb | 1ls")}function as(t){return JSON.parse(t)}var nn={};O(nn,{stripJSComments:()=>mt,parseJavaScript:()=>us,isQuoteChar:()=>qe,handleStringChar:()=>tn,handleNormalChar:()=>en,findMultiLineCommentEnd:()=>Ze,findCommentEnd:()=>Ye});function qe(t){return t==='"'||t==="'"||t==="`"}function Ye(t,e,n){let o=t.slice(e).findIndex((i)=>i===n);return o===-1?t.length-e:o}function Ze(t,e){let n=2,r=t.length-e;while(n<r){let o=t[e+n],s=t[e+n+1];if(o==="*"&&s==="/")return n+1;n++}return n}function tn(t,e,n){if(t.result.push(e),e==="\\"&&n)return t.result.push(n),{result:t.result,inString:t.inString,delimiter:t.delimiter,skip:1};if(e===t.delimiter)return{result:t.result,inString:!1,delimiter:"",skip:0};return t}function en(t,e,n,r,o){if(qe(e))return t.result.push(e),{result:t.result,inString:!0,delimiter:e,skip:0};if(e==="/"&&n==="/"){let a=Ye(r,o,`
|
|
10
|
+
`);return{result:t.result,inString:t.inString,delimiter:t.delimiter,skip:a}}if(e==="/"&&n==="*"){let a=Ze(r,o);return{result:t.result,inString:t.inString,delimiter:t.delimiter,skip:a}}return t.result.push(e),t}function mt(t){let e=t.split("");return e.reduce((n,r,o)=>{if(n.skip>0)return{result:n.result,inString:n.inString,delimiter:n.delimiter,skip:n.skip-1};let i=e[o+1];return n.inString?tn(n,r,i):en(n,r,i,e,o)},{result:[],inString:!1,delimiter:"",skip:0}).result.join("")}function us(input){let withoutComments=mt(input),exportMatch=withoutComments.match(/export\s+default\s+([\s\S]+)/),code=exportMatch?exportMatch[1]:withoutComments,trimmed=code.trim().replace(/;$/,"");return eval(`(${trimmed})`)}var rn={};O(rn,{parseTypeScript:()=>ps});function ls(){if(ft!==null)return ft;return ft=new Bun.Transpiler({loader:"ts"}),ft}function ps(input){let withoutComments=mt(input),transpiler=ls(),transpiled=transpiler.transformSync(withoutComments),exportMatch=transpiled.match(/export\s+default\s+(.+?)(?:;|\n|$)/),exportedValue=exportMatch?exportMatch[1]:null,hasExport=exportedValue!==null;if(!hasExport)return null;let exportIndex=transpiled.indexOf("export default"),codeBeforeExport=transpiled.substring(0,exportIndex),fullCode=`${codeBeforeExport}
|
|
11
|
+
(${exportedValue})`;return eval(fullCode)}var ft=null;var sn=()=>{};var cn={};O(cn,{parseENVValue:()=>on,parseENV:()=>ms});function on(t){let e=t.trim(),n=e.startsWith('"')&&e.endsWith('"'),r=e.startsWith("'")&&e.endsWith("'");if(n||r)return e.slice(1,-1);let s=Q(e);if(s!==void 0)return s;let i=H(e);if(i!==void 0)return i;let c=lt(e);if(c!==void 0)return c;return e}function ds(t){let e=t.indexOf("#");if(!(e>=0))return t;let r=t.substring(0,e);if(r.match(/["'].*["']/)!==null){if((r.match(/["']/g)||[]).length%2!==0)return t}return r}function hs(t,e){let r=ds(e).trim();if(!r)return t;let i=r.startsWith("export ")?r.substring(7).trim():r,c=i.indexOf("=");if(c>0){let u=i.substring(0,c).trim(),l=i.substring(c+1).trim();t.result[u]=on(l)}return t}function ms(t){return t.trim().split(`
|
|
12
|
+
`).reduce((r,o)=>hs(r,o),{result:{}}).result}var an=x(()=>{pt()});var un={};O(un,{parseNDJSON:()=>fs});function fs(t){return t.trim().split(`
|
|
13
|
+
`).map((n)=>n.trim()).filter((n)=>n.length>0).map((n)=>{try{return JSON.parse(n)}catch{return n}})}function gs(t){return t.trim().split(`
|
|
14
|
+
`).filter((e)=>e.length>0)}async function gt(t,e){switch(e??Gt(t)){case"json":return JSON.parse(t);case"json5":{let{parseJSON5:r}=await Promise.resolve().then(() => (Pe(),ke));return r(t)}case"yaml":{let{parseYAML:r}=await Promise.resolve().then(() => (je(),Be));return r(t)}case"toml":{let{parseTOML:r}=await Promise.resolve().then(() => (Ve(),De));return r(t)}case"xml":{let{parseXML:r}=await Promise.resolve().then(() => (We(),Ge));return r(t)}case"ini":{let{parseINI:r}=await Promise.resolve().then(() => (Qe(),ze));return r(t)}case"csv":{let{parseCSV:r}=await Promise.resolve().then(() => ($t(),Vt));return r(t)}case"tsv":{let{parseTSV:r}=await Promise.resolve().then(() => ($t(),Vt));return r(t)}case"protobuf":{let{parseProtobuf:r}=await Promise.resolve().then(() => Xe);return r(t)}case"javascript":{let{parseJavaScript:r}=await Promise.resolve().then(() => nn);return r(t)}case"typescript":{let{parseTypeScript:r}=await Promise.resolve().then(() => (sn(),rn));return r(t)}case"env":{let{parseENV:r}=await Promise.resolve().then(() => (an(),cn));return r(t)}case"ndjson":{let{parseNDJSON:r}=await Promise.resolve().then(() => un);return r(t)}case"lines":return gs(t);case"text":default:return t}}function bs(t){let e=t.split(`
|
|
15
|
+
`),n=E.NDJSON_FEATURES.test(t),r=e.every(xs);if(n&&r)return"ndjson";let s=e[0],i=ln(s,/,/g),c=ln(s,/\t/g);if(c>0&&c>=i)return"tsv";if(i>0)return"csv";return"lines"}function ys(t){if(E.ENV_FEATURES.test(t))return"env";if(E.TOML_QUOTED_VALUES.test(t))return"toml";let r=E.SECTION_HEADER.test(t),o=E.TOML_SECTION.test(t),s=E.TOML_SYNTAX.test(t);if(r&&o&&s)return"toml";let c=E.INI_SYNTAX.test(t);if(r&&c)return"ini";if(c)return"ini";return"text"}function Gt(t){let e=t.trim();if(!e)return"text";let n=e[0],r=e[e.length-1],o=Ns(e,n,r);if(o)return o;let s=Os(e);if(s)return s;return"text"}var xs=(t)=>{let e=t.trim();if(!e)return!0;try{return JSON.parse(e),!0}catch{return!1}},ln=(t,e)=>(t.match(e)||[]).length,Ss=(t)=>{try{return JSON.parse(t),"json"}catch{return E.JSON5_FEATURES.test(t)?"json5":null}},ws=(t,e,n)=>{if(e==="{"&&n==="}"||e==="["&&n==="]")return Ss(t);return null},Es=(t)=>{let e=t.startsWith("<?xml"),n=/<\/\w+>/.test(t);return e||n?"xml":null},As=(t)=>E.TS_INTERFACE.test(t)||E.TS_TYPE_ALIAS.test(t)||E.TS_TYPE_ANNOTATION.test(t),Ts=(t)=>{if(!E.JS_EXPORT.test(t))return null;return As(t)?"typescript":"javascript"},Ns=(t,e,n)=>{switch(e){case"{":case"[":return ws(t,e,n);case"<":return Es(t);case"-":return t.startsWith("---")?"yaml":null;case"e":return Ts(t);case"i":return E.TS_INTERFACE.test(t)?"typescript":null;case"t":return E.TS_TYPE_ALIAS.test(t)?"typescript":null;case"c":case"l":case"v":return E.TS_TYPE_ANNOTATION.test(t)?"typescript":null;default:return null}},Os=(t)=>{if(t.includes("="))return ys(t);let n=t.includes(": "),r=/^[\s]*-\s+/m.test(t);if(n||r)return"yaml";if(t.includes(`
|
|
16
|
+
`))return bs(t);return null};var xt=x(()=>{V()});async function pn(t){let e=[];for await(let r of process.stdin)e.push(r);let n=Buffer.concat(e).toString("utf-8").trim();if(!n)return null;return gt(n,t)}var Wt=x(()=>{xt()});var vs,Is,Cs,dn,hn;var bt=x(()=>{vs=[".ts",".js",".tsx",".jsx"],Is=[".json",".yml",".yaml"],Cs=[".md",".txt"],dn=[...vs,...Is,...Cs],hn=/[.*+?^${}()|[\]\\]/g});import{readdir as Rs,stat as mn}from"fs/promises";import{join as Fs,extname as Ms,basename as Ls}from"path";async function yt(t,e=!0){let r=await Bun.file(t).text();if(!e)return r;return gt(r)}function ks(t,e){return{path:t,name:Ls(t),ext:Ms(t),size:Number(e.size),isDirectory:e.isDirectory(),isFile:e.isFile(),modified:e.mtime,created:e.birthtime}}async function Ps(t){let e=await mn(t);return ks(t,e)}function _s(t){return t.startsWith(".")}function Bs(t,e){return e||!_s(t)}function js(t,e){if(e===void 0)return!0;return e.includes(t)}function Ds(t,e){if(e===void 0)return!0;return e.test(t)}function Vs(t,e,n){let r=js(t.ext,e),o=Ds(t.name,n);return r&&o}function $s(t,e){return t<=(e??1/0)}async function Gs(t,e,n,r){if(!Bs(e,r.includeHidden??!1))return[];let s=Fs(t,e),i=await Ps(s);if(i.isFile)return Vs(i,r.extensions,r.pattern)?[i]:[];if(!i.isDirectory)return[];let a=r.recursive===!0?await fn(s,n+1,r):[];return[i,...a]}async function fn(t,e,n){if(!$s(e,n.maxDepth))return[];let o=await Rs(t);return(await Promise.all(o.map((i)=>Gs(t,i,e,n)))).flat()}async function Ut(t,e={}){return fn(t,0,e)}function Ws(t,e){if(typeof t!=="string")return t;return new RegExp(t,e?"gi":"g")}function Us(t,e,n,r,o,s){let i={file:t,line:e+1,column:n+1,match:r};if(s===void 0)return i;let a=Math.max(0,e-s),u=Math.min(o.length,e+s+1);return{...i,context:o.slice(a,u)}}function Js(t,e,n){if(!n)return;let r=e instanceof Error?e.message:String(e);console.error(`Failed to search ${t}: ${r}`)}function zs(t,e,n,r,o,s){return[...t.matchAll(n)].map((c)=>Us(r,e,c.index,t,o,s))}async function gn(t,e,n){try{let r=await yt(t,!1);if(typeof r!=="string")return[];let s=r.split(`
|
|
17
|
+
`),i=s.flatMap((a,u)=>zs(a,u,e,t,s,n.context)),c=n.maxMatches??1/0;return i.slice(0,c)}catch(r){return Js(t,r,n.verbose??!1),[]}}async function Qs(t,e,n){let r=await Ut(t,{recursive:!0,extensions:[...dn]});return(await Promise.all(r.filter((s)=>s.isFile).map((s)=>gn(s.path,e,n)))).flat()}async function xn(t,e,n={}){let r=Ws(t,n.ignoreCase??!1),o=await mn(e);if(o.isFile())return gn(e,r,n);if(o.isDirectory()&&n.recursive)return Qs(e,r,n);return[]}var Jt=x(()=>{bt();xt()});var St=()=>{};var yn,Sn="+-*/%<>!&|=",wn;var En=x(()=>{St();yn={".":"DOT","[":"LEFT_BRACKET","]":"RIGHT_BRACKET","{":"LEFT_BRACE","}":"RIGHT_BRACE","(":"LEFT_PAREN",")":"RIGHT_PAREN",":":"COLON",",":"COMMA"},wn=[" ","\t",`
|
|
18
|
+
`,"\r"]});function $(t,e,n){return{type:t,value:e,position:n}}class et{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($("EOF","",this.position)),t}nextToken(){let t=this.position,e=yn[this.current];if(e){let u=this.current;return this.advance(),$(e,u,t)}if(this.current==="="&&this.peek()===">")return this.advance(),this.advance(),$("ARROW","=>",t);if(this.current==='"'||this.current==="'")return this.readString();let o=this.isDigit(this.current),s=this.current==="-"&&this.isDigit(this.peek());if(o||s)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 $("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 $("NUMBER",e,t)}readIdentifier(){let t=this.position,e="";while(this.isIdentifierChar(this.current))e+=this.current,this.advance();return $("IDENTIFIER",e,t)}readOperator(){let t=this.position,e="";while(this.isOperator(this.current))e+=this.current,this.advance();return $("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 wn.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 Sn.includes(t)}}var zt=x(()=>{St();En()});var An=()=>{};var C=(t)=>{return{type:"Literal",value:t}},Qt=(t)=>{if(t==="true")return C(!0);if(t==="false")return C(!1);if(t==="null")return C(null);return};var Tn=x(()=>{An()});function k(t,e){return`${e} at position ${t.position} (got ${t.type}: "${t.value}")`}function G(t,e){return{type:"PropertyAccess",property:t,object:e}}function Hs(t,e){return{type:"IndexAccess",index:t,object:e}}function Ks(t,e,n){return{type:"SliceAccess",start:t,end:e,object:n}}function Nn(t,e,n){return{type:"MethodCall",method:t,args:e,object:n}}function Xs(t,e){return{type:"ObjectOperation",operation:t,object:e}}function qs(t){return{type:"ArraySpread",object:t}}function Ys(t,e){return{type:"ArrowFunction",params:t,body:e}}function wt(t){return{type:"Root",expression:t}}function Zs(t){return On.includes(t)}class nt{tokens;position=0;current;constructor(t){this.tokens=t,this.current=this.tokens[0]}parse(){if(this.current.type==="EOF")return wt();let e=this.parseExpression();return wt(e)}parseExpression(){return this.parsePrimary()}parsePrimary(){let t=this.parsePrimaryNode();return this.parsePostfix(t)}parsePrimaryNode(){let t=this.current.type;if(t==="DOT")return this.advance(),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(),C(e)}if(t==="NUMBER"){let e=Number(this.current.value);return this.advance(),C(e)}if(t==="LEFT_PAREN"){let e=this.parseFunctionParams();return this.parseArrowFunction(e)}throw Error(k(this.current,"Unexpected token"))}parseAccessChain(t){let e=this.current.type;if(e==="IDENTIFIER"){let n=this.current.value;return this.advance(),G(n,t)}if(e==="LEFT_BRACKET")return this.parseBracketAccess(t);if(e==="LEFT_BRACE")return this.parseObjectOperation(t);throw Error(k(this.current,"Expected property name after dot"))}parseBracketAccess(t){if(this.advance(),this.current.type==="RIGHT_BRACKET")return this.advance(),qs(t);if(this.current.type==="STRING"){let c=this.current.value;return this.advance(),this.expect("RIGHT_BRACKET"),G(c,t)}let r=this.current.type==="NUMBER",o=this.current.type==="OPERATOR"&&this.current.value==="-",s=this.current.type==="COLON";if(r||o||s)return this.parseNumericIndexOrSlice(t);throw Error(k(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"),Hs(n,t)}parseSliceFromColon(t,e){this.advance();let n=this.current.type==="NUMBER",r=this.current.type==="OPERATOR"&&this.current.value==="-",o=n||r,s=o?this.parseNumber():void 0;if(o)this.advance();return this.expect("RIGHT_BRACKET"),Ks(t,s,e)}parseArrayAccess(){return this.parseBracketAccess()}parseObjectOperation(t){if(this.advance(),this.current.type!=="IDENTIFIER")throw Error(k(this.current,"Expected operation name after {"));let n=this.current.value;if(!Zs(n)){let r=On.join(", ");throw Error(k(this.current,`Invalid object operation "${n}". Valid operations: ${r}`))}return this.advance(),this.expect("RIGHT_BRACE"),Xs(n,t)}parseIdentifierOrFunction(){let t=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([t]);let n=Qt(t);if(n)return n;return G(t)}parseArrowFunction(t){this.expect("ARROW");let e=this.parseFunctionBody();return Ys(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=Nn(`__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(),C(e)}if(t==="STRING"){let e=this.current.value;return this.advance(),C(e)}if(t==="LEFT_PAREN"){this.advance();let e=this.parseBinaryExpression();return this.expect("RIGHT_PAREN"),e}throw Error(k(this.current,"Unexpected token in function body"))}parseIdentifierChain(){let t=this.current.value;this.advance();let e=Qt(t);if(e)return e;let n=G(t),r=()=>this.current.type==="DOT",o=()=>this.current.type==="IDENTIFIER",s=()=>this.current.type==="LEFT_PAREN";while(r()||s()){if(s()){let c=n,a=c.property,u=c.object;n=this.parseMethodCall(u?u:wt(),a);continue}if(this.advance(),!o())break;let i=this.current.value;this.advance(),n=G(i,n)}return n}parseMethodCall(t,e){this.expect("LEFT_PAREN");let n=this.parseMethodArguments();return this.expect("RIGHT_PAREN"),Nn(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 G(e)}if(t==="NUMBER"){let e=Number(this.current.value);return this.advance(),C(e)}if(t==="STRING"){let e=this.current.value;return this.advance(),C(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 s=e.property;e=this.parseMethodCall(wt(),s);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 G(n,t)}if(e==="LEFT_BRACKET")return this.parseBracketAccess(t);if(e==="LEFT_BRACE")return this.parseObjectOperation(t);throw Error(k(this.current,"Expected property name after dot"))}parseNumber(){let t=this.current.value==="-";if(t)this.advance();if(this.current.type!=="NUMBER")throw Error(k(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(k(this.current,`Expected ${t} but got ${this.current.type}`));this.advance()}}var On;var Ht=x(()=>{St();Tn();On=["keys","values","entries","length"]});function vn(t){return t.startsWith("__operator_")&&t.endsWith("__")}function In(t){return t.slice(11,-2)}function Cn(t,e,n){let r=to[e];if(!r)throw Error(`Unknown operator: ${e}`);return r(t,n)}function eo(t,e){return Object.fromEntries(t.map((n,r)=>[n,e[r]]))}function Kt(t){return Object.values(t)[0]}function Fn(t){return t!==null&&typeof t==="object"}function Xt(t,e){if(!Fn(t))return;return t[e]}function qt(t,e){return t<0?e+t:t}function no(t,e){if(!Array.isArray(t))return;let n=qt(e,t.length);return t[n]}function ro(t,e,n){if(!Array.isArray(t))return;let r=t.length,o=e!==void 0?qt(e,r):0,s=n!==void 0?qt(n,r):r;return t.slice(o,s)}function so(t,e){if(!Fn(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}}function Rn(t,e,n){if(!oo(t,e))throw Error(`Method ${e} does not exist on ${typeof t}`);try{return t[e].call(t,...n)}catch(o){let s=io(o);throw Error(`Error executing method ${e}: ${s}`)}}class rt{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 no(t.object?this.evaluate(t.object,e):e,t.index);case"SliceAccess":return ro(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 so(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;return Xt(n,t.property)}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(vn(t.method)){let s=In(t.method),i=this.evaluate(t.args[0],e);return Cn(n,s,i)}let o=t.args.map((s)=>this.evaluateArg(s,e));return Rn(n,t.method,o)}createFunction(t){return(...e)=>{let n=eo(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,Kt(e))}}evaluatePropertyAccessInFunction(t,e){if(t.object!==void 0){let s=this.evaluateFunctionBody(t.object,e);return Xt(s,t.property)}if(Object.prototype.hasOwnProperty.call(e,t.property))return e[t.property];let o=Kt(e);return Xt(o,t.property)}evaluateMethodCallInFunction(t,e){let n=t.object?this.evaluateFunctionBody(t.object,e):Kt(e);if(vn(t.method)){let s=In(t.method),i=this.evaluateFunctionBody(t.args[0],e);return Cn(n,s,i)}let o=t.args.map((s)=>this.evaluateFunctionBody(s,e));return Rn(n,t.method,o)}}var to,oo=(t,e)=>{if(t===null||t===void 0)return!1;return typeof t[e]==="function"},io=(t)=>t instanceof Error?t.message:String(t);var Yt=x(()=>{to={"+":(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}});var W;var te=x(()=>{W={ERROR:0,WARN:1,INFO:2,DEBUG:3}});var ao,yc;var kn=x(()=>{te();ao={ERROR:W.ERROR,WARN:W.WARN,INFO:W.INFO,DEBUG:W.DEBUG},yc=process.env.LOG_LEVEL?ao[process.env.LOG_LEVEL]||W.INFO:W.INFO});function ee(t){return t.replace(hn,"\\$&")}var Pn=x(()=>{bt();bt();Jt();kn();Et();Wt();te()});function ot(t){return uo.reduce((e,{regex:n,replacement:r})=>e.replace(n,r),t)}function _n(t){return lo.reduce((e,{regex:n,replacement:r})=>e.replace(n,r),t)}function Bn(){let t=B.filter((s)=>s.type==="array"),e=B.filter((s)=>s.type==="object"),n=B.filter((s)=>s.type==="string"),r=B.filter((s)=>s.type==="any"),o=(s,i)=>{let c=Math.max(...i.map((p)=>p.short.length)),a=Math.max(...i.map((p)=>p.full.length)),u=`
|
|
19
|
+
${s}:
|
|
20
|
+
`,l=i.map((p)=>` ${p.short.padEnd(c+2)} \u2192 ${p.full.padEnd(a+2)} # ${p.description}`).join(`
|
|
21
|
+
`);return u+l};return`
|
|
22
|
+
Shorthand Reference:
|
|
23
|
+
${o("Array Methods",t)}
|
|
24
|
+
${o("Object Methods",e)}
|
|
25
|
+
${o("String Methods",n)}
|
|
26
|
+
${o("Universal Methods",r)}
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
echo '[1,2,3]' | 1ls '.mp(x => x * 2)' # Short form
|
|
30
|
+
echo '[1,2,3]' | 1ls '.map(x => x * 2)' # Full form
|
|
31
|
+
|
|
32
|
+
1ls --shorten ".map(x => x * 2)" # Returns: .mp(x => x * 2)
|
|
33
|
+
1ls --expand ".mp(x => x * 2)" # Returns: .map(x => x * 2)
|
|
34
|
+
`}var B,Rc,Fc,uo,lo;var Et=x(()=>{Pn();B=[{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:".fndIdx",full:".findIndex",description:"Find index of 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:".splt",full:".split",description:"Split string to array",type:"string"},{short:".psh",full:".push",description:"Add to end",type:"array"},{short:".pp",full:".pop",description:"Remove from end",type:"array"},{short:".shft",full:".shift",description:"Remove from start",type:"array"},{short:".unshft",full:".unshift",description:"Add to start",type:"array"},{short:".fltMap",full:".flatMap",description:"Map and flatten",type:"array"},{short:".flt1",full:".flat",description:"Flatten array",type:"array"},{short:".incl",full:".includes",description:"Check if includes",type:"array"},{short:".idxOf",full:".indexOf",description:"Find index",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:".trmSt",full:".trimStart",description:"Remove leading whitespace",type:"string"},{short:".trmEnd",full:".trimEnd",description:"Remove trailing whitespace",type:"string"},{short:".rpl",full:".replace",description:"Replace text",type:"string"},{short:".rplAll",full:".replaceAll",description:"Replace all occurrences",type:"string"},{short:".pdSt",full:".padStart",description:"Pad start",type:"string"},{short:".pdEnd",full:".padEnd",description:"Pad end",type:"string"},{short:".stsWith",full:".startsWith",description:"Check if starts with",type:"string"},{short:".endsWith",full:".endsWith",description:"Check if ends with",type:"string"},{short:".sbstr",full:".substring",description:"Extract substring",type:"string"},{short:".chr",full:".charAt",description:"Get character at index",type:"string"},{short:".chrCd",full:".charCodeAt",description:"Get character code",type:"string"},{short:".mtch",full:".match",description:"Match pattern",type:"string"},{short:".str",full:".toString",description:"Convert to string",type:"any"},{short:".json",full:".toJSON",description:"Convert to JSON",type:"any"},{short:".val",full:".valueOf",description:"Get primitive value",type:"any"}],Rc=new Map(B.map((t)=>[t.short,t.full])),Fc=new Map(B.map((t)=>[t.full,t.short])),uo=B.map((t)=>({regex:new RegExp(`${ee(t.short)}(?![a-zA-Z])`,"g"),replacement:t.full})).sort((t,e)=>e.replacement.length-t.replacement.length),lo=B.map((t)=>({regex:new RegExp(`${ee(t.full)}(?![a-zA-Z])`,"g"),replacement:t.short})).sort((t,e)=>e.regex.source.length-t.regex.source.length)});var At=(t)=>{if(t===null)return"null";if(Array.isArray(t))return"Array";let e=typeof t;return e.charAt(0).toUpperCase()+e.slice(1)},Tt=(t,e)=>{if(e==="null")return"null";if(e==="String")return`"${t}"`;if(e==="Array")return`[${t.length} items]`;if(e==="Object")return`{${Object.keys(t).length} keys}`;return String(t)},ne=(t,e="",n=[])=>{if(t===null||t===void 0){let i=At(t),c=Tt(t,i);return n.push({path:e||".",value:t,type:i,displayValue:c}),n}if(Array.isArray(t)){let i=At(t),c=Tt(t,i),a=e||".";return n.push({path:a,value:t,type:i,displayValue:c}),t.forEach((u,l)=>{let p=e?`${e}[${l}]`:`.[${l}]`;ne(u,p,n)}),n}if(typeof t==="object"){let i=At(t),c=Tt(t,i),a=e||".";if(e)n.push({path:a,value:t,type:i,displayValue:c});return Object.entries(t).forEach(([l,p])=>{let d=/[^a-zA-Z0-9_$]/.test(l),h=e?d?`${e}["${l}"]`:`${e}.${l}`:d?`.["${l}"]`:`.${l}`;ne(p,h,n)}),n}let r=At(t),o=Tt(t,r),s=e||".";return n.push({path:s,value:t,type:r,displayValue:o}),n},Nt=(t)=>{return ne(t)};var po=(t,e,n)=>{let r=n.length*100,o=(p,d,h)=>{if(h===0)return p;let g=n[h-1]===d-1?5:0;return p+g},s=n.reduce(o,0),a=n[0]===0?10:0,u=t.length-e.length;return r+s+a-u},ho=(t,e)=>{let n=t.toLowerCase(),r=e.toLowerCase(),o=[],s=0,i=0,c=()=>{let u=s<n.length,l=i<r.length;return u&&l};while(c()){let u=n[s],l=r[i];if(u===l)o.push(s),i=i+1;s=s+1}return i===r.length?o:null},mo=(t,e,n)=>{let r=ho(e,n);if(!r)return null;let s=po(e,n,r);return Object.assign({},{item:t,score:s,matches:r})},fo=(t,e)=>e.score-t.score,P=(t,e,n)=>{if(!e){let u=(l)=>{return Object.assign({},{item:l,score:0,matches:[]})};return t.map(u)}let o=(u)=>{let l=n(u);return mo(u,l,e)},s=t.map(o),i=(u)=>u!==null;return s.filter(i).sort(fo)};var jn=(t,e)=>{let n=P(t,"",(o)=>o.path);return Object.assign({},{mode:"explore",paths:t,matches:n,query:"",selectedIndex:0,builder:null,originalData:e,methodMatches:[],propertyMatches:[]})},re=(t,e)=>{let n=P(t.paths,e,(s)=>s.path),r=n.length>0?0:t.selectedIndex;return Object.assign({},t,{query:e,matches:n,selectedIndex:r})},U=(t,e)=>{let n=t.mode==="explore",r=t.mode==="build",o=n?t.matches.length:r?t.methodMatches.length:t.propertyMatches.length;if(o===0)return t;let c=t.selectedIndex+e;if(c<0)c=o-1;else if(c>=o)c=0;return Object.assign({},t,{selectedIndex:c})},Dn=(t)=>{let e=t.matches.length>0,n=t.selectedIndex>=0&&t.selectedIndex<t.matches.length;if(e&&n)return t.matches[t.selectedIndex].item;return null};var se=()=>{};import{stdout as X}from"process";var J=()=>{X.write("\x1B[2J\x1B[H")},oe=(t,e=1)=>{X.write(`\x1B[${t};${e}H`)},Vn=()=>{X.write("\x1B[2K")},$n=()=>{X.write("\x1B[J")},Gn=()=>{X.write("\x1B[?25l")},Wn=()=>{X.write("\x1B[?25h")},Un=()=>{if(process.stdin.setRawMode!==void 0)process.stdin.setRawMode(!0);process.stdin.resume()},Jn=()=>{if(process.stdin.setRawMode!==void 0)process.stdin.setRawMode(!1);process.stdin.pause()},m,f=(t,e)=>{let n=m.reset;return e.concat(t,n)},it=(t,e)=>{let n=t.split(""),r=m.bright.concat(m.cyan),o=(c,a)=>{return e.includes(a)?f(c,r):c};return n.map(o).join("")};var Ot=x(()=>{m=Object.assign({},{reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",cyan:"\x1B[36m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",gray:"\x1B[90m"})});import{stdout as j}from"process";var v=10,go=(t,e)=>it(t,e),xo=(t)=>{let e=`[${t}]`;return f(e,m.dim)},bo=(t)=>f(t,m.gray),zn=(t)=>{let e=f("\u276F",m.green),n=" ";return t?e:" "},yo=(t,e,n)=>{let r=zn(e),o=go(t.signature,n),s=t.category?xo(t.category):"",i=bo(t.description);return r.concat(" ",o).concat(s?" "+s:"").concat(" - ",i)},So=(t,e)=>{let{item:n,matches:r}=t,o=zn(e),s=it(n.path,r),i=f(`[${n.type}]`,m.dim),c=f(n.displayValue,m.gray);return o.concat(" ",s).concat(" ",i).concat(" ",c)},wo=(t)=>{if(t.builder===null)return"";let n="Expression Builder",r=m.bright.concat(m.cyan),o=f(n,r),s=t.builder.expression,i=`
|
|
35
|
+
|
|
36
|
+
Building: `,c=f(s,m.bright.concat(m.yellow)),a=`
|
|
37
|
+
|
|
38
|
+
Search methods for `,u=f(t.builder.baseType,m.bright),l=": ",p=t.query;return o.concat(i,c).concat(a,u,l,p,`
|
|
39
|
+
|
|
40
|
+
`)},Eo=(t)=>{let e=t.builder!==null,n=t.builder?.arrowFnContext!==null;if(!e||!n)return"";let r="Expression Builder - Arrow Function",o=m.bright.concat(m.cyan),s=f(r,o),i=t.builder.expression,c=`
|
|
41
|
+
|
|
42
|
+
Building: `,a=f(i,m.bright.concat(m.yellow)),u=t.builder.arrowFnContext,l=`
|
|
43
|
+
|
|
44
|
+
Search properties for '${u.paramName}' (${u.paramType}): `,p=t.query;return s.concat(c,a).concat(l,p,`
|
|
45
|
+
|
|
46
|
+
`)},Ao=(t)=>{if(t.builder===null)return"";let{methodMatches:n,selectedIndex:r}=t;if(n.length===0)return f("No methods found",m.dim);let o=Math.floor(v/2),s=Math.max(0,r-o),i=Math.min(n.length,s+v);if(i-s<v&&n.length>=v)s=Math.max(0,i-v);let a=n.slice(s,i),u=(d,h)=>{let T=s+h===r;return yo(d.item,T,d.matches)};return a.map(u).join(`
|
|
47
|
+
`)},To=(t)=>{let e=t.builder===null,n=t.builder?.arrowFnContext===null;if(e||n)return"";let{propertyMatches:r,selectedIndex:o}=t;if(r.length===0)return f("No properties found",m.dim);let s=Math.floor(v/2),i=Math.max(0,o-s),c=Math.min(r.length,i+v);if(c-i<v&&r.length>=v)i=Math.max(0,c-v);let u=r.slice(i,c),l=(h,N)=>{let y=i+N===o;return So(h,y)};return u.map(l).join(`
|
|
48
|
+
`)},Qn=(t)=>{let e=t-v;if(e>0){let r=`
|
|
49
|
+
|
|
50
|
+
... `.concat(String(e)," more");return f(r,m.dim)}return""},Hn=()=>{let t=`
|
|
51
|
+
|
|
52
|
+
`.concat(f("\u2191/\u2193",m.bright)," navigate ",f("\u2192/Tab",m.bright)," accept ",f("\u2190",m.bright)," undo ",f("Enter",m.bright)," execute ",f("Esc",m.bright)," quit");return f(t,m.dim)},Kn=(t)=>{J();let e=wo(t);j.write(e);let n=Ao(t);j.write(n);let r=t.methodMatches.length,o=Qn(r);j.write(o);let s=Hn();j.write(s)},Xn=(t)=>{J();let e=Eo(t);j.write(e);let n=To(t);j.write(n);let r=t.propertyMatches.length,o=Qn(r);j.write(o);let s=Hn();j.write(s)};var qn=x(()=>{Ot()});import{stdout as Zn}from"process";var q=10,vt,tr=!0,No=(t,e)=>it(t,e),Oo=(t)=>{let r="[".concat(t,"]");return f(r,m.dim)},vo=(t)=>f(t,m.gray),Io=(t)=>{let e=f("\u276F",m.green),n=" ";return t?e:" "},Co=(t,e)=>{let{item:n,matches:r}=t,o=Io(e),s=No(n.path,r),i=Oo(n.type),c=vo(n.displayValue);return o.concat(" ",s).concat(" ",i).concat(" ",c)},Ro=()=>{let e=m.bright.concat(m.cyan);return f("1ls Interactive Explorer",e)},Fo,Mo,Yn=5,Lo=(t)=>f(String(t),m.cyan),ko=(t)=>{let n=JSON.stringify(t,null,2).split(`
|
|
53
|
+
`),r=n.slice(0,Yn),o=n.length>Yn,s=f(r.join(`
|
|
54
|
+
`),m.cyan);return o?s.concat(f(`
|
|
55
|
+
... (truncated)`,m.dim)):s},Po=(t)=>{let{type:e,displayValue:n,value:r}=t;if(Fo.includes(e))return Lo(n);if(Mo.includes(e))return ko(r);return f(String(r),m.cyan)},_o=(t)=>{let{matches:e,selectedIndex:n}=t,r=e.length>0,o=n>=0&&n<e.length;if(!(r&&o))return"";let i=e[n].item,c=f(`
|
|
56
|
+
|
|
57
|
+
Preview:
|
|
58
|
+
`,m.bright),a=Po(i);return c.concat(a)},Bo=()=>{let t=`
|
|
59
|
+
|
|
60
|
+
`.concat(f("\u2191/\u2193",m.bright)," navigate ",f("Enter",m.bright)," select ",f("Tab",m.bright)," build ",f("Esc/q",m.bright)," quit");return f(t,m.dim)},jo=(t,e)=>{let n=Math.floor(q/2),r=Math.max(0,t-n),o=Math.min(e,r+q);return{start:o-r<q&&e>=q?Math.max(0,o-q):r,end:o}},Do=(t)=>{let{selectedIndex:e,matches:n}=t,r=n.length;if(r===0)return[f("No matches found",m.dim)];let{start:s,end:i}=jo(e,r);return n.slice(s,i).map((a,u)=>{let p=s+u===e;return Co(a,p)})},Vo=(t)=>{let e=t-q;return e>0?["",f("... "+e+" more",m.dim)]:[]},$o=(t)=>{let e=_o(t);return e?e.split(`
|
|
61
|
+
`):[]},Go=(t)=>{let e=[Ro(),"","Search: "+t.query,""],n=Do(t),r=Vo(t.matches.length),o=$o(t),s=["",Bo().trim()];return[...e,...n,...r,...o,...s]},Wo=(t)=>{J(),Zn.write(t.join(`
|
|
62
|
+
`)),vt=t,tr=!1},Uo=(t,e)=>{oe(e+1),Vn(),Zn.write(t)},Jo=(t)=>{if(tr){Wo(t);return}if(t.forEach((n,r)=>{if(vt[r]!==n)Uo(n,r)}),t.length<vt.length)oe(t.length+1),$n();vt=t},zo=(t)=>{let e=Go(t);Jo(e)},Qo,ie=(t)=>{let e=Qo[t.mode];e(t)};var er=x(()=>{Ot();qn();vt=[],Fo=["String","Number","Boolean","null"],Mo=["Array","Object"],Qo={explore:zo,build:Kn,"build-arrow-fn":Xn}});var Ho,Ko,Xo,qo,Y=(t)=>{switch(t){case"Array":return Ho;case"String":return Ko;case"Object":return Xo;case"Number":return qo;default:return[]}};var nr=x(()=>{Ho=[{name:"map",signature:".map(x => ...)",description:"Transform each item",template:".map(x => x)",category:"Transform"},{name:"filter",signature:".filter(x => ...)",description:"Filter by condition",template:".filter(x => x)",category:"Filter"},{name:"reduce",signature:".reduce((acc, x) => ..., initial)",description:"Reduce to single value",template:".reduce((acc, x) => acc, 0)",category:"Aggregate"},{name:"find",signature:".find(x => ...)",description:"Find first match",template:".find(x => x)",category:"Search"},{name:"findIndex",signature:".findIndex(x => ...)",description:"Find first match index",template:".findIndex(x => x)",category:"Search"},{name:"some",signature:".some(x => ...)",description:"Check if any match",template:".some(x => x)",category:"Test"},{name:"every",signature:".every(x => ...)",description:"Check if all match",template:".every(x => x)",category:"Test"},{name:"sort",signature:".sort((a, b) => ...)",description:"Sort items",template:".sort((a, b) => a - b)",category:"Transform"},{name:"reverse",signature:".reverse()",description:"Reverse order",template:".reverse()",category:"Transform"},{name:"slice",signature:".slice(start, end)",description:"Get subset",template:".slice(0, 10)",category:"Transform"},{name:"concat",signature:".concat(arr)",description:"Combine arrays",template:".concat([])",category:"Transform"},{name:"join",signature:".join(separator)",description:"Join to string",template:".join(', ')",category:"Convert"},{name:"flat",signature:".flat(depth)",description:"Flatten nested arrays",template:".flat(1)",category:"Transform"},{name:"flatMap",signature:".flatMap(x => ...)",description:"Map then flatten",template:".flatMap(x => x)",category:"Transform"},{name:"length",signature:".length",description:"Get array length",template:".length",category:"Property"}],Ko=[{name:"toUpperCase",signature:".toUpperCase()",description:"Convert to uppercase",template:".toUpperCase()",category:"Transform"},{name:"toLowerCase",signature:".toLowerCase()",description:"Convert to lowercase",template:".toLowerCase()",category:"Transform"},{name:"trim",signature:".trim()",description:"Remove whitespace",template:".trim()",category:"Transform"},{name:"trimStart",signature:".trimStart()",description:"Remove leading whitespace",template:".trimStart()",category:"Transform"},{name:"trimEnd",signature:".trimEnd()",description:"Remove trailing whitespace",template:".trimEnd()",category:"Transform"},{name:"split",signature:".split(separator)",description:"Split into array",template:".split(',')",category:"Convert"},{name:"replace",signature:".replace(search, replace)",description:"Replace first match",template:".replace('old', 'new')",category:"Transform"},{name:"replaceAll",signature:".replaceAll(search, replace)",description:"Replace all matches",template:".replaceAll('old', 'new')",category:"Transform"},{name:"substring",signature:".substring(start, end)",description:"Extract substring",template:".substring(0, 10)",category:"Transform"},{name:"slice",signature:".slice(start, end)",description:"Extract slice",template:".slice(0, 10)",category:"Transform"},{name:"startsWith",signature:".startsWith(str)",description:"Check if starts with",template:".startsWith('prefix')",category:"Test"},{name:"endsWith",signature:".endsWith(str)",description:"Check if ends with",template:".endsWith('suffix')",category:"Test"},{name:"includes",signature:".includes(str)",description:"Check if contains",template:".includes('text')",category:"Test"},{name:"match",signature:".match(regex)",description:"Match regex pattern",template:".match(/pattern/)",category:"Search"},{name:"length",signature:".length",description:"Get string length",template:".length",category:"Property"}],Xo=[{name:"keys",signature:".{keys}",description:"Get object keys",template:".{keys}",category:"Convert"},{name:"values",signature:".{values}",description:"Get object values",template:".{values}",category:"Convert"},{name:"entries",signature:".{entries}",description:"Get key-value pairs",template:".{entries}",category:"Convert"},{name:"length",signature:".{length}",description:"Get property count",template:".{length}",category:"Property"}],qo=[{name:"toFixed",signature:".toFixed(decimals)",description:"Format with decimals",template:".toFixed(2)",category:"Format"},{name:"toString",signature:".toString()",description:"Convert to string",template:".toString()",category:"Convert"}]});var rr=(t)=>{let e=t.matches.length>0,n=t.selectedIndex>=0&&t.selectedIndex<t.matches.length;if(!e||!n)return t;let r=t.matches[t.selectedIndex].item,o={basePath:r.path,baseValue:r.value,baseType:r.type,expression:r.path,currentMethodIndex:0,arrowFnContext:null},s=Y(r.type),i=P(s,"",(a)=>a.signature);return Object.assign({},t,{mode:"build",builder:o,query:"",selectedIndex:0,methodMatches:i})},ct=(t)=>{return Object.assign({},t,{mode:"explore",builder:null,selectedIndex:0})},ce=(t,e)=>{if(!t.builder)return t;let r=t.builder,o=Y(r.baseType),s=P(o,e,(c)=>c.signature);return Object.assign({},t,{query:e,methodMatches:s,selectedIndex:0})},ae=(t,e)=>{let n=!t.builder,r=!t.builder?.arrowFnContext;if(n||r)return t;let o=t.builder.arrowFnContext,s=P(o.paramPaths,e,(c)=>c.path);return Object.assign({},t,{query:e,propertyMatches:s,selectedIndex:0})},sr=(t,e)=>{if(!t.builder)return t;let r=t.builder;if(e<0||e>=t.methodMatches.length)return t;let i=t.methodMatches[e].item.template||"";if(i.includes("x =>")||i.includes("(a, b)")||i.includes("(acc, x)")){let h=r.baseType==="Array"?(()=>{if(!Array.isArray(r.baseValue))return{};if(r.baseValue.length===0)return{};return r.baseValue[0]})():r.baseValue,N=Array.isArray(h)?"Array":h===null?"null":typeof h==="object"?"Object":typeof h==="string"?"String":typeof h==="number"?"Number":typeof h==="boolean"?"Boolean":"unknown",T=i.includes("(a, b)")?"a":"x",y=Nt(h),g={paramName:T,paramType:N,paramValue:h,paramPaths:y,expression:""},b=P(y,"",(S)=>S.path),R=Object.assign({},r,{currentMethodIndex:e,arrowFnContext:g,expression:r.expression+i});return Object.assign({},t,{mode:"build-arrow-fn",builder:R,query:"",selectedIndex:0,propertyMatches:b})}let a=r.expression+i,u=Object.assign({},r,{expression:a,currentMethodIndex:e});return Object.assign({},t,{builder:u})},or=(t,e)=>{let n=!t.builder,r=!t.builder?.arrowFnContext;if(n||r)return t;if(e<0||e>=t.propertyMatches.length)return t;let s=t.builder,i=s.arrowFnContext,c=t.propertyMatches[e].item,a=i.paramName,u=c.path==="."?a:`${a}${c.path}`,l=Object.assign({},i,{expression:u}),p=Object.assign({},s,{arrowFnContext:l});return Object.assign({},t,{builder:p})},ir=(t)=>{let e=!t.builder,n=!t.builder?.arrowFnContext;if(e||n)return t;let r=t.builder,o=r.arrowFnContext;if(!o.expression)return t;let a=Y(r.baseType)[r.currentMethodIndex].template||"",u=(h,N,T)=>{let y=h.lastIndexOf(N);if(y===-1)return h;return h.substring(0,y)+T+h.substring(y+N.length)},l=r.expression;if(a.includes("x => x"))l=u(l,"x => x",`x => ${o.expression}`);else if(a.includes("(a, b) => a - b"))l=u(l,"(a, b) => a - b",`(a, b) => ${o.expression}`);else if(a.includes("(acc, x) => acc"))l=u(l,"(acc, x) => acc",`(acc, x) => ${o.expression}`);let p=Object.assign({},r,{expression:l,arrowFnContext:null});return Object.assign({},t,{mode:"build",builder:p,query:"",selectedIndex:0})},ue=(t)=>{if(!t.builder)return t;let n=t.builder,s=Y(n.baseType)[n.currentMethodIndex].template||"",i=n.expression.replace(s,""),c=Object.assign({},n,{expression:i,arrowFnContext:null});return Object.assign({},t,{mode:"build",builder:c})},cr=(t)=>{if(!t.builder)return t;let n=t.builder,r=n.expression,o=r.lastIndexOf(".");if(o===-1)return ct(t);let c=r.lastIndexOf("(")>o?r.substring(0,o):r;if(c===n.basePath)return ct(t);let a=Object.assign({},n,{expression:c}),u=Y(n.baseType),l=P(u,"",(d)=>d.signature);return Object.assign({},t,{builder:a,methodMatches:l,query:"",selectedIndex:0})};var ar=x(()=>{nr()});var I,Yo=(t)=>{let e=t===I.CTRL_C,n=t===I.ESCAPE;return e||n||t==="q"},le=(t)=>t===I.ENTER,pe=(t)=>t===I.TAB,de=(t)=>t===I.UP,he=(t)=>t===I.DOWN,ur=(t)=>t===I.LEFT,lr=(t)=>t===I.RIGHT,me=(t)=>t===I.BACKSPACE,fe=(t)=>{let e=t>=" ",n=t<="~";return e&&n},Zo=(t,e)=>{if(pe(e))return{state:rr(t),output:null};if(le(e)){let n=Dn(t);if(!n)return{state:null,output:null};return{state:null,output:JSON.stringify(n.value,null,2)}}if(de(e))return{state:U(t,-1),output:null};if(he(e))return{state:U(t,1),output:null};if(me(e)){let n=t.query.slice(0,-1);return{state:re(t,n),output:null}}if(fe(e)){let n=t.query.concat(e);return{state:re(t,n),output:null}}return{state:t,output:null}},ti=(t,e)=>{if(e===I.ESCAPE)return{state:ct(t),output:null};if(le(e)){if(!t.builder)return{state:t,output:null};return{state:null,output:t.builder.expression}}if(lr(e)||pe(e)){if(!t.builder)return{state:t,output:null};return{state:sr(t,t.selectedIndex),output:null}}if(ur(e))return{state:cr(t),output:null};if(de(e))return{state:U(t,-1),output:null};if(he(e))return{state:U(t,1),output:null};if(me(e)){let n=t.query.slice(0,-1);return{state:ce(t,n),output:null}}if(fe(e)){let n=t.query.concat(e);return{state:ce(t,n),output:null}}return{state:t,output:null}},ei=(t,e)=>{if(e===I.ESCAPE)return{state:ue(t),output:null};if(le(e)){if(!t.builder)return{state:t,output:null};return{state:null,output:t.builder.expression}}if(lr(e)||pe(e)){let n=or(t,t.selectedIndex);return{state:ir(n),output:null}}if(ur(e))return{state:ue(t),output:null};if(de(e))return{state:U(t,-1),output:null};if(he(e))return{state:U(t,1),output:null};if(me(e)){let n=t.query.slice(0,-1);return{state:ae(t,n),output:null}}if(fe(e)){let n=t.query.concat(e);return{state:ae(t,n),output:null}}return{state:t,output:null}},ni,pr=(t,e)=>{let n=e.toString();if(Yo(n)){if(t.mode==="build"||t.mode==="build-arrow-fn")return{state:ct(t),output:null};return{state:null,output:null}}let r=ni[t.mode];return r(t,n)};var dr=x(()=>{se();ar();I=Object.assign({},{CTRL_C:"\x03",ESCAPE:"\x1B",ENTER:"\r",TAB:"\t",UP:"\x1B[A",DOWN:"\x1B[B",LEFT:"\x1B[D",RIGHT:"\x1B[C",BACKSPACE:"\x7F"}),ni={explore:Zo,build:ti,"build-arrow-fn":ei}});var hr={};O(hr,{runInteractive:()=>ii});import{stdin as ge,stdout as at,exit as ut}from"process";var xe=!1,It=()=>{if(xe)Wn(),Jn(),xe=!1;J()},be=(t)=>{It();let e=t instanceof Error?t.message:String(t),n=f(`Fatal error: ${e}
|
|
63
|
+
`,m.yellow);at.write(n),ut(1)},ri=()=>{process.on("uncaughtException",be),process.on("unhandledRejection",be),process.on("SIGINT",()=>{It(),ut(0)}),process.on("SIGTERM",()=>{It(),ut(0)})},si=(t,e)=>{return pr(t,e)},oi=async(t)=>{let e=t;return new Promise((n)=>{let r=(o)=>{let{state:s,output:i}=si(e,o);if(i!==null){ge.off("data",r),n(i);return}if(s===null){ge.off("data",r),n(null);return}e=s,ie(e)};ge.on("data",r)})},ii=async(t)=>{ri();let e=Nt(t);if(!(e.length>0)){let o=f(`No paths found in data
|
|
64
|
+
`,m.yellow);at.write(o),ut(1)}let r=jn(e,t);Un(),xe=!0,Gn(),ie(r);try{let o=await oi(r);if(It(),o!==null)try{let i=ot(o),a=new et(i).tokenize(),l=new nt(a).parse(),d=new rt().evaluate(l,t),h=JSON.stringify(d,null,2);at.write(h),at.write(`
|
|
65
|
+
`)}catch(i){let c=i instanceof Error?i.message:String(i);at.write(f("Error: "+c+`
|
|
66
|
+
`,m.yellow))}ut(0)}catch(o){be(o)}};var mr=x(()=>{se();er();dr();Ot();zt();Ht();Yt();Et()});var ye=["json","yaml","csv","table"],Se=["json","yaml","toml","csv","tsv","lines","text"],yr=[{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 Ct=(t,e)=>{let r=yr.filter((o)=>o.type===t).map((o)=>` ${o.short.padEnd(6)} -> ${o.full.padEnd(14)} ${o.description}`);return`${e}:
|
|
67
|
+
${r.join(`
|
|
68
|
+
`)}`},di=`Expression Shortcuts:
|
|
69
|
+
|
|
70
|
+
${Ct("array","Array Methods")}
|
|
71
|
+
|
|
72
|
+
${Ct("object","Object Methods")}
|
|
73
|
+
|
|
74
|
+
${Ct("string","String Methods")}
|
|
75
|
+
`;var we=ye,Ee=[...Se],Ae={format:"json",pretty:!1,raw:!1,compact:!1,type:!1,recursive:!1,ignoreCase:!1,showLineNumbers:!1,inputFormat:void 0};function Te(t){let e={...Ae},n=0;while(n<t.length){let r=t[n];switch(r){case"--help":case"-h":e.help=!0;break;case"--version":case"-v":e.version=!0;break;case"--raw":case"-r":e.raw=!0;break;case"--pretty":case"-p":e.pretty=!0;break;case"--compact":case"-c":e.compact=!0;break;case"--type":case"-t":e.type=!0;break;case"--format":if(n++,n<t.length){let s=t[n],i=we.includes(s);if(s&&i)e.format=s}break;case"--input-format":case"-if":if(n++,n<t.length){let s=t[n];if(Ee.includes(s))e.inputFormat=s}break;case"readFile":e.readFile=!0,n+=2;break;case"--find":case"-f":if(n++,n<t.length)e.find=t[n];break;case"--grep":case"-g":if(n++,n<t.length)e.grep=t[n];break;case"--list":case"-l":if(n++,n<t.length)e.list=t[n];break;case"--recursive":case"-R":e.recursive=!0;break;case"--interactive":e.interactive=!0;break;case"--ignore-case":case"-i":e.ignoreCase=!0;break;case"--line-numbers":case"-n":e.showLineNumbers=!0;break;case"--ext":if(n++,n<t.length){let s=t[n].split(",");e.extensions=s.map((i)=>i.startsWith(".")?i:`.${i}`)}break;case"--max-depth":if(n++,n<t.length)e.maxDepth=parseInt(t[n],10);break;case"--shorten":if(n++,n<t.length)e.shorten=t[n];break;case"--expand":if(n++,n<t.length)e.expand=t[n];break;case"--shortcuts":e.shortcuts=!0;break;case"--detect":e.detect=!0;break;default:if(r.startsWith(".")||r.startsWith("["))e.expression=r;break}n++}return e}function Rt(){console.log(`
|
|
13
76
|
1ls - 1 line script for JSON manipulation and file operations
|
|
14
77
|
|
|
15
78
|
Usage:
|
|
@@ -82,74 +145,15 @@ Examples:
|
|
|
82
145
|
1ls --shorten ".map(x => x * 2)" # Convert to shorthand
|
|
83
146
|
1ls --expand ".mp(x => x * 2)" # Convert to full form
|
|
84
147
|
1ls --shortcuts # Show all shortcuts
|
|
85
|
-
`)}
|
|
86
|
-
`)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
`,"\r"];function _(e,t,n){return{type:e,value:t,position:n}}class H{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(_("EOF","",this.position)),e}nextToken(){let e=this.position,t=Rt[this.current];if(t){let u=this.current;return this.advance(),_(t,u,e)}if(this.current==="="&&this.peek()===">")return this.advance(),this.advance(),_("ARROW","=>",e);if(this.current==='"'||this.current==="'")return this.readString();let o=this.isDigit(this.current),s=this.current==="-"&&this.isDigit(this.peek());if(o||s)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 _("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 _("NUMBER",t,e)}readIdentifier(){let e=this.position,t="";while(this.isIdentifierChar(this.current))t+=this.current,this.advance();return _("IDENTIFIER",t,e)}readOperator(){let e=this.position,t="";while(this.isOperator(this.current))t+=this.current,this.advance();return _("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 Ft.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 Mt.includes(e)}}var v=(e)=>{return{type:"Literal",value:e}},Te=(e)=>{if(e==="true")return v(!0);if(e==="false")return v(!1);if(e==="null")return v(null);return};function C(e,t){return`${t} at position ${e.position} (got ${e.type}: "${e.value}")`}function B(e,t){return{type:"PropertyAccess",property:e,object:t}}function Wr(e,t){return{type:"IndexAccess",index:e,object:t}}function Jr(e,t,n){return{type:"SliceAccess",start:e,end:t,object:n}}function Lt(e,t,n){return{type:"MethodCall",method:e,args:t,object:n}}function Ur(e,t){return{type:"ObjectOperation",operation:e,object:t}}function zr(e){return{type:"ArraySpread",object:e}}function Qr(e,t){return{type:"ArrowFunction",params:e,body:t}}function Oe(e){return{type:"Root",expression:e}}var Pt=["keys","values","entries","length"];function Hr(e){return Pt.includes(e)}class K{tokens;position=0;current;constructor(e){this.tokens=e,this.current=this.tokens[0]}parse(){if(this.current.type==="EOF")return Oe();let t=this.parseExpression();return Oe(t)}parseExpression(){return this.parsePrimary()}parsePrimary(){let e=this.parsePrimaryNode();return this.parsePostfix(e)}parsePrimaryNode(){let e=this.current.type;if(e==="DOT")return this.advance(),this.parseAccessChain();if(e==="LEFT_BRACKET")return this.parseArrayAccess();if(e==="IDENTIFIER")return this.parseIdentifierOrFunction();if(e==="STRING"){let t=this.current.value;return this.advance(),v(t)}if(e==="NUMBER"){let t=Number(this.current.value);return this.advance(),v(t)}if(e==="LEFT_PAREN"){let t=this.parseFunctionParams();return this.parseArrowFunction(t)}throw Error(C(this.current,"Unexpected token"))}parseAccessChain(e){let t=this.current.type;if(t==="IDENTIFIER"){let n=this.current.value;return this.advance(),B(n,e)}if(t==="LEFT_BRACKET")return this.parseBracketAccess(e);if(t==="LEFT_BRACE")return this.parseObjectOperation(e);throw Error(C(this.current,"Expected property name after dot"))}parseBracketAccess(e){if(this.advance(),this.current.type==="RIGHT_BRACKET")return this.advance(),zr(e);if(this.current.type==="STRING"){let c=this.current.value;return this.advance(),this.expect("RIGHT_BRACKET"),B(c,e)}let r=this.current.type==="NUMBER",o=this.current.type==="OPERATOR"&&this.current.value==="-",s=this.current.type==="COLON";if(r||o||s)return this.parseNumericIndexOrSlice(e);throw Error(C(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"),Wr(n,e)}parseSliceFromColon(e,t){this.advance();let n=this.current.type==="NUMBER",r=this.current.type==="OPERATOR"&&this.current.value==="-",o=n||r,s=o?this.parseNumber():void 0;if(o)this.advance();return this.expect("RIGHT_BRACKET"),Jr(e,s,t)}parseArrayAccess(){return this.parseBracketAccess()}parseObjectOperation(e){if(this.advance(),this.current.type!=="IDENTIFIER")throw Error(C(this.current,"Expected operation name after {"));let n=this.current.value;if(!Hr(n)){let r=Pt.join(", ");throw Error(C(this.current,`Invalid object operation "${n}". Valid operations: ${r}`))}return this.advance(),this.expect("RIGHT_BRACE"),Ur(n,e)}parseIdentifierOrFunction(){let e=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([e]);let n=Te(e);if(n)return n;return B(e)}parseArrowFunction(e){this.expect("ARROW");let t=this.parseFunctionBody();return Qr(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=Lt(`__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(),v(t)}if(e==="STRING"){let t=this.current.value;return this.advance(),v(t)}if(e==="LEFT_PAREN"){this.advance();let t=this.parseBinaryExpression();return this.expect("RIGHT_PAREN"),t}throw Error(C(this.current,"Unexpected token in function body"))}parseIdentifierChain(){let e=this.current.value;this.advance();let t=Te(e);if(t)return t;let n=B(e),r=()=>this.current.type==="DOT",o=()=>this.current.type==="IDENTIFIER";while(r()){if(this.advance(),!o())break;let s=this.current.value;this.advance(),n=B(s,n)}return n}parseMethodCall(e,t){this.expect("LEFT_PAREN");let n=this.parseMethodArguments();return this.expect("RIGHT_PAREN"),Lt(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 B(t)}if(e==="NUMBER"){let t=Number(this.current.value);return this.advance(),v(t)}if(e==="STRING"){let t=this.current.value;return this.advance(),v(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==="DOT"){t=this.parsePostfixDot(t);continue}if(n==="LEFT_BRACKET"){t=this.parseBracketAccess(t);continue}if(n==="LEFT_PAREN"){if(t.type==="PropertyAccess"&&!t.object){let s=t.property;t=this.parseMethodCall(Oe(),s);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 B(n,e)}if(t==="LEFT_BRACKET")return this.parseBracketAccess(e);if(t==="LEFT_BRACE")return this.parseObjectOperation(e);throw Error(C(this.current,"Expected property name after dot"))}parseNumber(){let e=this.current.value==="-";if(e)this.advance();if(this.current.type!=="NUMBER")throw Error(C(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(C(this.current,`Expected ${e} but got ${this.current.type}`));this.advance()}}var Kr={"+":(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};function kt(e){return e.startsWith("__operator_")&&e.endsWith("__")}function _t(e){return e.slice(11,-2)}function Bt(e,t,n){let r=Kr[t];if(!r)throw Error(`Unknown operator: ${t}`);return r(e,n)}function Xr(e,t){return Object.fromEntries(e.map((n,r)=>[n,t[r]]))}function ve(e){return Object.values(e)[0]}function Dt(e){return e!==null&&typeof e==="object"}function Ie(e,t){if(!Dt(e))return;return e[t]}function Ce(e,t){return e<0?t+e:e}function qr(e,t){if(!Array.isArray(e))return;let n=Ce(t,e.length);return e[n]}function Yr(e,t,n){if(!Array.isArray(e))return;let r=e.length,o=t!==void 0?Ce(t,r):0,s=n!==void 0?Ce(n,r):r;return e.slice(o,s)}function Zr(e,t){if(!Dt(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}}function jt(e,t,n){let r=e;if(!(e!==null&&e!==void 0&&typeof r[t]==="function"))throw Error(`Method ${t} does not exist on ${typeof e}`);try{return r[t].call(e,...n)}catch(s){let i=s instanceof Error?s.message:String(s);throw Error(`Error executing method ${t}: ${i}`)}}class X{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 qr(e.object?this.evaluate(e.object,t):t,e.index);case"SliceAccess":return Yr(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 Zr(e.object?this.evaluate(e.object,t):t,e.operation);case"Literal":return e.value;case"ArrowFunction":return this.createFunction(e);default:throw Error(`Unknown AST node type: ${e.type}`)}}evaluatePropertyAccess(e,t){let n=e.object?this.evaluate(e.object,t):t;return Ie(n,e.property)}evaluateMethodCall(e,t){let n=e.object?this.evaluate(e.object,t):t;if(kt(e.method)){let s=_t(e.method),i=this.evaluate(e.args[0],t);return Bt(n,s,i)}let o=e.args.map((s)=>{return s.type==="ArrowFunction"?this.createFunction(s):this.evaluate(s,t)});return jt(n,e.method,o)}createFunction(e){return(...t)=>{let n=Xr(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,ve(t))}}evaluatePropertyAccessInFunction(e,t){if(e.object!==void 0){let s=this.evaluateFunctionBody(e.object,t);return Ie(s,e.property)}if(Object.prototype.hasOwnProperty.call(t,e.property))return t[e.property];let o=ve(t);return Ie(o,e.property)}evaluateMethodCallInFunction(e,t){let n=e.object?this.evaluateFunctionBody(e.object,t):ve(t);if(kt(e.method)){let s=_t(e.method),i=this.evaluateFunctionBody(e.args[0],t);return Bt(n,s,i)}let o=e.args.map((s)=>this.evaluateFunctionBody(s,t));return jt(n,e.method,o)}}var b={reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",gray:"\x1B[90m"},es=[{regex:/"([^"]+)":/g,replacement:`${b.cyan}"$1"${b.reset}:`},{regex:/: "([^"]*)"/g,replacement:`: ${b.green}"$1"${b.reset}`},{regex:/: (-?\d+\.?\d*)/g,replacement:`: ${b.yellow}$1${b.reset}`},{regex:/: (true|false)/g,replacement:`: ${b.magenta}$1${b.reset}`},{regex:/: (null)/g,replacement:`: ${b.gray}$1${b.reset}`},{regex:/([{[])/g,replacement:`${b.gray}$1${b.reset}`},{regex:/([}\]])/g,replacement:`${b.gray}$1${b.reset}`}];function Vt(e){if(process.env.NO_COLOR)return e;return es.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function $t(e){if(process.env.NO_COLOR)return e;return`${b.yellow}${e}${b.reset}`}function Re(e){if(process.env.NO_COLOR)return e;return`${b.cyan}${e}${b.reset}`}class q{options;constructor(e){this.options=e}format(e){if(this.options.raw)return this.formatRaw(e);if(this.options.type)return this.formatWithType(e);switch(this.options.format){case"yaml":return this.formatYaml(e);case"csv":return this.formatCsv(e);case"table":return this.formatTable(e);default:return this.formatJson(e)}}formatRaw(e){if(typeof e==="string")return e;if(e===void 0)return"";if(e===null)return"null";if(typeof e==="object")return JSON.stringify(e);return String(e)}formatJson(e){if(e===void 0)return"undefined";if(this.options.compact)return JSON.stringify(e);if(this.options.pretty){let t=JSON.stringify(e,null,2);return Vt(t)}return JSON.stringify(e,null,2)}formatWithType(e){let t=Array.isArray(e)?"array":typeof e,n=this.formatJson(e);return`[${t}] ${n}`}formatYaml(e){return this.toYaml(e,0)}toYaml(e,t){let n=" ".repeat(t);if(e===null||e===void 0)return"null";if(typeof e==="string")return e.includes(`
|
|
90
|
-
`)||e.includes('"')||e.includes("'")?`|
|
|
91
|
-
${n} ${e.replace(/\n/g,`
|
|
92
|
-
`+n+" ")}`:e;if(typeof e==="number"||typeof e==="boolean")return String(e);if(Array.isArray(e)){if(e.length===0)return"[]";return e.map((r)=>`${n}- ${this.toYaml(r,t+2).trim()}`).join(`
|
|
93
|
-
`)}if(typeof e==="object"){let r=Object.entries(e);if(r.length===0)return"{}";return r.map(([o,s])=>{let i=this.toYaml(s,t+2);if(typeof s==="object"&&s!==null)return`${n}${o}:
|
|
148
|
+
`)}Wt();Jt();zt();Ht();Yt();var A={reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",gray:"\x1B[90m"},co=[{regex:/"([^"]+)":/g,replacement:`${A.cyan}"$1"${A.reset}:`},{regex:/: "([^"]*)"/g,replacement:`: ${A.green}"$1"${A.reset}`},{regex:/: (-?\d+\.?\d*)/g,replacement:`: ${A.yellow}$1${A.reset}`},{regex:/: (true|false)/g,replacement:`: ${A.magenta}$1${A.reset}`},{regex:/: (null)/g,replacement:`: ${A.gray}$1${A.reset}`},{regex:/([{[])/g,replacement:`${A.gray}$1${A.reset}`},{regex:/([}\]])/g,replacement:`${A.gray}$1${A.reset}`}];function Mn(t){if(process.env.NO_COLOR)return t;return co.reduce((e,{regex:n,replacement:r})=>e.replace(n,r),t)}function Ln(t){if(process.env.NO_COLOR)return t;return`${A.yellow}${t}${A.reset}`}function Zt(t){if(process.env.NO_COLOR)return t;return`${A.cyan}${t}${A.reset}`}class st{options;constructor(t){this.options=t}format(t){if(this.options.raw)return this.formatRaw(t);if(this.options.type)return this.formatWithType(t);switch(this.options.format){case"yaml":return this.formatYaml(t);case"csv":return this.formatCsv(t);case"table":return this.formatTable(t);default:return this.formatJson(t)}}formatRaw(t){if(typeof t==="string")return t;if(t===void 0)return"";if(t===null)return"null";if(typeof t==="object")return JSON.stringify(t);return String(t)}formatJson(t){if(t===void 0)return"undefined";if(this.options.compact)return JSON.stringify(t);if(this.options.pretty){let e=JSON.stringify(t,null,2);return Mn(e)}return JSON.stringify(t,null,2)}formatWithType(t){let e=Array.isArray(t)?"array":typeof t,n=this.formatJson(t);return`[${e}] ${n}`}formatYaml(t){return this.toYaml(t,0)}toYaml(t,e){let n=" ".repeat(e);if(t===null||t===void 0)return"null";if(typeof t==="string")return t.includes(`
|
|
149
|
+
`)||t.includes('"')||t.includes("'")?`|
|
|
150
|
+
${n} ${t.replace(/\n/g,`
|
|
151
|
+
`+n+" ")}`:t;if(typeof t==="number"||typeof t==="boolean")return String(t);if(Array.isArray(t)){if(t.length===0)return"[]";return t.map((r)=>`${n}- ${this.toYaml(r,e+2).trim()}`).join(`
|
|
152
|
+
`)}if(typeof t==="object"){let r=Object.entries(t);if(r.length===0)return"{}";return r.map(([o,s])=>{let i=this.toYaml(s,e+2);if(typeof s==="object"&&s!==null)return`${n}${o}:
|
|
94
153
|
${i}`;return`${n}${o}: ${i}`}).join(`
|
|
95
|
-
`)}return String(
|
|
96
|
-
`)}return
|
|
97
|
-
`)}escapeCsvValue(
|
|
98
|
-
`))return`"${
|
|
99
|
-
`)}formatObjectTable(
|
|
100
|
-
`)}}
|
|
101
|
-
${s}:
|
|
102
|
-
`,l=i.map((p)=>` ${p.short.padEnd(c+2)} \u2192 ${p.full.padEnd(a+2)} # ${p.description}`).join(`
|
|
103
|
-
`);return u+l};return`
|
|
104
|
-
Shorthand Reference:
|
|
105
|
-
${o("Array Methods",e)}
|
|
106
|
-
${o("Object Methods",t)}
|
|
107
|
-
${o("String Methods",n)}
|
|
108
|
-
${o("Universal Methods",r)}
|
|
109
|
-
|
|
110
|
-
Examples:
|
|
111
|
-
echo '[1,2,3]' | 1ls '.mp(x => x * 2)' # Short form
|
|
112
|
-
echo '[1,2,3]' | 1ls '.map(x => x * 2)' # Full form
|
|
113
|
-
|
|
114
|
-
1ls --shorten ".map(x => x * 2)" # Returns: .mp(x => x * 2)
|
|
115
|
-
1ls --expand ".mp(x => x * 2)" # Returns: .map(x => x * 2)
|
|
116
|
-
`}import{stdin as Ue,stdout as ne,exit as ze}from"process";var he=(e)=>{if(e===null)return"null";if(Array.isArray(e))return"Array";let t=typeof e;return t.charAt(0).toUpperCase()+t.slice(1)},me=(e,t)=>{if(t==="null")return"null";if(t==="String")return`"${e}"`;if(t==="Array")return`[${e.length} items]`;if(t==="Object")return`{${Object.keys(e).length} keys}`;return String(e)},Fe=(e,t="",n=[])=>{if(e===null||e===void 0){let i=he(e),c=me(e,i);return n.push({path:t||".",value:e,type:i,displayValue:c}),n}if(Array.isArray(e)){let i=he(e),c=me(e,i),a=t||".";return n.push({path:a,value:e,type:i,displayValue:c}),e.forEach((u,l)=>{let p=t?`${t}[${l}]`:`.[${l}]`;Fe(u,p,n)}),n}if(typeof e==="object"){let i=he(e),c=me(e,i),a=t||".";if(t)n.push({path:a,value:e,type:i,displayValue:c});return Object.entries(e).forEach(([l,p])=>{let d=/[^a-zA-Z0-9_$]/.test(l),h=t?d?`${t}["${l}"]`:`${t}.${l}`:d?`.["${l}"]`:`.${l}`;Fe(p,h,n)}),n}let r=he(e),o=me(e,r),s=t||".";return n.push({path:s,value:e,type:r,displayValue:o}),n},de=(e)=>{return Fe(e)};var ss=(e,t,n)=>{let r=n.length*100,o=(p,d,h)=>{if(h===0)return p;let w=n[h-1]===d-1?5:0;return p+w},s=n.reduce(o,0),a=n[0]===0?10:0,u=e.length-t.length;return r+s+a-u},os=(e,t)=>{let n=e.toLowerCase(),r=t.toLowerCase(),o=[],s=0,i=0,c=()=>{let u=s<n.length,l=i<r.length;return u&&l};while(c()){let u=n[s],l=r[i];if(u===l)o.push(s),i=i+1;s=s+1}return i===r.length?o:null},is=(e,t,n)=>{let r=os(t,n);if(!r)return null;let s=ss(t,n,r);return Object.assign({},{item:e,score:s,matches:r})},cs=(e,t)=>t.score-e.score,R=(e,t,n)=>{if(!t){let u=(l)=>{return Object.assign({},{item:l,score:0,matches:[]})};return e.map(u)}let o=(u)=>{let l=n(u);return is(u,l,t)},s=e.map(o),i=(u)=>u!==null;return s.filter(i).sort(cs)};var Jt=(e,t)=>{let n=R(e,"",(o)=>o.path);return Object.assign({},{mode:"explore",paths:e,matches:n,query:"",selectedIndex:0,builder:null,originalData:t,methodMatches:[],propertyMatches:[]})},Le=(e,t)=>{let n=R(e.paths,t,(s)=>s.path),r=n.length>0?0:e.selectedIndex;return Object.assign({},e,{query:t,matches:n,selectedIndex:r})},D=(e,t)=>{let n=e.mode==="explore",r=e.mode==="build",o=n?e.matches.length:r?e.methodMatches.length:e.propertyMatches.length;if(o===0)return e;let c=e.selectedIndex+t;if(c<0)c=o-1;else if(c>=o)c=0;return Object.assign({},e,{selectedIndex:c})},Ut=(e)=>{let t=e.matches.length>0,n=e.selectedIndex>=0&&e.selectedIndex<e.matches.length;if(t&&n)return e.matches[e.selectedIndex].item;return null};import{stdout as ee}from"process";import{stdout as Pe}from"process";var V=()=>{Pe.write("\x1B[2J\x1B[H")};var zt=()=>{Pe.write("\x1B[?25l")},Qt=()=>{Pe.write("\x1B[?25h")},Ht=()=>{if(process.stdin.setRawMode!==void 0)process.stdin.setRawMode(!0);process.stdin.resume()},Kt=()=>{if(process.stdin.setRawMode!==void 0)process.stdin.setRawMode(!1);process.stdin.pause()},m=Object.assign({},{reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",cyan:"\x1B[36m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",gray:"\x1B[90m"}),f=(e,t)=>{let n=m.reset;return t.concat(e,n)},Z=(e,t)=>{let n=e.split(""),r=m.bright.concat(m.cyan),o=(c,a)=>{return t.includes(a)?f(c,r):c};return n.map(o).join("")};import{stdout as F}from"process";var A=10,as=(e,t)=>Z(e,t),us=(e)=>{let t=`[${e}]`;return f(t,m.dim)},ls=(e)=>f(e,m.gray),Xt=(e)=>{let t=f("\u276F",m.green),n=" ";return e?t:" "},ps=(e,t,n)=>{let r=Xt(t),o=as(e.signature,n),s=e.category?us(e.category):"",i=ls(e.description);return r.concat(" ",o).concat(s?" "+s:"").concat(" - ",i)},hs=(e,t)=>{let{item:n,matches:r}=e,o=Xt(t),s=Z(n.path,r),i=f(`[${n.type}]`,m.dim),c=f(n.displayValue,m.gray);return o.concat(" ",s).concat(" ",i).concat(" ",c)},ms=(e)=>{if(e.builder===null)return"";let n="Expression Builder",r=m.bright.concat(m.cyan),o=f(n,r),s=e.builder.expression,i=`
|
|
117
|
-
|
|
118
|
-
Building: `,c=f(s,m.bright.concat(m.yellow)),a=`
|
|
119
|
-
|
|
120
|
-
Search methods for `,u=f(e.builder.baseType,m.bright),l=": ",p=e.query;return o.concat(i,c).concat(a,u,l,p,`
|
|
121
|
-
|
|
122
|
-
`)},ds=(e)=>{let t=e.builder!==null,n=e.builder?.arrowFnContext!==null;if(!t||!n)return"";let r="Expression Builder - Arrow Function",o=m.bright.concat(m.cyan),s=f(r,o),i=e.builder.expression,c=`
|
|
123
|
-
|
|
124
|
-
Building: `,a=f(i,m.bright.concat(m.yellow)),u=e.builder.arrowFnContext,l=`
|
|
125
|
-
|
|
126
|
-
Search properties for '${u.paramName}' (${u.paramType}): `,p=e.query;return s.concat(c,a).concat(l,p,`
|
|
127
|
-
|
|
128
|
-
`)},fs=(e)=>{if(e.builder===null)return"";let{methodMatches:n,selectedIndex:r}=e;if(n.length===0)return f("No methods found",m.dim);let o=Math.floor(A/2),s=Math.max(0,r-o),i=Math.min(n.length,s+A);if(i-s<A&&n.length>=A)s=Math.max(0,i-A);let a=n.slice(s,i),u=(d,h)=>{let y=s+h===r;return ps(d.item,y,d.matches)};return a.map(u).join(`
|
|
129
|
-
`)},gs=(e)=>{let t=e.builder===null,n=e.builder?.arrowFnContext===null;if(t||n)return"";let{propertyMatches:r,selectedIndex:o}=e;if(r.length===0)return f("No properties found",m.dim);let s=Math.floor(A/2),i=Math.max(0,o-s),c=Math.min(r.length,i+A);if(c-i<A&&r.length>=A)i=Math.max(0,c-A);let u=r.slice(i,c),l=(h,g)=>{let x=i+g===o;return hs(h,x)};return u.map(l).join(`
|
|
130
|
-
`)},qt=(e)=>{let t=e-A;if(t>0){let r=`
|
|
131
|
-
|
|
132
|
-
... `.concat(String(t)," more");return f(r,m.dim)}return""},Yt=()=>{let e=`
|
|
133
|
-
|
|
134
|
-
`.concat(f("\u2191/\u2193",m.bright)," navigate ",f("\u2192/Tab",m.bright)," accept ",f("\u2190",m.bright)," undo ",f("Enter",m.bright)," execute ",f("Esc",m.bright)," quit");return f(e,m.dim)},Zt=(e)=>{V();let t=ms(e);F.write(t);let n=fs(e);F.write(n);let r=e.methodMatches.length,o=qt(r);F.write(o);let s=Yt();F.write(s)},en=(e)=>{V();let t=ds(e);F.write(t);let n=gs(e);F.write(n);let r=e.propertyMatches.length,o=qt(r);F.write(o);let s=Yt();F.write(s)};var J=10,xs=(e,t)=>Z(e,t),bs=(e)=>{let r="[".concat(e,"]");return f(r,m.dim)},Ss=(e)=>f(e,m.gray),ys=(e)=>{let t=f("\u276F",m.green),n=" ";return e?t:" "},ws=(e,t)=>{let{item:n,matches:r}=e,o=ys(t),s=xs(n.path,r),i=bs(n.type),c=Ss(n.displayValue);return o.concat(" ",s).concat(" ",i).concat(" ",c)},Es=()=>{let t=m.bright.concat(m.cyan);return f("1ls Interactive Explorer",t)},Ns=(e)=>{let t=Es(),n=`
|
|
135
|
-
|
|
136
|
-
Search: `;return t.concat(`
|
|
137
|
-
|
|
138
|
-
Search: `,e,`
|
|
139
|
-
|
|
140
|
-
`)},As=(e)=>{let t=e.selectedIndex,n=e.matches.length;if(n===0)return f("No matches found",m.dim);let r=Math.floor(J/2),o=Math.max(0,t-r),s=Math.min(n,o+J);if(s-o<J&&n>=J)o=Math.max(0,s-J);let c=e.matches.slice(o,s),a=(p,d)=>{let g=o+d===t;return ws(p,g)};return c.map(a).join(`
|
|
141
|
-
`)},Ts=(e)=>{let t=e.matches.length>0,n=e.selectedIndex>=0&&e.selectedIndex<e.matches.length;if(!t||!n)return"";let r=e.matches[e.selectedIndex].item,o=f(`
|
|
142
|
-
|
|
143
|
-
Preview:
|
|
144
|
-
`,m.bright),s="",i=r.type;if(i==="String"||i==="Number"||i==="Boolean"||i==="null")s=f(String(r.displayValue),m.cyan);else if(i==="Array"||i==="Object"){let a=JSON.stringify(r.value,null,2).split(`
|
|
145
|
-
`),u=a.slice(0,5),l=a.length>5;if(s=f(u.join(`
|
|
146
|
-
`),m.cyan),l)s=s.concat(f(`
|
|
147
|
-
... (truncated)`,m.dim))}else s=f(String(r.value),m.cyan);return o.concat(s)},Os=(e)=>{let t=e-J;if(t>0){let r=`
|
|
148
|
-
|
|
149
|
-
... `.concat(String(t)," more");return f(r,m.dim)}return""},vs=()=>{let e=`
|
|
150
|
-
|
|
151
|
-
`.concat(f("\u2191/\u2193",m.bright)," navigate ",f("Enter",m.bright)," select ",f("Tab",m.bright)," build ",f("Esc/q",m.bright)," quit");return f(e,m.dim)},Is=(e)=>{V();let t=Ns(e.query);ee.write(t);let n=As(e);ee.write(n);let r=Os(e.matches.length);ee.write(r);let o=Ts(e);ee.write(o);let s=vs();ee.write(s)},Cs={explore:Is,build:Zt,"build-arrow-fn":en},ke=(e)=>{let t=Cs[e.mode];t(e)};var Rs=[{name:"map",signature:".map(x => ...)",description:"Transform each item",template:".map(x => x)",category:"Transform"},{name:"filter",signature:".filter(x => ...)",description:"Filter by condition",template:".filter(x => x)",category:"Filter"},{name:"reduce",signature:".reduce((acc, x) => ..., initial)",description:"Reduce to single value",template:".reduce((acc, x) => acc, 0)",category:"Aggregate"},{name:"find",signature:".find(x => ...)",description:"Find first match",template:".find(x => x)",category:"Search"},{name:"findIndex",signature:".findIndex(x => ...)",description:"Find first match index",template:".findIndex(x => x)",category:"Search"},{name:"some",signature:".some(x => ...)",description:"Check if any match",template:".some(x => x)",category:"Test"},{name:"every",signature:".every(x => ...)",description:"Check if all match",template:".every(x => x)",category:"Test"},{name:"sort",signature:".sort((a, b) => ...)",description:"Sort items",template:".sort((a, b) => a - b)",category:"Transform"},{name:"reverse",signature:".reverse()",description:"Reverse order",template:".reverse()",category:"Transform"},{name:"slice",signature:".slice(start, end)",description:"Get subset",template:".slice(0, 10)",category:"Transform"},{name:"concat",signature:".concat(arr)",description:"Combine arrays",template:".concat([])",category:"Transform"},{name:"join",signature:".join(separator)",description:"Join to string",template:".join(', ')",category:"Convert"},{name:"flat",signature:".flat(depth)",description:"Flatten nested arrays",template:".flat(1)",category:"Transform"},{name:"flatMap",signature:".flatMap(x => ...)",description:"Map then flatten",template:".flatMap(x => x)",category:"Transform"},{name:"length",signature:".length",description:"Get array length",template:".length",category:"Property"}],Ms=[{name:"toUpperCase",signature:".toUpperCase()",description:"Convert to uppercase",template:".toUpperCase()",category:"Transform"},{name:"toLowerCase",signature:".toLowerCase()",description:"Convert to lowercase",template:".toLowerCase()",category:"Transform"},{name:"trim",signature:".trim()",description:"Remove whitespace",template:".trim()",category:"Transform"},{name:"trimStart",signature:".trimStart()",description:"Remove leading whitespace",template:".trimStart()",category:"Transform"},{name:"trimEnd",signature:".trimEnd()",description:"Remove trailing whitespace",template:".trimEnd()",category:"Transform"},{name:"split",signature:".split(separator)",description:"Split into array",template:".split(',')",category:"Convert"},{name:"replace",signature:".replace(search, replace)",description:"Replace first match",template:".replace('old', 'new')",category:"Transform"},{name:"replaceAll",signature:".replaceAll(search, replace)",description:"Replace all matches",template:".replaceAll('old', 'new')",category:"Transform"},{name:"substring",signature:".substring(start, end)",description:"Extract substring",template:".substring(0, 10)",category:"Transform"},{name:"slice",signature:".slice(start, end)",description:"Extract slice",template:".slice(0, 10)",category:"Transform"},{name:"startsWith",signature:".startsWith(str)",description:"Check if starts with",template:".startsWith('prefix')",category:"Test"},{name:"endsWith",signature:".endsWith(str)",description:"Check if ends with",template:".endsWith('suffix')",category:"Test"},{name:"includes",signature:".includes(str)",description:"Check if contains",template:".includes('text')",category:"Test"},{name:"match",signature:".match(regex)",description:"Match regex pattern",template:".match(/pattern/)",category:"Search"},{name:"length",signature:".length",description:"Get string length",template:".length",category:"Property"}],Fs=[{name:"keys",signature:".{keys}",description:"Get object keys",template:".{keys}",category:"Convert"},{name:"values",signature:".{values}",description:"Get object values",template:".{values}",category:"Convert"},{name:"entries",signature:".{entries}",description:"Get key-value pairs",template:".{entries}",category:"Convert"},{name:"length",signature:".{length}",description:"Get property count",template:".{length}",category:"Property"}],Ls=[{name:"toFixed",signature:".toFixed(decimals)",description:"Format with decimals",template:".toFixed(2)",category:"Format"},{name:"toString",signature:".toString()",description:"Convert to string",template:".toString()",category:"Convert"}],U=(e)=>{switch(e){case"Array":return Rs;case"String":return Ms;case"Object":return Fs;case"Number":return Ls;default:return[]}};var tn=(e)=>{let t=e.matches.length>0,n=e.selectedIndex>=0&&e.selectedIndex<e.matches.length;if(!t||!n)return e;let r=e.matches[e.selectedIndex].item,o={basePath:r.path,baseValue:r.value,baseType:r.type,expression:r.path,currentMethodIndex:0,arrowFnContext:null},s=U(r.type),i=R(s,"",(a)=>a.signature);return Object.assign({},e,{mode:"build",builder:o,query:"",selectedIndex:0,methodMatches:i})},te=(e)=>{return Object.assign({},e,{mode:"explore",builder:null,selectedIndex:0})},_e=(e,t)=>{if(!e.builder)return e;let r=e.builder,o=U(r.baseType),s=R(o,t,(c)=>c.signature);return Object.assign({},e,{query:t,methodMatches:s,selectedIndex:0})},Be=(e,t)=>{let n=!e.builder,r=!e.builder?.arrowFnContext;if(n||r)return e;let o=e.builder.arrowFnContext,s=R(o.paramPaths,t,(c)=>c.path);return Object.assign({},e,{query:t,propertyMatches:s,selectedIndex:0})},nn=(e,t)=>{if(!e.builder)return e;let r=e.builder;if(t<0||t>=e.methodMatches.length)return e;let i=e.methodMatches[t].item.template||"";if(i.includes("x =>")||i.includes("(a, b)")||i.includes("(acc, x)")){let h=r.baseType==="Array"?(()=>{if(!Array.isArray(r.baseValue))return{};if(r.baseValue.length===0)return{};return r.baseValue[0]})():r.baseValue,g=Array.isArray(h)?"Array":h===null?"null":typeof h==="object"?"Object":typeof h==="string"?"String":typeof h==="number"?"Number":typeof h==="boolean"?"Boolean":"unknown",y=i.includes("(a, b)")?"a":"x",x=de(h),w={paramName:y,paramType:g,paramValue:h,paramPaths:x,expression:""},L=R(x,"",(P)=>P.path),E=Object.assign({},r,{currentMethodIndex:t,arrowFnContext:w,expression:r.expression+i});return Object.assign({},e,{mode:"build-arrow-fn",builder:E,query:"",selectedIndex:0,propertyMatches:L})}let a=r.expression+i,u=Object.assign({},r,{expression:a,currentMethodIndex:t});return Object.assign({},e,{builder:u})},rn=(e,t)=>{let n=!e.builder,r=!e.builder?.arrowFnContext;if(n||r)return e;if(t<0||t>=e.propertyMatches.length)return e;let s=e.builder,i=s.arrowFnContext,c=e.propertyMatches[t].item,a=i.paramName,u=c.path==="."?a:`${a}${c.path}`,l=Object.assign({},i,{expression:u}),p=Object.assign({},s,{arrowFnContext:l});return Object.assign({},e,{builder:p})},sn=(e)=>{let t=!e.builder,n=!e.builder?.arrowFnContext;if(t||n)return e;let r=e.builder,o=r.arrowFnContext;if(!o.expression)return e;let a=U(r.baseType)[r.currentMethodIndex].template||"",u=(h,g,y)=>{let x=h.lastIndexOf(g);if(x===-1)return h;return h.substring(0,x)+y+h.substring(x+g.length)},l=r.expression;if(a.includes("x => x"))l=u(l,"x => x",`x => ${o.expression}`);else if(a.includes("(a, b) => a - b"))l=u(l,"(a, b) => a - b",`(a, b) => ${o.expression}`);else if(a.includes("(acc, x) => acc"))l=u(l,"(acc, x) => acc",`(acc, x) => ${o.expression}`);let p=Object.assign({},r,{expression:l,arrowFnContext:null});return Object.assign({},e,{mode:"build",builder:p,query:"",selectedIndex:0})},je=(e)=>{if(!e.builder)return e;let n=e.builder,s=U(n.baseType)[n.currentMethodIndex].template||"",i=n.expression.replace(s,""),c=Object.assign({},n,{expression:i,arrowFnContext:null});return Object.assign({},e,{mode:"build",builder:c})},on=(e)=>{if(!e.builder)return e;let n=e.builder,r=n.expression,o=r.lastIndexOf(".");if(o===-1)return te(e);let c=r.lastIndexOf("(")>o?r.substring(0,o):r;if(c===n.basePath)return te(e);let a=Object.assign({},n,{expression:c}),u=U(n.baseType),l=R(u,"",(d)=>d.signature);return Object.assign({},e,{builder:a,methodMatches:l,query:"",selectedIndex:0})};var T=Object.assign({},{CTRL_C:"\x03",ESCAPE:"\x1B",ENTER:"\r",TAB:"\t",UP:"\x1B[A",DOWN:"\x1B[B",LEFT:"\x1B[D",RIGHT:"\x1B[C",BACKSPACE:"\x7F"}),Ps=(e)=>{let t=e===T.CTRL_C,n=e===T.ESCAPE;return t||n||e==="q"},De=(e)=>e===T.ENTER,Ve=(e)=>e===T.TAB,$e=(e)=>e===T.UP,Ge=(e)=>e===T.DOWN,cn=(e)=>e===T.LEFT,an=(e)=>e===T.RIGHT,We=(e)=>e===T.BACKSPACE,Je=(e)=>{let t=e>=" ",n=e<="~";return t&&n},ks=(e,t)=>{if(Ve(t))return{state:tn(e),output:null};if(De(t)){let n=Ut(e);if(!n)return{state:null,output:null};return{state:null,output:JSON.stringify(n.value,null,2)}}if($e(t))return{state:D(e,-1),output:null};if(Ge(t))return{state:D(e,1),output:null};if(We(t)){let n=e.query.slice(0,-1);return{state:Le(e,n),output:null}}if(Je(t)){let n=e.query.concat(t);return{state:Le(e,n),output:null}}return{state:e,output:null}},_s=(e,t)=>{if(t===T.ESCAPE)return{state:te(e),output:null};if(De(t)){if(!e.builder)return{state:e,output:null};return{state:null,output:e.builder.expression}}if(an(t)||Ve(t)){if(!e.builder)return{state:e,output:null};return{state:nn(e,e.selectedIndex),output:null}}if(cn(t))return{state:on(e),output:null};if($e(t))return{state:D(e,-1),output:null};if(Ge(t))return{state:D(e,1),output:null};if(We(t)){let n=e.query.slice(0,-1);return{state:_e(e,n),output:null}}if(Je(t)){let n=e.query.concat(t);return{state:_e(e,n),output:null}}return{state:e,output:null}},Bs=(e,t)=>{if(t===T.ESCAPE)return{state:je(e),output:null};if(De(t)){if(!e.builder)return{state:e,output:null};return{state:null,output:e.builder.expression}}if(an(t)||Ve(t)){let n=rn(e,e.selectedIndex);return{state:sn(n),output:null}}if(cn(t))return{state:je(e),output:null};if($e(t))return{state:D(e,-1),output:null};if(Ge(t))return{state:D(e,1),output:null};if(We(t)){let n=e.query.slice(0,-1);return{state:Be(e,n),output:null}}if(Je(t)){let n=e.query.concat(t);return{state:Be(e,n),output:null}}return{state:e,output:null}},js={explore:ks,build:_s,"build-arrow-fn":Bs},un=(e,t)=>{let n=t.toString();if(Ps(n)){if(e.mode==="build"||e.mode==="build-arrow-fn")return{state:te(e),output:null};return{state:null,output:null}}let r=js[e.mode];return r(e,n)};var ln=()=>{Qt(),Kt(),V()},Ds=(e)=>{ln();let t=f("Error: ",m.yellow),n=e.message,r=`
|
|
152
|
-
`,o=t.concat(n,r);ne.write(o),ze(1)},Vs=(e,t)=>{return un(e,t)},$s=async(e)=>{let t=e;return new Promise((n)=>{let r=(o)=>{let{state:s,output:i}=Vs(t,o);if(i!==null){Ue.off("data",r),n(i);return}if(s===null){Ue.off("data",r),n(null);return}t=s,ke(t)};Ue.on("data",r)})},pn=async(e)=>{let t=de(e);if(!(t.length>0)){let o=f(`No paths found in data
|
|
153
|
-
`,m.yellow);ne.write(o),ze(1)}let r=Jt(t,e);Ht(),zt(),ke(r);try{let o=await $s(r);if(ln(),o!==null)try{let i=Y(o),a=new H(i).tokenize(),l=new K(a).parse(),d=new X().evaluate(l,e),h=JSON.stringify(d,null,2);ne.write(h),ne.write(`
|
|
154
|
-
`)}catch(i){let c=i instanceof Error?i.message:String(i);ne.write(f("Error: "+c+`
|
|
155
|
-
`,m.yellow))}ze(0)}catch(o){Ds(o)}};async function Gs(e){let t=await It(e.grep,e.find,{recursive:e.recursive,ignoreCase:e.ignoreCase,showLineNumbers:e.showLineNumbers});if(t.length===0){console.log($t("No matches found"));return}for(let n of t){let r=`${Re(n.file)}:${n.line}:${n.column}`,o=e.showLineNumbers?`${r}: ${n.match}`:`${Re(n.file)}: ${n.match}`;console.log(o)}}async function Ws(e,t){if(e.readFile){let s=t[t.indexOf("readFile")+1],i=await pe(s);return e.expression=t[t.indexOf("readFile")+2]||".",i}let n=!process.stdin.isTTY,r=e.list||e.grep;if(!n&&!r)fe(),process.exit(1);if(n)return await Et(e.inputFormat);return null}async function hn(e,t){if(!e.expression){let n=new q(e);console.log(n.format(t));return}try{let n=Y(e.expression),o=new H(n).tokenize(),i=new K(o).parse(),a=new X().evaluate(i,t),u=new q(e);console.log(u.format(a))}catch(n){let r=n instanceof Error?n.message:String(n);console.error("Error:",r),process.exit(1)}}async function Js(e){let t=Ke(e);if(t.help)fe(),process.exit(0);if(t.version){let r=await Bun.file("package.json").json();console.log(`1ls version ${r.version}`),process.exit(0)}if(t.shortcuts)console.log(Wt()),process.exit(0);if(t.shorten)console.log(Gt(t.shorten)),process.exit(0);if(t.expand)console.log(Y(t.expand)),process.exit(0);if(t.list){let r=await Ae(t.list,{recursive:t.recursive,extensions:t.extensions,maxDepth:t.maxDepth});console.log(new q(t).format(r));return}if(t.grep&&t.find){await Gs(t);return}if(t.readFile){let r=e[e.indexOf("readFile")+1],o=await pe(r),s=e[e.indexOf("readFile")+2]||".",i=s===".";if(t.interactive||i){await pn(o);return}t.expression=s,await hn(t,o);return}if(t.interactive)console.error("Error: Interactive mode requires a file path. Use: 1ls readFile <path>"),process.exit(1);let n=await Ws(t,e);await hn(t,n)}if(import.meta.main)Js(process.argv.slice(2)).catch((e)=>{console.error("Error:",e.message),process.exit(1)});export{Js as main};
|
|
154
|
+
`)}return String(t)}formatCsv(t){if(!Array.isArray(t))return this.formatJson(t);if(t.length===0)return"";if(typeof t[0]==="object"&&t[0]!==null&&!Array.isArray(t[0])){let e=Object.keys(t[0]),n=e.join(","),r=t.map((o)=>e.map((s)=>this.escapeCsvValue(o[s])).join(","));return[n,...r].join(`
|
|
155
|
+
`)}return t.map((e)=>this.escapeCsvValue(e)).join(`
|
|
156
|
+
`)}escapeCsvValue(t){if(t===null||t===void 0)return"";let e=String(t);if(e.includes(",")||e.includes('"')||e.includes(`
|
|
157
|
+
`))return`"${e.replace(/"/g,'""')}"`;return e}formatTable(t){if(!Array.isArray(t))return this.formatJson(t);if(t.length===0)return"(empty array)";if(typeof t[0]==="object"&&t[0]!==null&&!Array.isArray(t[0]))return this.formatObjectTable(t);return t.map((e,n)=>`${n}: ${this.formatRaw(e)}`).join(`
|
|
158
|
+
`)}formatObjectTable(t){let e=[...new Set(t.flatMap((i)=>Object.keys(i)))],n={};e.forEach((i)=>{n[i]=Math.max(i.length,...t.map((c)=>String(c[i]??"").length))});let r=e.map((i)=>i.padEnd(n[i])).join(" | "),o=e.map((i)=>"-".repeat(n[i])).join("-+-"),s=t.map((i)=>e.map((c)=>String(i[c]??"").padEnd(n[c])).join(" | "));return[r,o,...s].join(`
|
|
159
|
+
`)}}Et();xt();var ci=()=>Promise.resolve().then(() => (mr(),hr));async function ai(t){let e=await xn(t.grep,t.find,{recursive:t.recursive,ignoreCase:t.ignoreCase,showLineNumbers:t.showLineNumbers});if(e.length===0){console.log(Ln("No matches found"));return}for(let n of e){let r=`${Zt(n.file)}:${n.line}:${n.column}`,o=t.showLineNumbers?`${r}: ${n.match}`:`${Zt(n.file)}: ${n.match}`;console.log(o)}}async function ui(t,e){if(t.readFile){let s=e[e.indexOf("readFile")+1],i=await yt(s);return t.expression=e[e.indexOf("readFile")+2]||".",i}let n=!process.stdin.isTTY,r=t.list||t.grep;if(!n&&!r)Rt(),process.exit(1);if(n)return await pn(t.inputFormat);return null}async function fr(t,e){if(!t.expression){let n=new st(t);console.log(n.format(e));return}try{let n=ot(t.expression),o=new et(n).tokenize(),i=new nt(o).parse(),a=new rt().evaluate(i,e),u=new st(t);console.log(u.format(a))}catch(n){let r=n instanceof Error?n.message:String(n);console.error("Error:",r),process.exit(1)}}async function li(t){let e=Te(t);if(e.help)Rt(),process.exit(0);if(e.version){let r=await Bun.file("package.json").json();console.log(`1ls version ${r.version}`),process.exit(0)}if(e.shortcuts)console.log(Bn()),process.exit(0);if(e.shorten)console.log(_n(e.shorten)),process.exit(0);if(e.expand)console.log(ot(e.expand)),process.exit(0);if(e.detect){if(!!process.stdin.isTTY)console.error("Error: --detect requires input from stdin"),process.exit(1);let o=await Bun.stdin.text(),s=Gt(o);console.log(s),process.exit(0)}if(e.list){let r=await Ut(e.list,{recursive:e.recursive,extensions:e.extensions,maxDepth:e.maxDepth});console.log(new st(e).format(r));return}if(e.grep&&e.find){await ai(e);return}if(e.readFile){let r=t[t.indexOf("readFile")+1],o=await yt(r),s=t[t.indexOf("readFile")+2]||".",i=s===".";if(e.interactive||i){let{runInteractive:a}=await ci();await a(o);return}e.expression=s,await fr(e,o);return}if(e.interactive)console.error("Error: Interactive mode requires a file path. Use: 1ls readFile <path>"),process.exit(1);let n=await ui(e,t);await fr(e,n)}if(import.meta.main)li(process.argv.slice(2)).catch((t)=>{console.error("Error:",t.message),process.exit(1)});export{fr as processExpression,li as main,ui as loadData,ai as handleGrepOperation,ci as getInteractive};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const clearScreen: () => void;
|
|
2
|
-
export declare const moveCursor: (
|
|
2
|
+
export declare const moveCursor: (row: number, col?: number) => void;
|
|
3
|
+
export declare const clearLine: () => void;
|
|
4
|
+
export declare const clearToEnd: () => void;
|
|
3
5
|
export declare const hideCursor: () => void;
|
|
4
6
|
export declare const showCursor: () => void;
|
|
5
7
|
export declare const enableRawMode: () => void;
|
package/dist/navigator/json.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function callMethod(target: unknown, method: string, args: readon
|
|
|
17
17
|
export declare class JsonNavigator {
|
|
18
18
|
evaluate(ast: ASTNode, data: unknown): unknown;
|
|
19
19
|
private evaluatePropertyAccess;
|
|
20
|
+
private evaluateArg;
|
|
20
21
|
private evaluateMethodCall;
|
|
21
22
|
private createFunction;
|
|
22
23
|
private evaluateFunctionBody;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ShortcutMapping } from "../utils/types";
|
|
2
|
+
export declare const VALID_OUTPUT_FORMATS: readonly ["json", "yaml", "csv", "table"];
|
|
3
|
+
export declare const VALID_INPUT_FORMATS: readonly ["json", "yaml", "toml", "csv", "tsv", "lines", "text"];
|
|
4
|
+
export declare const SHORTCUTS: ShortcutMapping[];
|
|
5
|
+
export declare const HELP_TEXT = "1ls - Lightweight JSON CLI with JavaScript syntax\n\nUsage: 1ls [options] [expression]\n\nOptions:\n -h, --help Show this help message\n -v, --version Show version number\n -r, --raw Output raw strings without quotes\n -p, --pretty Pretty print output with indentation\n -c, --compact Output compact JSON (no whitespace)\n -t, --type Show the type of the result\n --format <format> Output format: json, yaml, csv, table\n --input-format, -if Input format: json, yaml, toml, csv, tsv, lines, text\n --detect Show detected input format without processing\n --shortcuts List available expression shortcuts\n\nExpression Syntax:\n . Identity (return entire input)\n .foo Access property 'foo'\n .foo.bar Nested property access\n .[0] Array index access\n .foo[0].bar Combined access\n .map(x => x.name) Transform each element\n .filter(x => x > 5) Filter elements\n .{keys} Get object keys\n .{values} Get object values\n .{length} Get length\n\nExamples:\n echo '{\"name\":\"test\"}' | 1ls .name\n echo '[1,2,3]' | 1ls '.map(x => x * 2)'\n echo '{\"a\":1,\"b\":2}' | 1ls '.{keys}'\n\nShortcuts:\n .mp -> .map .flt -> .filter .rd -> .reduce\n .fnd -> .find .sm -> .some .evr -> .every\n .srt -> .sort .rvs -> .reverse .jn -> .join\n .slc -> .slice .kys -> .{keys} .vls -> .{values}\n .ents -> .{entries} .len -> .{length}\n .lc -> .toLowerCase .uc -> .toUpperCase .trm -> .trim\n .splt -> .split .incl -> .includes\n";
|
|
6
|
+
export declare const SHORTCUTS_TEXT: string;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "1ls",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "1 line script - Lightweight JSON CLI with JavaScript syntax",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./browser": {
|
|
13
|
+
"import": "./dist/browser/index.js",
|
|
14
|
+
"types": "./dist/browser/index.d.ts"
|
|
11
15
|
}
|
|
12
16
|
},
|
|
13
17
|
"bin": {
|
|
@@ -23,9 +27,12 @@
|
|
|
23
27
|
"app"
|
|
24
28
|
],
|
|
25
29
|
"scripts": {
|
|
26
|
-
"dev": "
|
|
27
|
-
"
|
|
30
|
+
"dev": "turbo dev --filter=1ls-app",
|
|
31
|
+
"dev:cli": "bun run ./src/cli/index.ts",
|
|
32
|
+
"build": "rm -rf dist bin && bun build ./src/cli/index.ts --outdir dist --target bun --minify && bun build ./src/browser/index.ts --outdir dist/browser --target browser --minify --format esm && tsc --emitDeclarationOnly --outDir dist && cp -r src/completions dist/",
|
|
28
33
|
"build:binary:all": "rm -rf dist bin && mkdir -p bin && bun build ./src/cli/index.ts --compile --minify --target=bun-darwin-arm64 --outfile bin/1ls-darwin-arm64 && bun build ./src/cli/index.ts --compile --minify --target=bun-darwin-x64 --outfile bin/1ls-darwin-x64 && bun build ./src/cli/index.ts --compile --minify --target=bun-linux-x64 --outfile bin/1ls-linux-x64 && bun build ./src/cli/index.ts --compile --minify --target=bun-linux-arm64 --outfile bin/1ls-linux-arm64",
|
|
34
|
+
"build:qjs": "bash scripts/build-qjs.sh",
|
|
35
|
+
"build:qjs:bundle": "mkdir -p dist/qjs && bun build ./src/browser/index.ts --outfile dist/qjs/core.js --target browser --minify --format esm",
|
|
29
36
|
"clean": "rm -rf dist bin",
|
|
30
37
|
"prepublishOnly": "bun run build && bun run lint && bun test",
|
|
31
38
|
"test": "bun test",
|
|
@@ -56,9 +63,27 @@
|
|
|
56
63
|
"homepage": "https://github.com/yowainwright/1ls",
|
|
57
64
|
"devDependencies": {
|
|
58
65
|
"@types/bun": "latest",
|
|
66
|
+
"react": "^19.1.1",
|
|
67
|
+
"react-dom": "^19.1.1",
|
|
59
68
|
"release-it": "^19.0.5",
|
|
60
69
|
"turbo": "^2.3.3",
|
|
61
70
|
"typescript": "5.9.2"
|
|
62
71
|
},
|
|
63
|
-
"packageManager": "bun@1.1.38"
|
|
72
|
+
"packageManager": "bun@1.1.38",
|
|
73
|
+
"release-it": {
|
|
74
|
+
"git": {
|
|
75
|
+
"commitMessage": "chore(release): ${version}",
|
|
76
|
+
"tagName": "v${version}",
|
|
77
|
+
"requireCleanWorkingDir": true,
|
|
78
|
+
"requireUpstream": true
|
|
79
|
+
},
|
|
80
|
+
"github": {
|
|
81
|
+
"release": true,
|
|
82
|
+
"releaseName": "Release ${version}",
|
|
83
|
+
"releaseNotes": "git log --pretty=format:'* %s (%h)' ${latestTag}...HEAD"
|
|
84
|
+
},
|
|
85
|
+
"npm": {
|
|
86
|
+
"publish": true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
64
89
|
}
|