1ls 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -8
- package/dist/cli/constants.d.ts +3 -0
- package/dist/expression/constants.d.ts +1 -0
- package/dist/expression/index.d.ts +43 -0
- package/dist/expression/utils.d.ts +4 -0
- package/dist/formats/constants.d.ts +51 -0
- package/dist/formats/csv.d.ts +4 -0
- package/dist/formats/env.d.ts +2 -0
- package/dist/formats/index.d.ts +4 -0
- package/dist/formats/ini.d.ts +2 -0
- package/dist/formats/javascript.d.ts +2 -0
- package/dist/formats/json5.d.ts +3 -0
- package/dist/formats/ndjson.d.ts +1 -0
- package/dist/formats/protobuf.d.ts +2 -0
- package/dist/formats/toml.d.ts +2 -0
- package/dist/formats/types.d.ts +41 -0
- package/dist/formats/typescript.d.ts +1 -0
- package/dist/formats/utils.d.ts +11 -0
- package/dist/formats/xml.d.ts +5 -0
- package/dist/formats/yaml.d.ts +3 -0
- package/dist/index.js +34 -28
- package/dist/lexer/constants.d.ts +4 -0
- package/dist/{parser/lexer.d.ts → lexer/index.d.ts} +3 -1
- package/dist/navigator/json.d.ts +20 -3
- package/dist/navigator/types.d.ts +2 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/file.d.ts +24 -3
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/logger.d.ts +1 -10
- package/dist/utils/stream.d.ts +1 -1
- package/dist/utils/types.d.ts +12 -1
- package/package.json +5 -4
- package/dist/parser/parser.d.ts +0 -25
- package/dist/utils/parsers.d.ts +0 -8
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# 1ls - One Line Script
|
|
2
2
|
|
|
3
|
-
A lightweight, fast
|
|
3
|
+
A 0 dependency, lightweight, fast data processor with family JavaScript syntax.
|
|
4
4
|
|
|
5
5
|
## Why 1ls?
|
|
6
6
|
|
|
7
7
|
- **JavaScript Syntax**: Use familiar JavaScript array methods and syntax instead of learning jq's DSL
|
|
8
|
-
- **Multi-format**: Works with JSON, YAML, TOML, CSV, TSV
|
|
9
|
-
- **Fast**: Built
|
|
8
|
+
- **Multi-format**: Works with JSON, JSON5, YAML, TOML, XML, INI, CSV, TSV, ENV, NDJSON, JavaScript, TypeScript, and more
|
|
9
|
+
- **Fast**: Built for speed; no deps, compiled by Bun
|
|
10
10
|
- **Intuitive**: Property access with dot notation, just like JavaScript
|
|
11
11
|
- **Powerful**: Full support for array methods, arrow functions, and object operations
|
|
12
12
|
- **Shortcuts**: Built-in shortcuts for common operations (e.g., `.mp` for `.map`)
|
|
@@ -110,11 +110,34 @@ John,30
|
|
|
110
110
|
Jane,25' | 1ls '.map(x => x.name)'
|
|
111
111
|
# Output: ["John", "Jane"]
|
|
112
112
|
|
|
113
|
+
# ENV file input
|
|
114
|
+
echo 'DATABASE_URL=postgres://localhost/db
|
|
115
|
+
PORT=3000
|
|
116
|
+
DEBUG=true' | 1ls '.PORT'
|
|
117
|
+
# Output: 3000
|
|
118
|
+
|
|
119
|
+
# NDJSON (Newline-Delimited JSON) - great for logs
|
|
120
|
+
echo '{"level":"error","msg":"Failed"}
|
|
121
|
+
{"level":"info","msg":"Started"}
|
|
122
|
+
{"level":"error","msg":"Timeout"}' | 1ls '.filter(x => x.level === "error")'
|
|
123
|
+
# Output: [{"level":"error","msg":"Failed"}, {"level":"error","msg":"Timeout"}]
|
|
124
|
+
|
|
113
125
|
# Specify input format explicitly
|
|
114
126
|
cat data.yaml | 1ls --input-format yaml '.users[0].name'
|
|
115
127
|
cat data.csv | 1ls --input-format csv '.filter(x => x.age > 25)'
|
|
128
|
+
cat app.env | 1ls --input-format env '.DATABASE_URL'
|
|
129
|
+
cat logs.ndjson | 1ls --input-format ndjson '.filter(x => x.level === "error")'
|
|
116
130
|
```
|
|
117
131
|
|
|
132
|
+
**Supported Formats:**
|
|
133
|
+
- JSON, JSON5 (JSON with comments/trailing commas)
|
|
134
|
+
- YAML, TOML, XML, INI
|
|
135
|
+
- CSV, TSV
|
|
136
|
+
- ENV files (.env)
|
|
137
|
+
- NDJSON (Newline-Delimited JSON for logs)
|
|
138
|
+
- JavaScript, TypeScript (with `export default`)
|
|
139
|
+
- Plain text, line-by-line
|
|
140
|
+
|
|
118
141
|
### File Operations
|
|
119
142
|
|
|
120
143
|
```bash
|
|
@@ -316,10 +339,6 @@ MIT © Jeff Wainwright
|
|
|
316
339
|
|
|
317
340
|
## Troubleshooting
|
|
318
341
|
|
|
319
|
-
### Installation Issues
|
|
320
|
-
- Ensure Bun is installed: `curl -fsSL https://bun.sh/install | bash`
|
|
321
|
-
- Check PATH includes Bun location
|
|
322
|
-
|
|
323
342
|
### Expression Errors
|
|
324
343
|
- Wrap expressions in quotes to prevent shell interpretation
|
|
325
344
|
- Use single quotes for expressions containing dollar signs
|
|
@@ -332,4 +351,4 @@ MIT © Jeff Wainwright
|
|
|
332
351
|
|
|
333
352
|
- [GitHub Repository](https://github.com/yowainwright/1ls)
|
|
334
353
|
- [Documentation](https://1ls.dev)
|
|
335
|
-
- [Issue Tracker](https://github.com/yowainwright/1ls/issues)
|
|
354
|
+
- [Issue Tracker](https://github.com/yowainwright/1ls/issues)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BOOLEAN_LITERALS: readonly ["true", "false", "null"];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Token, ASTNode, PropertyAccessNode, IndexAccessNode, SliceAccessNode, MethodCallNode, ObjectOperationNode, ObjectOperationType, ArraySpreadNode, ArrowFunctionNode, RootNode } from "../types";
|
|
2
|
+
export declare function createErrorMessage(token: Token, message: string): string;
|
|
3
|
+
export declare function createPropertyAccessNode(property: string, object?: ASTNode): PropertyAccessNode;
|
|
4
|
+
export declare function createIndexAccessNode(index: number, object?: ASTNode): IndexAccessNode;
|
|
5
|
+
export declare function createSliceAccessNode(start: number | undefined, end: number | undefined, object?: ASTNode): SliceAccessNode;
|
|
6
|
+
export declare function createMethodCallNode(method: string, args: ASTNode[], object?: ASTNode): MethodCallNode;
|
|
7
|
+
export declare function createObjectOperationNode(operation: ObjectOperationType, object?: ASTNode): ObjectOperationNode;
|
|
8
|
+
export declare function createArraySpreadNode(object?: ASTNode): ArraySpreadNode;
|
|
9
|
+
export declare function createArrowFunctionNode(params: string[], body: ASTNode): ArrowFunctionNode;
|
|
10
|
+
export declare function createRootNode(expression?: ASTNode): RootNode;
|
|
11
|
+
export declare const VALID_OBJECT_OPERATIONS: readonly ObjectOperationType[];
|
|
12
|
+
export declare function isValidObjectOperation(value: string): value is ObjectOperationType;
|
|
13
|
+
export declare class ExpressionParser {
|
|
14
|
+
private tokens;
|
|
15
|
+
private position;
|
|
16
|
+
private current;
|
|
17
|
+
constructor(tokens: readonly Token[]);
|
|
18
|
+
parse(): RootNode;
|
|
19
|
+
private parseExpression;
|
|
20
|
+
private parsePrimary;
|
|
21
|
+
private parsePrimaryNode;
|
|
22
|
+
private parseAccessChain;
|
|
23
|
+
private parseBracketAccess;
|
|
24
|
+
private parseNumericIndexOrSlice;
|
|
25
|
+
private parseSliceFromColon;
|
|
26
|
+
private parseArrayAccess;
|
|
27
|
+
private parseObjectOperation;
|
|
28
|
+
private parseIdentifierOrFunction;
|
|
29
|
+
private parseArrowFunction;
|
|
30
|
+
private parseFunctionBody;
|
|
31
|
+
private parseBinaryExpression;
|
|
32
|
+
private parseFunctionTerm;
|
|
33
|
+
private parseIdentifierChain;
|
|
34
|
+
private parseMethodCall;
|
|
35
|
+
private parseMethodArguments;
|
|
36
|
+
private parseMethodArgument;
|
|
37
|
+
private parseFunctionParams;
|
|
38
|
+
private parsePostfix;
|
|
39
|
+
private parsePostfixDot;
|
|
40
|
+
private parseNumber;
|
|
41
|
+
private advance;
|
|
42
|
+
private expect;
|
|
43
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LiteralNode } from "../types";
|
|
2
|
+
export declare const isBooleanLiteral: (value: string) => boolean;
|
|
3
|
+
export declare const createLiteralNode: (value: string | number | boolean | null) => LiteralNode;
|
|
4
|
+
export declare const tryParseLiteralIdentifier: (identifier: string) => LiteralNode | undefined;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare const CSV: {
|
|
2
|
+
readonly NUMBER: RegExp;
|
|
3
|
+
};
|
|
4
|
+
export declare const YAML: {
|
|
5
|
+
readonly INTEGER: RegExp;
|
|
6
|
+
readonly FLOAT: RegExp;
|
|
7
|
+
};
|
|
8
|
+
export declare const TOML: {
|
|
9
|
+
readonly INTEGER: RegExp;
|
|
10
|
+
readonly FLOAT: RegExp;
|
|
11
|
+
};
|
|
12
|
+
export declare const XML: {
|
|
13
|
+
readonly NUMBER: RegExp;
|
|
14
|
+
readonly ATTRIBUTES: RegExp;
|
|
15
|
+
readonly SELF_CLOSING: RegExp;
|
|
16
|
+
readonly OPEN_TAG: RegExp;
|
|
17
|
+
readonly NESTED_TAGS: RegExp;
|
|
18
|
+
readonly COMPLETE_TAGS: RegExp;
|
|
19
|
+
readonly XML_DECLARATION: RegExp;
|
|
20
|
+
};
|
|
21
|
+
export declare const INI: {
|
|
22
|
+
readonly NUMBER: RegExp;
|
|
23
|
+
};
|
|
24
|
+
export declare const JSON5: {
|
|
25
|
+
readonly TRAILING_COMMA: RegExp;
|
|
26
|
+
readonly UNQUOTED_KEY: RegExp;
|
|
27
|
+
};
|
|
28
|
+
export declare const JS: {
|
|
29
|
+
readonly EXPORT: RegExp;
|
|
30
|
+
};
|
|
31
|
+
export declare const TS: {
|
|
32
|
+
readonly TYPE_ANNOTATION: RegExp;
|
|
33
|
+
readonly INTERFACE: RegExp;
|
|
34
|
+
readonly TYPE_ALIAS: RegExp;
|
|
35
|
+
readonly GENERIC: RegExp;
|
|
36
|
+
readonly EXPORT: RegExp;
|
|
37
|
+
};
|
|
38
|
+
export declare const DETECTION: {
|
|
39
|
+
readonly JSON5_FEATURES: RegExp;
|
|
40
|
+
readonly SECTION_HEADER: RegExp;
|
|
41
|
+
readonly TOML_SECTION: RegExp;
|
|
42
|
+
readonly TOML_QUOTED_VALUES: RegExp;
|
|
43
|
+
readonly TOML_SYNTAX: RegExp;
|
|
44
|
+
readonly INI_SYNTAX: RegExp;
|
|
45
|
+
readonly JS_EXPORT: RegExp;
|
|
46
|
+
readonly TS_TYPE_ANNOTATION: RegExp;
|
|
47
|
+
readonly TS_INTERFACE: RegExp;
|
|
48
|
+
readonly TS_TYPE_ALIAS: RegExp;
|
|
49
|
+
readonly ENV_FEATURES: RegExp;
|
|
50
|
+
readonly NDJSON_FEATURES: RegExp;
|
|
51
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function parseCSVLine(line: string, delimiter: string): string[];
|
|
2
|
+
export declare function parseCSVValue(value: string): unknown;
|
|
3
|
+
export declare function parseCSV(input: string, delimiter?: string): unknown[];
|
|
4
|
+
export declare function parseTSV(input: string): unknown[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseNDJSON(input: string): unknown[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface CSVOptions {
|
|
2
|
+
delimiter: string;
|
|
3
|
+
}
|
|
4
|
+
export interface TOMLTable {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface YAMLParseContext {
|
|
8
|
+
stack: unknown[];
|
|
9
|
+
indentStack: number[];
|
|
10
|
+
currentList: unknown[] | null;
|
|
11
|
+
listIndent: number;
|
|
12
|
+
}
|
|
13
|
+
export interface XMLAttributes {
|
|
14
|
+
_attributes?: Record<string, unknown>;
|
|
15
|
+
_text?: unknown;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface ParseState {
|
|
19
|
+
result: string[];
|
|
20
|
+
inString: boolean;
|
|
21
|
+
delimiter: string;
|
|
22
|
+
skip: number;
|
|
23
|
+
}
|
|
24
|
+
export interface XMLParseState {
|
|
25
|
+
buffer: string[];
|
|
26
|
+
depth: number;
|
|
27
|
+
skip: number;
|
|
28
|
+
}
|
|
29
|
+
export interface XMLElementState {
|
|
30
|
+
elements: string[];
|
|
31
|
+
buffer: string[];
|
|
32
|
+
depth: number;
|
|
33
|
+
skip: number;
|
|
34
|
+
}
|
|
35
|
+
export interface INIParseState {
|
|
36
|
+
result: Record<string, unknown>;
|
|
37
|
+
currentSection: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ENVParseState {
|
|
40
|
+
result: Record<string, unknown>;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseTypeScript(input: string): unknown;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const TRUTHY_VALUES: readonly ["true", "yes", "on"];
|
|
2
|
+
export declare const FALSY_VALUES: readonly ["false", "no", "off"];
|
|
3
|
+
export declare const NULL_VALUES: readonly ["null", "~", ""];
|
|
4
|
+
export declare const isTruthyValue: (value: string) => boolean;
|
|
5
|
+
export declare const isFalsyValue: (value: string) => boolean;
|
|
6
|
+
export declare const isNullValue: (value: string) => boolean;
|
|
7
|
+
export declare const parseBooleanValue: (value: string) => boolean | undefined;
|
|
8
|
+
export declare const parseNullValue: (value: string) => null | undefined;
|
|
9
|
+
export declare const tryParseNumber: (value: string) => number | undefined;
|
|
10
|
+
export declare const countQuotes: (line: string, endPos: number) => number;
|
|
11
|
+
export declare const isQuoteBalanced: (quoteCount: number) => boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function parseXMLValue(value: string): unknown;
|
|
2
|
+
export declare function parseXMLAttributes(attrString: string): Record<string, unknown>;
|
|
3
|
+
export declare function parseXMLElement(xml: string): unknown;
|
|
4
|
+
export declare function parseXMLChildren(content: string): Record<string, unknown>;
|
|
5
|
+
export declare function parseXML(input: string): unknown;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
3
|
+
var ft=Object.defineProperty;var N=(e,t)=>{for(var n in t)ft(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(r)=>t[n]=()=>r})};var A=(e,t)=>()=>(e&&(t=e(e=0)),t);var dt,gt,xt,Nt,Pe,Et,At,Ot,St,bt,yt,Tt,wt,vt,It,Rt,Ct,Ft,Lt,Y,q,S,Me,z,kt,_t,Pt,Mt,Dt,jt,h;var v=A(()=>{dt=/^-?\d+$/,gt=/^[+-]?\d+$/,xt=/^-?\d+\.\d+$/,Nt=/^[+-]?\d+\.\d+$/,Pe=/^-?\d+(\.\d+)?$/,Et=/(\w+)=["']([^"']+)["']/g,At=/^<(\w+)([^>]*?)\/>/,Ot=/^<(\w+)([^>]*)>([\s\S]*)<\/\1>$/,St=/<\w+/,bt=/<\/\w+>$/,yt=/^<\?xml[^>]+\?>\s*/,Tt=/,(\s*[}\]])/g,wt=/(['"])?([a-zA-Z_$][a-zA-Z0-9_$]*)\1?\s*:/g,vt=/\/\/|\/\*|,\s*[}\]]/,It=/^\[[\w.\s]+\]$/m,Rt=/^\[[\w.]+\]$/m,Ct=/^\w+\s*=\s*"[^"]*"$/m,Ft=/=\s*["[{]/m,Lt=/^\w+\s*=\s*.+$/m,Y={INTEGER:dt,FLOAT:xt},q={INTEGER:gt,FLOAT:Nt},S={NUMBER:Pe,ATTRIBUTES:Et,SELF_CLOSING:At,OPEN_TAG:Ot,NESTED_TAGS:St,COMPLETE_TAGS:bt,XML_DECLARATION:yt},Me={NUMBER:Pe},z={TRAILING_COMMA:Tt,UNQUOTED_KEY:wt},kt=/^\s*export\s+(const|let|var|function|class|default|type|interface|enum)/m,_t=/:\s*(string|number|boolean|any|unknown|void|never|object|Array|Promise)/,Pt=/^\s*interface\s+\w+/m,Mt=/^\s*type\s+\w+\s*=/m,Dt=/^[A-Z_][A-Z0-9_]*\s*=/m,jt=/^\{.*\}\s*$/m,h={JSON5_FEATURES:vt,SECTION_HEADER:It,TOML_SECTION:Rt,TOML_QUOTED_VALUES:Ct,TOML_SYNTAX:Ft,INI_SYNTAX:Lt,JS_EXPORT:kt,TS_TYPE_ANNOTATION:_t,TS_INTERFACE:Pt,TS_TYPE_ALIAS:Mt,ENV_FEATURES:Dt,NDJSON_FEATURES:jt}});var Z={};N(Z,{stripJSON5Comments:()=>De,parseJSON5:()=>Ut,normalizeJSON5:()=>je});function $t(e){return e==='"'||e==="'"}function Bt(e,t,n){let i=e.slice(t).findIndex((o)=>o===n);return i===-1?e.length-t:i}function Vt(e,t){let n=2,r=e.length-t;while(n<r){let i=e[t+n],s=e[t+n+1];if(i==="*"&&s==="/")return n+1;n++}return n}function Gt(e,t,n){if(e.result.push(t),t==="\\"&&n)return e.result.push(n),{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:1};if(t===e.delimiter)return{result:e.result,inString:!1,delimiter:"",skip:0};return e}function Wt(e,t,n,r,i){if($t(t))return e.result.push(t),{result:e.result,inString:!0,delimiter:t,skip:0};if(t==="/"&&n==="/"){let c=Bt(r,i,`
|
|
4
|
+
`);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:c}}if(t==="/"&&n==="*"){let c=Vt(r,i);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:c}}return e.result.push(t),e}function De(e){let t=e.split("");return t.reduce((n,r,i)=>{if(n.skip>0)return{result:n.result,inString:n.inString,delimiter:n.delimiter,skip:n.skip-1};let o=t[i+1];return n.inString?Gt(n,r,o):Wt(n,r,o,t,i)},{result:[],inString:!1,delimiter:"",skip:0}).result.join("")}function je(e){let t=De(e);return t=t.replace(z.TRAILING_COMMA,"$1"),t=t.replace(z.UNQUOTED_KEY,'"$2":'),t=t.replace(/'/g,'"'),t}function Ut(e){let t=je(e);return JSON.parse(t)}var ee=A(()=>{v()});var Jt,Qt,Ht,Xt=(e)=>Jt.includes(e),Kt=(e)=>Qt.includes(e),Yt=(e)=>Ht.includes(e),F=(e)=>{if(Xt(e))return!0;if(Kt(e))return!1;return},L=(e)=>{if(Yt(e))return null;return},V=(e)=>{if(e==="")return;let t=Number(e);return isNaN(t)?void 0:t};var G=A(()=>{Jt=["true","yes","on"],Qt=["false","no","off"],Ht=["null","~",""]});var te={};N(te,{parseYAMLValue:()=>k,parseYAML:()=>qt,findPreviousKey:()=>$e});function k(e){let t=e.startsWith('"')&&e.endsWith('"'),n=e.startsWith("'")&&e.endsWith("'");if(t||n)return e.slice(1,-1);let i=F(e);if(i!==void 0)return i;let s=L(e);if(s!==void 0)return s;if(Y.INTEGER.test(e))return parseInt(e,10);if(Y.FLOAT.test(e))return parseFloat(e);if(e.startsWith("[")&&e.endsWith("]"))return e.slice(1,-1).split(",").map((p)=>k(p.trim()));if(e.startsWith("{")&&e.endsWith("}")){let p={};return e.slice(1,-1).split(",").forEach((m)=>{let[f,E]=m.split(":").map((w)=>w.trim());if(f&&E)p[f]=k(E)}),p}return e}function $e(e,t){return Array.from({length:t},(r,i)=>t-1-i).reduce((r,i)=>{if(r!==null)return r;let s=e[i],o=s.indexOf("#");if(o>=0){let p=s.substring(0,o);if((p.match(/["']/g)||[]).length%2===0)s=p}let c=s.trim();if(c&&!c.startsWith("-")&&c.includes(":")){let p=c.indexOf(":"),l=c.substring(0,p).trim();if(!c.substring(p+1).trim())return l}return null},null)}function qt(e){let t=e.trim().split(`
|
|
5
|
+
`),n={},r=[n],i=[0],s=null,o=-1;return t.forEach((u,c)=>{let a=u,p=a.indexOf("#");if(p>=0){let g=a.substring(0,p);if((g.match(/["']/g)||[]).length%2===0)a=g}if(!a.trim())return;if(a.trim()==="---"||a.trim()==="...")return;let m=a.length-a.trimStart().length,f=a.trim();if(f.startsWith("- ")){let g=f.substring(2).trim();if(s!==null&&m===o){s.push(k(g));return}s=[k(g)],o=m;while(i.length>1&&i[i.length-1]>=m)r.pop(),i.pop();let x=r[r.length-1];if(typeof x==="object"&&!Array.isArray(x)){let P=$e(t,c);if(P)x[P]=s}return}if(!f.startsWith("- "))s=null,o=-1;let T=f.indexOf(":");if(T>0){let g=f.substring(0,T).trim(),_=f.substring(T+1).trim();while(i.length>1&&i[i.length-1]>=m)r.pop(),i.pop();let x=r[r.length-1];if(!_){let X=c+1;if(X<t.length){if(t[X].trim().startsWith("- "))return}let P={};x[g]=P,r.push(P),i.push(m)}else x[g]=k(_)}}),n}var ne=A(()=>{v();G()});var re={};N(re,{parseTOMLValue:()=>W,parseTOML:()=>zt});function W(e){if(e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1).replace(/\\"/g,'"');if(e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;if(q.INTEGER.test(e))return parseInt(e,10);if(q.FLOAT.test(e))return parseFloat(e);if(e.startsWith("[")&&e.endsWith("]"))return e.slice(1,-1).split(",").map((c)=>W(c.trim()));if(e.startsWith("{")&&e.endsWith("}")){let u={};return e.slice(1,-1).split(",").forEach((a)=>{let[p,l]=a.split("=").map((m)=>m.trim());if(p&&l)u[p]=W(l)}),u}return e}function zt(e){let t=e.trim().split(`
|
|
6
|
+
`),n={},r=n,i=[];return t.forEach((s)=>{let o=s,u=o.indexOf("#");if(u>=0){let m=o.substring(0,u);if((m.match(/["']/g)||[]).length%2===0)o=m}let c=o.trim();if(!c)return;if(c.startsWith("[")&&c.endsWith("]")){let m=c.slice(1,-1).split(".");r=n,i=[],m.forEach((f)=>{if(!r[f])r[f]={};r=r[f],i.push(f)});return}let p=c.indexOf("=");if(p>0){let m=c.substring(0,p).trim(),f=c.substring(p+1).trim();r[m]=W(f)}}),n}var se=A(()=>{v()});var oe={};N(oe,{parseXMLValue:()=>M,parseXMLElement:()=>ie,parseXMLChildren:()=>Be,parseXMLAttributes:()=>U,parseXML:()=>tn});function M(e){let t=e.trim();if(t==="true")return!0;if(t==="false")return!1;if(S.NUMBER.test(t))return parseFloat(t);return t}function U(e){return Array.from(e.matchAll(S.ATTRIBUTES)).reduce((n,r)=>{let[,i,s]=r;return n[i]=M(s),n},{})}function ie(e){let t=e.trim(),n=t.match(S.SELF_CLOSING);if(n){let[,l,m]=n;if(m.trim().length>0)return{[l]:{_attributes:U(m)}};return{[l]:null}}let r=t.match(S.OPEN_TAG);if(!r)return M(t);let[,i,s,o]=r,u=o.trim();if(!S.NESTED_TAGS.test(u)){if(s.trim().length>0)return{[i]:{_attributes:U(s),_text:M(u)}};return{[i]:M(u)}}let a=Be(u);if(s.trim().length>0)return{[i]:{_attributes:U(s),...a}};return{[i]:a}}function Zt(e){let t=e.split(""),n=t.reduce((s,o,u)=>{if(s.skip>0)return{elements:s.elements,buffer:s.buffer,depth:s.depth,skip:s.skip-1};if(o==="<"){let E=t[u+1]==="/",w=e.slice(u).match(/^<[^>]+\/>/);if(E)return s.buffer.push(o),{elements:s.elements,buffer:s.buffer,depth:s.depth-1,skip:0};if(w){let g=w[0];if(g.split("").forEach((x)=>s.buffer.push(x)),s.depth===0){let x=s.buffer.join("").trim();s.elements.push(x),s.buffer.length=0}return{elements:s.elements,buffer:s.buffer,depth:s.depth,skip:g.length-1}}return s.buffer.push(o),{elements:s.elements,buffer:s.buffer,depth:s.depth+1,skip:0}}s.buffer.push(o);let p=s.depth===0,l=s.buffer.join("").trim(),m=l.length>0,f=!o.match(/\s/);if(p&&m&&f){if(l.match(S.COMPLETE_TAGS))s.elements.push(l),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 en(e,t,n){let r=e[t];if(r===void 0){e[t]=n;return}if(Array.isArray(r)){r.push(n);return}e[t]=[r,n]}function Be(e){return Zt(e).reduce((n,r)=>{let i=ie(r);if(typeof i==="object"&&i!==null)Object.entries(i).forEach(([o,u])=>{en(n,o,u)});return n},{})}function tn(e){let t=e.trim(),n=t.match(S.XML_DECLARATION),r=n?t.slice(n[0].length):t;return ie(r)}var ce=A(()=>{v()});var ae={};N(ae,{parseINIValue:()=>ue,parseINI:()=>sn});function ue(e){let t=e.trim();if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t==="true")return!0;if(t==="false")return!1;if(Me.NUMBER.test(t))return parseFloat(t);return t}function nn(e){let t=e.indexOf(";"),n=e.indexOf("#");if(!(t>=0||n>=0))return e;let i=t>=0&&n>=0?Math.min(t,n):Math.max(t,n);return e.substring(0,i)}function rn(e,t){let r=nn(t).trim();if(!r)return e;if(r.startsWith("[")&&r.endsWith("]")){let c=r.slice(1,-1).trim();if(!e.result[c])e.result[c]={};return{result:e.result,currentSection:c}}let o=r.indexOf("=");if(o>0){let c=r.substring(0,o).trim(),a=r.substring(o+1).trim();if(e.currentSection.length>0){let l=e.result[e.currentSection];l[c]=ue(a)}else e.result[c]=ue(a)}return e}function sn(e){return e.trim().split(`
|
|
7
|
+
`).reduce((r,i)=>rn(r,i),{result:{},currentSection:""}).result}var pe=A(()=>{v()});var D={};N(D,{parseTSV:()=>on,parseCSVValue:()=>Ve,parseCSVLine:()=>le,parseCSV:()=>Ge});function le(e,t){let n=[],r="",i=!1,s=e.split("");return s.forEach((o,u)=>{let c=s[u+1];if(o==='"'){if(i&&c==='"'){r+='"',s.splice(u+1,1);return}i=!i;return}if(o===t&&!i){n.push(r),r="";return}r+=o}),n.push(r),n.map((o)=>o.trim())}function Ve(e){let t=e.trim();if(t.startsWith('"')&&t.endsWith('"'))return t.slice(1,-1).replace(/""/g,'"');let r=V(t);if(r!==void 0)return r;let i=t.toLowerCase(),s=F(i);if(s!==void 0)return s;let o=L(i);if(o!==void 0)return o;return t}function Ge(e,t=","){let n=e.trim().split(`
|
|
8
|
+
`);if(n.length===0)return[];let r=le(n[0],t);if(n.length===1)return[];return n.slice(1).reduce((i,s)=>{let o=le(s,t);if(o.length===0)return i;let u=Object.fromEntries(r.map((c,a)=>[c,Ve(o[a]||"")]));return[...i,u]},[])}function on(e){return Ge(e,"\t")}var j=A(()=>{G()});var me={};N(me,{parseProtobufJSON:()=>un,parseProtobuf:()=>cn});function cn(e){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 un(e){return JSON.parse(e)}var fe={};N(fe,{stripJSComments:()=>J,parseJavaScript:()=>hn});function an(e){return e==='"'||e==="'"||e==="`"}function pn(e,t,n){let i=e.slice(t).findIndex((o)=>o===n);return i===-1?e.length-t:i}function ln(e,t){let n=2,r=e.length-t;while(n<r){let i=e[t+n],s=e[t+n+1];if(i==="*"&&s==="/")return n+1;n++}return n}function mn(e,t,n){if(e.result.push(t),t==="\\"&&n)return e.result.push(n),{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:1};if(t===e.delimiter)return{result:e.result,inString:!1,delimiter:"",skip:0};return e}function fn(e,t,n,r,i){if(an(t))return e.result.push(t),{result:e.result,inString:!0,delimiter:t,skip:0};if(t==="/"&&n==="/"){let c=pn(r,i,`
|
|
9
|
+
`);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:c}}if(t==="/"&&n==="*"){let c=ln(r,i);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:c}}return e.result.push(t),e}function J(e){let t=e.split("");return t.reduce((n,r,i)=>{if(n.skip>0)return{result:n.result,inString:n.inString,delimiter:n.delimiter,skip:n.skip-1};let o=t[i+1];return n.inString?mn(n,r,o):fn(n,r,o,t,i)},{result:[],inString:!1,delimiter:"",skip:0}).result.join("")}function hn(input){let withoutComments=J(input),exportMatch=withoutComments.match(/export\s+default\s+([\s\S]+)/),code=exportMatch?exportMatch[1]:withoutComments,trimmed=code.trim().replace(/;$/,"");return eval(`(${trimmed})`)}var he={};N(he,{parseTypeScript:()=>gn});function dn(){if(Q!==null)return Q;return Q=new Bun.Transpiler({loader:"ts"}),Q}function gn(input){let withoutComments=J(input),transpiler=dn(),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}
|
|
10
|
+
(${exportedValue})`;return eval(fullCode)}var Q=null;var de=()=>{};var ge={};N(ge,{parseENVValue:()=>We,parseENV:()=>En});function We(e){let t=e.trim(),n=t.startsWith('"')&&t.endsWith('"'),r=t.startsWith("'")&&t.endsWith("'");if(n||r)return t.slice(1,-1);let s=F(t);if(s!==void 0)return s;let o=L(t);if(o!==void 0)return o;let u=V(t);if(u!==void 0)return u;return t}function xn(e){let t=e.indexOf("#");if(!(t>=0))return e;let r=e.substring(0,t);if(r.match(/["'].*["']/)!==null){if((r.match(/["']/g)||[]).length%2!==0)return e}return r}function Nn(e,t){let r=xn(t).trim();if(!r)return e;let o=r.startsWith("export ")?r.substring(7).trim():r,u=o.indexOf("=");if(u>0){let a=o.substring(0,u).trim(),p=o.substring(u+1).trim();e.result[a]=We(p)}return e}function En(e){return e.trim().split(`
|
|
11
|
+
`).reduce((r,i)=>Nn(r,i),{result:{}}).result}var xe=A(()=>{G()});var Ne={};N(Ne,{parseNDJSON:()=>An});function An(e){return e.trim().split(`
|
|
12
|
+
`).map((n)=>n.trim()).filter((n)=>n.length>0).map((n)=>{try{return JSON.parse(n)}catch{return n}})}var Le=["json","yaml","csv","table"],ke=["json","yaml","toml","csv","tsv","lines","text"];var ht={format:"json",pretty:!1,raw:!1,compact:!1,type:!1,recursive:!1,ignoreCase:!1,showLineNumbers:!1,inputFormat:void 0};function _e(e){let t={...ht},n=0;while(n<e.length){let r=e[n];switch(r){case"--help":case"-h":t.help=!0;break;case"--version":case"-v":t.version=!0;break;case"--raw":case"-r":t.raw=!0;break;case"--pretty":case"-p":t.pretty=!0;break;case"--compact":case"-c":t.compact=!0;break;case"--type":case"-t":t.type=!0;break;case"--format":if(n++,n<e.length){let s=e[n],o=Le.includes(s);if(s&&o)t.format=s}break;case"--input-format":case"-if":if(n++,n<e.length){let s=e[n];if(ke.includes(s))t.inputFormat=s}break;case"readFile":t.readFile=!0,n+=2;break;case"--find":case"-f":if(n++,n<e.length)t.find=e[n];break;case"--grep":case"-g":if(n++,n<e.length)t.grep=e[n];break;case"--list":case"-l":if(n++,n<e.length)t.list=e[n];break;case"--recursive":case"-R":t.recursive=!0;break;case"--ignore-case":case"-i":t.ignoreCase=!0;break;case"--line-numbers":case"-n":t.showLineNumbers=!0;break;case"--ext":if(n++,n<e.length){let s=e[n].split(",");t.extensions=s.map((o)=>o.startsWith(".")?o:`.${o}`)}break;case"--max-depth":if(n++,n<e.length)t.maxDepth=parseInt(e[n],10);break;case"--shorten":if(n++,n<e.length)t.shorten=e[n];break;case"--expand":if(n++,n<e.length)t.expand=e[n];break;case"--shortcuts":t.shortcuts=!0;break;default:if(r.startsWith(".")||r.startsWith("["))t.expression=r;break}n++}return t}function K(){console.log(`
|
|
4
13
|
1ls - 1 line script for JSON manipulation and file operations
|
|
5
14
|
|
|
6
15
|
Usage:
|
|
@@ -73,33 +82,30 @@ Examples:
|
|
|
73
82
|
1ls --shorten ".map(x => x * 2)" # Convert to shorthand
|
|
74
83
|
1ls --expand ".mp(x => x * 2)" # Convert to full form
|
|
75
84
|
1ls --shortcuts # Show all shortcuts
|
|
76
|
-
`)}
|
|
77
|
-
`)
|
|
78
|
-
`).
|
|
79
|
-
`)
|
|
80
|
-
`),i={},n=[i],c=[0],o=null,t=-1;for(let e=0;e<s.length;e++){let f=s[e],p=f.indexOf("#");if(p>=0){let F=f.substring(0,p);if((F.match(/["']/g)||[]).length%2===0)f=F}if(!f.trim())continue;if(f.trim()==="---"||f.trim()==="...")continue;let O=f.length-f.trimStart().length,h=f.trim();if(h.startsWith("- ")){let F=h.substring(2).trim();if(o&&O===t)o.push(w(F));else{o=[w(F)],t=O;while(c.length>1&&c[c.length-1]>=O)n.pop(),c.pop();let l=n[n.length-1];if(typeof l==="object"&&!Array.isArray(l)){let N=V(s,e);if(N)l[N]=o}}continue}if(!h.startsWith("- "))o=null,t=-1;let E=h.indexOf(":");if(E>0){let F=h.substring(0,E).trim(),l=h.substring(E+1).trim();while(c.length>1&&c[c.length-1]>=O)n.pop(),c.pop();let N=n[n.length-1];if(!l){let u=e+1;if(u<s.length){if(s[u].trim().startsWith("- "))continue}let A={};N[F]=A,n.push(A),c.push(O)}else N[F]=w(l)}}return i}function V(r,s){for(let i=s-1;i>=0;i--){let n=r[i],c=n.indexOf("#");if(c>=0){let t=n.substring(0,c);if((t.match(/["']/g)||[]).length%2===0)n=t}let o=n.trim();if(o&&!o.startsWith("-")&&o.includes(":")){let t=o.indexOf(":"),e=o.substring(0,t).trim();if(!o.substring(t+1).trim())return e}}return null}function w(r){if(r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'"))return r.slice(1,-1);if(r==="true"||r==="yes"||r==="on")return!0;if(r==="false"||r==="no"||r==="off")return!1;if(r==="null"||r==="~"||r==="")return null;if(/^-?\d+$/.test(r))return parseInt(r,10);if(/^-?\d+\.\d+$/.test(r))return parseFloat(r);if(r.startsWith("[")&&r.endsWith("]"))return r.slice(1,-1).split(",").map((s)=>w(s.trim()));if(r.startsWith("{")&&r.endsWith("}")){let s={},i=r.slice(1,-1).split(",");for(let n of i){let[c,o]=n.split(":").map((t)=>t.trim());if(c&&o)s[c]=w(o)}return s}return r}function k(r){let s=r.trim().split(`
|
|
81
|
-
`)
|
|
82
|
-
|
|
83
|
-
`||r==="\r"}isDigit(r){return r>="0"&&r<="9"}isIdentifierStart(r){return r>="a"&&r<="z"||r>="A"&&r<="Z"||r==="_"||r==="$"}isIdentifierChar(r){return this.isIdentifierStart(r)||this.isDigit(r)}isOperator(r){return"+-*/%<>!&|=".includes(r)}}class I{tokens;position=0;current;constructor(r){this.tokens=r,this.current=this.tokens[0]}parse(){if(this.current.type==="EOF")return{type:"Root"};return{type:"Root",expression:this.parseExpression()}}parseExpression(){return this.parsePrimary()}parsePrimary(){let r;if(this.current.type==="DOT")this.advance(),r=this.parseAccessChain();else if(this.current.type==="LEFT_BRACKET")r=this.parseArrayAccess();else if(this.current.type==="IDENTIFIER")r=this.parseIdentifierOrFunction();else if(this.current.type==="STRING"){let s=this.current.value;this.advance(),r={type:"Literal",value:s}}else if(this.current.type==="NUMBER"){let s=Number(this.current.value);this.advance(),r={type:"Literal",value:s}}else if(this.current.type==="LEFT_PAREN"){let s=this.parseFunctionParams();return this.parseArrowFunction(s)}if(!r)throw new Error(`Unexpected token: ${this.current.type} at position ${this.current.position}`);return this.parsePostfix(r)}parseAccessChain(r){if(this.current.type==="IDENTIFIER"){let s=this.current.value;this.advance();let i={type:"PropertyAccess",property:s,object:r};return this.parsePostfix(i)}if(this.current.type==="LEFT_BRACKET")return this.parseBracketAccess(r);if(this.current.type==="LEFT_BRACE")return this.parseObjectOperation(r);throw new Error(`Expected property name after dot at position ${this.current.position}`)}parseBracketAccess(r){if(this.advance(),this.current.type==="RIGHT_BRACKET"){this.advance();let i={type:"ArraySpread",object:r};return this.parsePostfix(i)}if(this.current.type==="STRING"){let i=this.current.value;this.advance(),this.expect("RIGHT_BRACKET");let n={type:"PropertyAccess",property:i,object:r};return this.parsePostfix(n)}if(this.current.type==="NUMBER"||this.current.type==="OPERATOR"&&this.current.value==="-"){let i=this.parseNumber();if(this.advance(),this.current.type==="COLON"){this.advance();let c,o=this.current.type;if(o==="NUMBER"||o==="OPERATOR"&&this.current.value==="-")c=this.parseNumber(),this.advance();this.expect("RIGHT_BRACKET");let t={type:"SliceAccess",start:i,end:c,object:r};return this.parsePostfix(t)}this.expect("RIGHT_BRACKET");let n={type:"IndexAccess",index:i,object:r};return this.parsePostfix(n)}if(this.current.type==="COLON"){this.advance();let i,n=this.current.type;if(n==="NUMBER"||n==="OPERATOR"&&this.current.value==="-")i=this.parseNumber(),this.advance();this.expect("RIGHT_BRACKET");let c={type:"SliceAccess",end:i,object:r};return this.parsePostfix(c)}throw new Error(`Unexpected token in bracket access: ${this.current.type} at position ${this.current.position}`)}parseArrayAccess(){return this.parseBracketAccess()}parseObjectOperation(r){if(this.advance(),this.current.type!=="IDENTIFIER")throw new Error(`Expected operation name after { at position ${this.current.position}`);let s=this.current.value;if(!["keys","values","entries","length"].includes(s))throw new Error(`Invalid object operation: ${s} at position ${this.current.position}`);this.advance(),this.expect("RIGHT_BRACE");let c={type:"ObjectOperation",operation:s,object:r};return this.parsePostfix(c)}parseIdentifierOrFunction(){let r=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([r]);let s={type:"PropertyAccess",property:r};return this.parsePostfix(s)}parseArrowFunction(r){this.expect("ARROW");let s=this.parseFunctionBody();return{type:"ArrowFunction",params:r,body:s}}parseFunctionBody(){if(this.current.type==="LEFT_BRACE"){this.advance();let s=this.parseBinaryExpression();return this.expect("RIGHT_BRACE"),s}return this.parseBinaryExpression()}parseBinaryExpression(){let r=this.parseFunctionTerm();while(this.current.type==="OPERATOR"){let s=this.current.value;this.advance();let i=this.parseFunctionTerm();r={type:"MethodCall",method:`__operator_${s}__`,args:[i],object:r}}return r}parseFunctionTerm(){if(this.current.type==="IDENTIFIER"){let r=this.current.value;this.advance();let s={type:"PropertyAccess",property:r};while(this.current.type==="DOT")if(this.advance(),this.current.type==="IDENTIFIER"){let n=this.current.value;this.advance(),s={type:"PropertyAccess",property:n,object:s}}else break;return s}if(this.current.type==="NUMBER"){let r=Number(this.current.value);return this.advance(),{type:"Literal",value:r}}if(this.current.type==="STRING"){let r=this.current.value;return this.advance(),{type:"Literal",value:r}}if(this.current.type==="LEFT_PAREN"){this.advance();let r=this.parseBinaryExpression();return this.expect("RIGHT_PAREN"),r}throw new Error(`Unexpected token in function body: ${this.current.type} at position ${this.current.position}`)}parseMethodCall(r,s){this.expect("LEFT_PAREN");let i=[];while(this.current.type!=="RIGHT_PAREN"&&this.current.type!=="EOF"){if(this.current.type==="LEFT_PAREN"){let n=this.parseFunctionParams();i.push(this.parseArrowFunction(n))}else if(this.current.type==="IDENTIFIER"){let n=this.current.value;if(this.advance(),this.current.type==="ARROW")i.push(this.parseArrowFunction([n]));else i.push({type:"PropertyAccess",property:n})}else if(this.current.type==="NUMBER"){let n=Number(this.current.value);this.advance(),i.push({type:"Literal",value:n})}else if(this.current.type==="STRING"){let n=this.current.value;this.advance(),i.push({type:"Literal",value:n})}else i.push(this.parseExpression());if(this.current.type==="COMMA")this.advance()}return this.expect("RIGHT_PAREN"),{type:"MethodCall",method:s,args:i,object:r}}parseFunctionParams(){this.expect("LEFT_PAREN");let r=[];while(this.current.type!=="RIGHT_PAREN"&&this.current.type!=="EOF"){if(this.current.type==="IDENTIFIER")r.push(this.current.value),this.advance();if(this.current.type==="COMMA")this.advance()}return this.expect("RIGHT_PAREN"),r}parsePostfix(r){while(!0)if(this.current.type==="DOT"){this.advance();let s=this.current.type;if(s==="IDENTIFIER"){let i=this.current.value;if(this.advance(),this.current.type==="LEFT_PAREN")r=this.parseMethodCall(r,i);else r={type:"PropertyAccess",property:i,object:r}}else if(s==="LEFT_BRACKET")r=this.parseBracketAccess(r);else if(s==="LEFT_BRACE")r=this.parseObjectOperation(r);else throw new Error(`Expected property name after dot at position ${this.current.position}`)}else if(this.current.type==="LEFT_BRACKET")r=this.parseBracketAccess(r);else if(this.current.type==="LEFT_PAREN")if(r.type==="PropertyAccess"&&!r.object){let s=r.property;r=this.parseMethodCall({type:"Root"},s)}else break;else break;return r}parseNumber(){let r=this.current.value==="-";if(r)this.advance();if(this.current.type!=="NUMBER")throw new Error(`Expected number after minus sign at position ${this.current.position}`);let s=Number(this.current.value);return r?-s:s}advance(){if(this.position++,this.position<this.tokens.length)this.current=this.tokens[this.position]}expect(r){if(this.current.type!==r)throw new Error(`Expected ${r} but got ${this.current.type} at position ${this.current.position}`);this.advance()}}class C{evaluate(r,s){switch(r.type){case"Root":return r.expression?this.evaluate(r.expression,s):s;case"PropertyAccess":let i=r.object?this.evaluate(r.object,s):s;if(!i)return;return i[r.property];case"IndexAccess":let n=r.object?this.evaluate(r.object,s):s;if(!Array.isArray(n))return;let c=r.index<0?n.length+r.index:r.index;return n[c];case"SliceAccess":let o=r.object?this.evaluate(r.object,s):s;if(!Array.isArray(o))return;let t=o.length,e=r.start!==void 0?r.start<0?t+r.start:r.start:0,f=r.end!==void 0?r.end<0?t+r.end:r.end:t;return o.slice(e,f);case"ArraySpread":let p=r.object?this.evaluate(r.object,s):s;if(!Array.isArray(p))return;return p;case"MethodCall":let O=r.object?this.evaluate(r.object,s):s;return this.executeMethod(O,r.method,r.args,s);case"ObjectOperation":let h=r.object?this.evaluate(r.object,s):s;if(!(h&&typeof h==="object"))return;switch(r.operation){case"keys":return Object.keys(h);case"values":return Object.values(h);case"entries":return Object.entries(h);case"length":return Array.isArray(h)?h.length:Object.keys(h).length;default:return}case"Literal":return r.value;case"ArrowFunction":return this.createFunction(r);default:throw new Error(`Unknown AST node type: ${r.type}`)}}executeMethod(r,s,i,n){if(!r)return;let c=i.map((e)=>{return e.type==="ArrowFunction"?this.createFunction(e):this.evaluate(e,n)});if(s.startsWith("__operator_")&&s.endsWith("__")){let e=s.slice(11,-2);return this.executeOperator(r,e,c[0])}if(typeof r[s]!=="function")throw new Error(`Method ${s} does not exist on ${typeof r}`);try{return r[s](...c)}catch(e){throw new Error(`Error executing method ${s}: ${e.message}`)}}executeOperator(r,s,i){switch(s){case"+":return r+i;case"-":return r-i;case"*":return r*i;case"/":return r/i;case"%":return r%i;case">":return r>i;case"<":return r<i;case">=":return r>=i;case"<=":return r<=i;case"==":return r==i;case"===":return r===i;case"!=":return r!=i;case"!==":return r!==i;case"&&":return r&&i;case"||":return r||i;default:throw new Error(`Unknown operator: ${s}`)}}createFunction(r){return(...s)=>{let i={};return r.params.forEach((n,c)=>{i[n]=s[c]}),this.evaluateFunctionBody(r.body,i)}}evaluateFunctionBody(r,s){switch(r.type){case"PropertyAccess":if(!r.object){if(s.hasOwnProperty(r.property))return s[r.property];let p=Object.values(s)[0];return p&&typeof p==="object"?p[r.property]:void 0}let i=this.evaluateFunctionBody(r.object,s);return i?i[r.property]:void 0;case"MethodCall":let n=r.object?this.evaluateFunctionBody(r.object,s):Object.values(s)[0],c=r.args.map((f)=>this.evaluateFunctionBody(f,s));if(r.method.startsWith("__operator_")&&r.method.endsWith("__")){let f=r.method.slice(11,-2);return this.executeOperator(n,f,c[0])}if(!n)return;let t=n[r.method];return typeof t==="function"?t(...c):void 0;case"Literal":return r.value;case"Root":return r.expression?this.evaluateFunctionBody(r.expression,s):s;default:return this.evaluate(r,Object.values(s)[0])}}}var x={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"};function U(r){if(process.env.NO_COLOR)return r;return r.replace(/"([^"]+)":/g,`${x.cyan}"$1"${x.reset}:`).replace(/: "([^"]*)"/g,`: ${x.green}"$1"${x.reset}`).replace(/: (-?\d+\.?\d*)/g,`: ${x.yellow}$1${x.reset}`).replace(/: (true|false)/g,`: ${x.magenta}$1${x.reset}`).replace(/: (null)/g,`: ${x.gray}$1${x.reset}`).replace(/([{[])/g,`${x.gray}$1${x.reset}`).replace(/([}\]])/g,`${x.gray}$1${x.reset}`)}function z(r){if(process.env.NO_COLOR)return r;return`${x.yellow}${r}${x.reset}`}function m(r){if(process.env.NO_COLOR)return r;return`${x.cyan}${r}${x.reset}`}class _{options;constructor(r){this.options=r}format(r){if(this.options.raw)return this.formatRaw(r);if(this.options.type)return this.formatWithType(r);switch(this.options.format){case"yaml":return this.formatYaml(r);case"csv":return this.formatCsv(r);case"table":return this.formatTable(r);default:return this.formatJson(r)}}formatRaw(r){if(typeof r==="string")return r;if(r===void 0)return"";if(r===null)return"null";if(typeof r==="object")return JSON.stringify(r);return String(r)}formatJson(r){if(r===void 0)return"undefined";if(this.options.compact)return JSON.stringify(r);if(this.options.pretty){let s=JSON.stringify(r,null,2);return U(s)}return JSON.stringify(r,null,2)}formatWithType(r){let s=Array.isArray(r)?"array":typeof r,i=this.formatJson(r);return`[${s}] ${i}`}formatYaml(r){return this.toYaml(r,0)}toYaml(r,s){let i=" ".repeat(s);if(r===null||r===void 0)return"null";if(typeof r==="string")return r.includes(`
|
|
84
|
-
`)
|
|
85
|
-
${i}
|
|
86
|
-
|
|
87
|
-
`)}
|
|
88
|
-
|
|
89
|
-
`)
|
|
90
|
-
`)}
|
|
91
|
-
`)}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
`)
|
|
95
|
-
${o}:
|
|
96
|
-
`,O=t.map((h)=>` ${h.short.padEnd(e+2)} \u2192 ${h.full.padEnd(f+2)} # ${h.description}`).join(`
|
|
97
|
-
`);return p+O};return`
|
|
85
|
+
`)}v();function Ue(e){return e.trim().split(`
|
|
86
|
+
`).filter((t)=>t.length>0)}async function H(e,t){if(t)switch(t){case"json":return JSON.parse(e);case"json5":{let{parseJSON5:r}=await Promise.resolve().then(() => (ee(),Z));return r(e)}case"yaml":{let{parseYAML:r}=await Promise.resolve().then(() => (ne(),te));return r(e)}case"toml":{let{parseTOML:r}=await Promise.resolve().then(() => (se(),re));return r(e)}case"xml":{let{parseXML:r}=await Promise.resolve().then(() => (ce(),oe));return r(e)}case"ini":{let{parseINI:r}=await Promise.resolve().then(() => (pe(),ae));return r(e)}case"csv":{let{parseCSV:r}=await Promise.resolve().then(() => (j(),D));return r(e)}case"tsv":{let{parseTSV:r}=await Promise.resolve().then(() => (j(),D));return r(e)}case"protobuf":{let{parseProtobuf:r}=await Promise.resolve().then(() => me);return r(e)}case"javascript":{let{parseJavaScript:r}=await Promise.resolve().then(() => fe);return r(e)}case"typescript":{let{parseTypeScript:r}=await Promise.resolve().then(() => (de(),he));return r(e)}case"env":{let{parseENV:r}=await Promise.resolve().then(() => (xe(),ge));return r(e)}case"ndjson":{let{parseNDJSON:r}=await Promise.resolve().then(() => Ne);return r(e)}case"lines":return Ue(e);case"text":return e}switch(On(e)){case"json":return JSON.parse(e);case"json5":{let{parseJSON5:r}=await Promise.resolve().then(() => (ee(),Z));return r(e)}case"yaml":{let{parseYAML:r}=await Promise.resolve().then(() => (ne(),te));return r(e)}case"toml":{let{parseTOML:r}=await Promise.resolve().then(() => (se(),re));return r(e)}case"xml":{let{parseXML:r}=await Promise.resolve().then(() => (ce(),oe));return r(e)}case"ini":{let{parseINI:r}=await Promise.resolve().then(() => (pe(),ae));return r(e)}case"csv":{let{parseCSV:r}=await Promise.resolve().then(() => (j(),D));return r(e)}case"tsv":{let{parseTSV:r}=await Promise.resolve().then(() => (j(),D));return r(e)}case"protobuf":{let{parseProtobuf:r}=await Promise.resolve().then(() => me);return r(e)}case"javascript":{let{parseJavaScript:r}=await Promise.resolve().then(() => fe);return r(e)}case"typescript":{let{parseTypeScript:r}=await Promise.resolve().then(() => (de(),he));return r(e)}case"env":{let{parseENV:r}=await Promise.resolve().then(() => (xe(),ge));return r(e)}case"ndjson":{let{parseNDJSON:r}=await Promise.resolve().then(() => Ne);return r(e)}case"lines":return Ue(e);case"text":default:return e}}function On(e){let t=e.trim();if(h.TS_INTERFACE.test(t)||h.TS_TYPE_ALIAS.test(t)||h.TS_TYPE_ANNOTATION.test(t))return"typescript";if(h.JS_EXPORT.test(t))return"javascript";if(t.startsWith("<")&&t.includes(">")){let p=t.startsWith("<?xml"),l=/<\/\w+>/.test(t);if(p||l)return"xml"}if(t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]"))try{return JSON.parse(t),"json"}catch{if(h.JSON5_FEATURES.test(t))return"json5"}if(t.includes("=")){if(h.ENV_FEATURES.test(t))return"env";if(t.match(h.TOML_QUOTED_VALUES))return"toml";if(t.match(h.SECTION_HEADER)){if(t.match(h.TOML_SECTION)&&t.match(h.TOML_SYNTAX))return"toml";if(t.match(h.INI_SYNTAX))return"ini"}if(t.match(h.INI_SYNTAX))return"ini"}if(t.includes("---")||t.includes(": ")||t.match(/^[\s]*-\s+/m))return"yaml";let c=t.split(`
|
|
87
|
+
`);if(c.length>1){let p=h.NDJSON_FEATURES.test(t),l=c.every((w)=>{let g=w.trim();if(!g)return!0;try{return JSON.parse(g),!0}catch{return!1}});if(p&&l)return"ndjson";let m=c[0],f=(m.match(/,/g)||[]).length,E=(m.match(/\t/g)||[]).length;if(E>0&&E>=f)return"tsv";if(f>0)return"csv";return"lines"}return"text"}async function Je(e){let t=[];for await(let r of process.stdin)t.push(r);let n=Buffer.concat(t).toString("utf-8").trim();if(!n)return null;return H(n,e)}import{readdir as Tn,stat as Xe}from"fs/promises";import{join as wn,extname as vn,basename as In}from"path";var Sn=[".ts",".js",".tsx",".jsx"],bn=[".json",".yml",".yaml"],yn=[".md",".txt"],Qe=[...Sn,...bn,...yn];var He=/[.*+?^${}()|[\]\\]/g;async function Ee(e,t=!0){let r=await Bun.file(e).text();if(!t)return r;return H(r)}function Rn(e,t){return{path:e,name:In(e),ext:vn(e),size:Number(t.size),isDirectory:t.isDirectory(),isFile:t.isFile(),modified:t.mtime,created:t.birthtime}}async function Cn(e){let t=await Xe(e);return Rn(e,t)}function Fn(e){return e.startsWith(".")}function Ln(e,t){return t||!Fn(e)}function kn(e,t){if(t===void 0)return!0;return t.includes(e)}function _n(e,t){if(t===void 0)return!0;return t.test(e)}function Pn(e,t,n){let r=kn(e.ext,t),i=_n(e.name,n);return r&&i}function Mn(e,t){return e<=(t??1/0)}async function Dn(e,t,n,r){if(!Ln(t,r.includeHidden??!1))return[];let s=wn(e,t),o=await Cn(s);if(o.isFile)return Pn(o,r.extensions,r.pattern)?[o]:[];if(!o.isDirectory)return[];let c=r.recursive===!0?await Ke(s,n+1,r):[];return[o,...c]}async function Ke(e,t,n){if(!Mn(t,n.maxDepth))return[];let i=await Tn(e);return(await Promise.all(i.map((o)=>Dn(e,o,t,n)))).flat()}async function Ae(e,t={}){return Ke(e,0,t)}function jn(e,t){if(typeof e!=="string")return e;return new RegExp(e,t?"gi":"g")}function $n(e,t,n,r,i,s){let o={file:e,line:t+1,column:n+1,match:r};if(s===void 0)return o;let c=Math.max(0,t-s),a=Math.min(i.length,t+s+1);return{...o,context:i.slice(c,a)}}function Bn(e,t,n){if(!n)return;let r=t instanceof Error?t.message:String(t);console.error(`Failed to search ${e}: ${r}`)}function Vn(e,t,n,r,i,s){return[...e.matchAll(n)].map((u)=>$n(r,t,u.index,e,i,s))}async function Ye(e,t,n){try{let r=await Ee(e,!1);if(typeof r!=="string")return[];let s=r.split(`
|
|
88
|
+
`),o=s.flatMap((c,a)=>Vn(c,a,t,e,s,n.context)),u=n.maxMatches??1/0;return o.slice(0,u)}catch(r){return Bn(e,r,n.verbose??!1),[]}}async function Gn(e,t,n){let r=await Ae(e,{recursive:!0,extensions:[...Qe]});return(await Promise.all(r.filter((s)=>s.isFile).map((s)=>Ye(s.path,t,n)))).flat()}async function qe(e,t,n={}){let r=jn(e,n.ignoreCase??!1),i=await Xe(t);if(i.isFile())return Ye(t,r,n);if(i.isDirectory()&&n.recursive)return Gn(t,r,n);return[]}var Ze={".":"DOT","[":"LEFT_BRACKET","]":"RIGHT_BRACKET","{":"LEFT_BRACE","}":"RIGHT_BRACE","(":"LEFT_PAREN",")":"RIGHT_PAREN",":":"COLON",",":"COMMA"},et="+-*/%<>!&|=",tt=[" ","\t",`
|
|
89
|
+
`,"\r"];function I(e,t,n){return{type:e,value:t,position:n}}class Oe{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(I("EOF","",this.position)),e}nextToken(){let e=this.position,t=Ze[this.current];if(t){let a=this.current;return this.advance(),I(t,a,e)}if(this.current==="="&&this.peek()===">")return this.advance(),this.advance(),I("ARROW","=>",e);if(this.current==='"'||this.current==="'")return this.readString();let i=this.isDigit(this.current),s=this.current==="-"&&this.isDigit(this.peek());if(i||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 I("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 I("NUMBER",t,e)}readIdentifier(){let e=this.position,t="";while(this.isIdentifierChar(this.current))t+=this.current,this.advance();return I("IDENTIFIER",t,e)}readOperator(){let e=this.position,t="";while(this.isOperator(this.current))t+=this.current,this.advance();return I("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 tt.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 et.includes(e)}}var O=(e)=>{return{type:"Literal",value:e}},Se=(e)=>{if(e==="true")return O(!0);if(e==="false")return O(!1);if(e==="null")return O(null);return};function b(e,t){return`${t} at position ${e.position} (got ${e.type}: "${e.value}")`}function R(e,t){return{type:"PropertyAccess",property:e,object:t}}function Wn(e,t){return{type:"IndexAccess",index:e,object:t}}function Un(e,t,n){return{type:"SliceAccess",start:e,end:t,object:n}}function nt(e,t,n){return{type:"MethodCall",method:e,args:t,object:n}}function Jn(e,t){return{type:"ObjectOperation",operation:e,object:t}}function Qn(e){return{type:"ArraySpread",object:e}}function Hn(e,t){return{type:"ArrowFunction",params:e,body:t}}function be(e){return{type:"Root",expression:e}}var rt=["keys","values","entries","length"];function Xn(e){return rt.includes(e)}class ye{tokens;position=0;current;constructor(e){this.tokens=e,this.current=this.tokens[0]}parse(){if(this.current.type==="EOF")return be();let t=this.parseExpression();return be(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(),O(t)}if(e==="NUMBER"){let t=Number(this.current.value);return this.advance(),O(t)}if(e==="LEFT_PAREN"){let t=this.parseFunctionParams();return this.parseArrowFunction(t)}throw Error(b(this.current,"Unexpected token"))}parseAccessChain(e){let t=this.current.type;if(t==="IDENTIFIER"){let n=this.current.value;return this.advance(),R(n,e)}if(t==="LEFT_BRACKET")return this.parseBracketAccess(e);if(t==="LEFT_BRACE")return this.parseObjectOperation(e);throw Error(b(this.current,"Expected property name after dot"))}parseBracketAccess(e){if(this.advance(),this.current.type==="RIGHT_BRACKET")return this.advance(),Qn(e);if(this.current.type==="STRING"){let u=this.current.value;return this.advance(),this.expect("RIGHT_BRACKET"),R(u,e)}let r=this.current.type==="NUMBER",i=this.current.type==="OPERATOR"&&this.current.value==="-",s=this.current.type==="COLON";if(r||i||s)return this.parseNumericIndexOrSlice(e);throw Error(b(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"),Wn(n,e)}parseSliceFromColon(e,t){this.advance();let n=this.current.type==="NUMBER",r=this.current.type==="OPERATOR"&&this.current.value==="-",i=n||r,s=i?this.parseNumber():void 0;if(i)this.advance();return this.expect("RIGHT_BRACKET"),Un(e,s,t)}parseArrayAccess(){return this.parseBracketAccess()}parseObjectOperation(e){if(this.advance(),this.current.type!=="IDENTIFIER")throw Error(b(this.current,"Expected operation name after {"));let n=this.current.value;if(!Xn(n)){let r=rt.join(", ");throw Error(b(this.current,`Invalid object operation "${n}". Valid operations: ${r}`))}return this.advance(),this.expect("RIGHT_BRACE"),Jn(n,e)}parseIdentifierOrFunction(){let e=this.current.value;if(this.advance(),this.current.type==="ARROW")return this.parseArrowFunction([e]);let n=Se(e);if(n)return n;return R(e)}parseArrowFunction(e){this.expect("ARROW");let t=this.parseFunctionBody();return Hn(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=nt(`__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(),O(t)}if(e==="STRING"){let t=this.current.value;return this.advance(),O(t)}if(e==="LEFT_PAREN"){this.advance();let t=this.parseBinaryExpression();return this.expect("RIGHT_PAREN"),t}throw Error(b(this.current,"Unexpected token in function body"))}parseIdentifierChain(){let e=this.current.value;this.advance();let t=Se(e);if(t)return t;let n=R(e),r=()=>this.current.type==="DOT",i=()=>this.current.type==="IDENTIFIER";while(r()){if(this.advance(),!i())break;let s=this.current.value;this.advance(),n=R(s,n)}return n}parseMethodCall(e,t){this.expect("LEFT_PAREN");let n=this.parseMethodArguments();return this.expect("RIGHT_PAREN"),nt(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 R(t)}if(e==="NUMBER"){let t=Number(this.current.value);return this.advance(),O(t)}if(e==="STRING"){let t=this.current.value;return this.advance(),O(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(be(),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 R(n,e)}if(t==="LEFT_BRACKET")return this.parseBracketAccess(e);if(t==="LEFT_BRACE")return this.parseObjectOperation(e);throw Error(b(this.current,"Expected property name after dot"))}parseNumber(){let e=this.current.value==="-";if(e)this.advance();if(this.current.type!=="NUMBER")throw Error(b(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(b(this.current,`Expected ${e} but got ${this.current.type}`));this.advance()}}var Kn={"+":(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 st(e){return e.startsWith("__operator_")&&e.endsWith("__")}function it(e){return e.slice(11,-2)}function ot(e,t,n){let r=Kn[t];if(!r)throw Error(`Unknown operator: ${t}`);return r(e,n)}function Yn(e,t){return Object.fromEntries(e.map((n,r)=>[n,t[r]]))}function Te(e){return Object.values(e)[0]}function ut(e){return e!==null&&typeof e==="object"}function we(e,t){if(!ut(e))return;return e[t]}function ve(e,t){return e<0?t+e:e}function qn(e,t){if(!Array.isArray(e))return;let n=ve(t,e.length);return e[n]}function zn(e,t,n){if(!Array.isArray(e))return;let r=e.length,i=t!==void 0?ve(t,r):0,s=n!==void 0?ve(n,r):r;return e.slice(i,s)}function Zn(e,t){if(!ut(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 ct(e,t,n){if(!(e!==null&&e!==void 0&&typeof e[t]==="function"))throw Error(`Method ${t} does not exist on ${typeof e}`);try{return e[t].call(e,...n)}catch(i){let s=i instanceof Error?i.message:String(i);throw Error(`Error executing method ${t}: ${s}`)}}class Ie{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 qn(e.object?this.evaluate(e.object,t):t,e.index);case"SliceAccess":return zn(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 Zn(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 we(n,e.property)}evaluateMethodCall(e,t){let n=e.object?this.evaluate(e.object,t):t;if(st(e.method)){let s=it(e.method),o=this.evaluate(e.args[0],t);return ot(n,s,o)}let i=e.args.map((s)=>{return s.type==="ArrowFunction"?this.createFunction(s):this.evaluate(s,t)});return ct(n,e.method,i)}createFunction(e){return(...t)=>{let n=Yn(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,Te(t))}}evaluatePropertyAccessInFunction(e,t){if(e.object!==void 0){let s=this.evaluateFunctionBody(e.object,t);return we(s,e.property)}if(Object.prototype.hasOwnProperty.call(t,e.property))return t[e.property];let i=Te(t);return we(i,e.property)}evaluateMethodCallInFunction(e,t){let n=e.object?this.evaluateFunctionBody(e.object,t):Te(t);if(st(e.method)){let s=it(e.method),o=this.evaluateFunctionBody(e.args[0],t);return ot(n,s,o)}let i=e.args.map((s)=>this.evaluateFunctionBody(s,t));return ct(n,e.method,i)}}var d={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"},er=[{regex:/"([^"]+)":/g,replacement:`${d.cyan}"$1"${d.reset}:`},{regex:/: "([^"]*)"/g,replacement:`: ${d.green}"$1"${d.reset}`},{regex:/: (-?\d+\.?\d*)/g,replacement:`: ${d.yellow}$1${d.reset}`},{regex:/: (true|false)/g,replacement:`: ${d.magenta}$1${d.reset}`},{regex:/: (null)/g,replacement:`: ${d.gray}$1${d.reset}`},{regex:/([{[])/g,replacement:`${d.gray}$1${d.reset}`},{regex:/([}\]])/g,replacement:`${d.gray}$1${d.reset}`}];function at(e){if(process.env.NO_COLOR)return e;return er.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function pt(e){if(process.env.NO_COLOR)return e;return`${d.yellow}${e}${d.reset}`}function Re(e){if(process.env.NO_COLOR)return e;return`${d.cyan}${e}${d.reset}`}class B{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 at(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(([i,s])=>{let o=this.toYaml(s,t+2);if(typeof s==="object"&&s!==null)return`${n}${i}:
|
|
94
|
+
${o}`;return`${n}${i}: ${o}`}).join(`
|
|
95
|
+
`)}return String(e)}formatCsv(e){if(!Array.isArray(e))return this.formatJson(e);if(e.length===0)return"";if(typeof e[0]==="object"&&e[0]!==null&&!Array.isArray(e[0])){let t=Object.keys(e[0]),n=t.join(","),r=e.map((i)=>t.map((s)=>this.escapeCsvValue(i[s])).join(","));return[n,...r].join(`
|
|
96
|
+
`)}return e.map((t)=>this.escapeCsvValue(t)).join(`
|
|
97
|
+
`)}escapeCsvValue(e){if(e===null||e===void 0)return"";let t=String(e);if(t.includes(",")||t.includes('"')||t.includes(`
|
|
98
|
+
`))return`"${t.replace(/"/g,'""')}"`;return t}formatTable(e){if(!Array.isArray(e))return this.formatJson(e);if(e.length===0)return"(empty array)";if(typeof e[0]==="object"&&e[0]!==null&&!Array.isArray(e[0]))return this.formatObjectTable(e);return e.map((t,n)=>`${n}: ${this.formatRaw(t)}`).join(`
|
|
99
|
+
`)}formatObjectTable(e){let t=[...new Set(e.flatMap((o)=>Object.keys(o)))],n={};t.forEach((o)=>{n[o]=Math.max(o.length,...e.map((u)=>String(u[o]??"").length))});let r=t.map((o)=>o.padEnd(n[o])).join(" | "),i=t.map((o)=>"-".repeat(n[o])).join("-+-"),s=e.map((o)=>t.map((u)=>String(o[u]??"").padEnd(n[u])).join(" | "));return[r,i,...s].join(`
|
|
100
|
+
`)}}var C={ERROR:0,WARN:1,INFO:2,DEBUG:3};var tr={ERROR:C.ERROR,WARN:C.WARN,INFO:C.INFO,DEBUG:C.DEBUG},xs=process.env.LOG_LEVEL?tr[process.env.LOG_LEVEL]||C.INFO:C.INFO;function Ce(e){return e.replace(He,"\\$&")}var y=[{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"}],Is=new Map(y.map((e)=>[e.short,e.full])),Rs=new Map(y.map((e)=>[e.full,e.short])),nr=y.map((e)=>({regex:new RegExp(`${Ce(e.short)}(?![a-zA-Z])`,"g"),replacement:e.full})).sort((e,t)=>t.replacement.length-e.replacement.length),rr=y.map((e)=>({regex:new RegExp(`${Ce(e.full)}(?![a-zA-Z])`,"g"),replacement:e.short})).sort((e,t)=>t.regex.source.length-e.regex.source.length);function Fe(e){return nr.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function lt(e){return rr.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function mt(){let e=y.filter((s)=>s.type==="array"),t=y.filter((s)=>s.type==="object"),n=y.filter((s)=>s.type==="string"),r=y.filter((s)=>s.type==="any"),i=(s,o)=>{let u=Math.max(...o.map((l)=>l.short.length)),c=Math.max(...o.map((l)=>l.full.length)),a=`
|
|
101
|
+
${s}:
|
|
102
|
+
`,p=o.map((l)=>` ${l.short.padEnd(u+2)} \u2192 ${l.full.padEnd(c+2)} # ${l.description}`).join(`
|
|
103
|
+
`);return a+p};return`
|
|
98
104
|
Shorthand Reference:
|
|
99
|
-
${
|
|
100
|
-
${
|
|
101
|
-
${
|
|
102
|
-
${
|
|
105
|
+
${i("Array Methods",e)}
|
|
106
|
+
${i("Object Methods",t)}
|
|
107
|
+
${i("String Methods",n)}
|
|
108
|
+
${i("Universal Methods",r)}
|
|
103
109
|
|
|
104
110
|
Examples:
|
|
105
111
|
echo '[1,2,3]' | 1ls '.mp(x => x * 2)' # Short form
|
|
@@ -107,4 +113,4 @@ Examples:
|
|
|
107
113
|
|
|
108
114
|
1ls --shorten ".map(x => x * 2)" # Returns: .mp(x => x * 2)
|
|
109
115
|
1ls --expand ".mp(x => x * 2)" # Returns: .map(x => x * 2)
|
|
110
|
-
`}async function
|
|
116
|
+
`}async function sr(e){if(e.help)K(),process.exit(0);if(e.version){let t=await Bun.file("package.json").json();console.log(`1ls version ${t.version}`),process.exit(0)}return!1}async function ir(e){if(e.shortcuts)console.log(mt()),process.exit(0);if(e.shorten){let t=lt(e.shorten);console.log(t),process.exit(0)}if(e.expand){let t=Fe(e.expand);console.log(t),process.exit(0)}return!1}async function or(e){if(e.list){let n=await Ae(e.list,{recursive:e.recursive,extensions:e.extensions,maxDepth:e.maxDepth}),r=new B(e);return console.log(r.format(n)),!0}if(e.grep&&e.find)return await cr(e),!0;return!1}async function cr(e){let t=await qe(e.grep,e.find,{recursive:e.recursive,ignoreCase:e.ignoreCase,showLineNumbers:e.showLineNumbers});if(t.length===0){console.log(pt("No matches found"));return}for(let n of t){let r=`${Re(n.file)}:${n.line}:${n.column}`,i=e.showLineNumbers?`${r}: ${n.match}`:`${Re(n.file)}: ${n.match}`;console.log(i)}}async function ur(e,t){if(e.readFile){let s=t[t.indexOf("readFile")+1],o=await Ee(s);return e.expression=t[t.indexOf("readFile")+2]||".",o}let n=!process.stdin.isTTY,r=e.list||e.grep;if(!n&&!r)K(),process.exit(1);if(n)return await Je(e.inputFormat);return null}async function ar(e,t){if(!e.expression){let n=new B(e);console.log(n.format(t));return}try{let n=Fe(e.expression),i=new Oe(n).tokenize(),o=new ye(i).parse(),c=new Ie().evaluate(o,t),a=new B(e);console.log(a.format(c))}catch(n){console.error("Error:",n.message),process.exit(1)}}async function pr(e){let t=_e(e);if(await sr(t),await ir(t),await or(t))return;let r=await ur(t,e);await ar(t,r)}if(import.meta.main)pr(process.argv.slice(2)).catch((e)=>{console.error("Error:",e.message),process.exit(1)});export{pr as main};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Token } from "../types";
|
|
1
|
+
import { Token, TokenType } from "../types";
|
|
2
|
+
export declare function getContextSnippet(input: string, position: number, length?: number): string;
|
|
3
|
+
export declare function createToken(type: TokenType, value: string, position: number): Token;
|
|
2
4
|
export declare class Lexer {
|
|
3
5
|
private input;
|
|
4
6
|
private position;
|
package/dist/navigator/json.d.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { ASTNode } from "../types";
|
|
2
|
+
import { EvaluationContext, OperatorFunction } from "./types";
|
|
3
|
+
export declare const OPERATORS: Readonly<Record<string, OperatorFunction>>;
|
|
4
|
+
export declare function isOperatorMethod(method: string): boolean;
|
|
5
|
+
export declare function extractOperator(method: string): string;
|
|
6
|
+
export declare function executeOperator(left: unknown, operator: string, right: unknown): unknown;
|
|
7
|
+
export declare function createParameterContext(params: readonly string[], args: readonly unknown[]): EvaluationContext;
|
|
8
|
+
export declare function getImplicitParameter(context: EvaluationContext): unknown;
|
|
9
|
+
export declare function isValidObject(value: unknown): value is Record<string, unknown>;
|
|
10
|
+
export declare function getPropertyFromObject(obj: unknown, property: string): unknown;
|
|
11
|
+
export declare function normalizeArrayIndex(index: number, length: number): number;
|
|
12
|
+
export declare function getArrayElement(arr: unknown, index: number): unknown;
|
|
13
|
+
export declare function sliceArray(arr: unknown, start: number | undefined, end: number | undefined): unknown;
|
|
14
|
+
export declare function evaluateObjectOperation(obj: unknown, operation: "keys" | "values" | "entries" | "length"): unknown;
|
|
15
|
+
export declare function isCallableMethod(target: unknown, method: string): boolean;
|
|
16
|
+
export declare function callMethod(target: unknown, method: string, args: readonly unknown[]): unknown;
|
|
2
17
|
export declare class JsonNavigator {
|
|
3
|
-
evaluate(ast: ASTNode, data:
|
|
4
|
-
private
|
|
5
|
-
private
|
|
18
|
+
evaluate(ast: ASTNode, data: unknown): unknown;
|
|
19
|
+
private evaluatePropertyAccess;
|
|
20
|
+
private evaluateMethodCall;
|
|
6
21
|
private createFunction;
|
|
7
22
|
private evaluateFunctionBody;
|
|
23
|
+
private evaluatePropertyAccessInFunction;
|
|
24
|
+
private evaluateMethodCallInFunction;
|
|
8
25
|
}
|
|
@@ -9,3 +9,4 @@ export declare const APP_NAME = "1ls";
|
|
|
9
9
|
export declare const VALID_OUTPUT_FORMATS: readonly ["json", "yaml", "csv", "table"];
|
|
10
10
|
export declare const VALID_INPUT_FORMATS: readonly ["json", "yaml", "toml", "csv", "tsv", "lines", "text"];
|
|
11
11
|
export declare const VALID_OBJECT_OPERATIONS: readonly ["keys", "values", "entries", "length"];
|
|
12
|
+
export declare const REGEX_SPECIAL_CHARS: RegExp;
|
package/dist/utils/file.d.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
1
2
|
import type { FileInfo, ListOptions, GrepOptions, GrepResult } from "./types";
|
|
2
|
-
export declare function readFile(path: string): Promise<
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function readFile(path: string): Promise<unknown>;
|
|
4
|
+
export declare function readFile(path: string, parseJson: true): Promise<unknown>;
|
|
5
|
+
export declare function readFile(path: string, parseJson: false): Promise<string>;
|
|
6
|
+
export declare function serializeContent(content: unknown): string;
|
|
7
|
+
export declare function writeFile(path: string, content: unknown): Promise<void>;
|
|
8
|
+
export declare function createFileInfo(path: string, stats: Awaited<ReturnType<typeof stat>>): FileInfo;
|
|
4
9
|
export declare function getFileInfo(path: string): Promise<FileInfo>;
|
|
10
|
+
export declare function isHiddenFile(entry: string): boolean;
|
|
11
|
+
export declare function shouldIncludeHiddenFile(entry: string, includeHidden: boolean): boolean;
|
|
12
|
+
export declare function matchesExtensionFilter(ext: string, extensions: string[] | undefined): boolean;
|
|
13
|
+
export declare function matchesPatternFilter(name: string, pattern: RegExp | undefined): boolean;
|
|
14
|
+
export declare function shouldIncludeFile(info: FileInfo, extensions: string[] | undefined, pattern: RegExp | undefined): boolean;
|
|
15
|
+
export declare function isWithinDepthLimit(depth: number, maxDepth: number | undefined): boolean;
|
|
16
|
+
export declare function processDirectoryEntry(currentDir: string, entry: string, depth: number, options: ListOptions): Promise<FileInfo[]>;
|
|
17
|
+
export declare function walkDirectory(currentDir: string, depth: number, options: ListOptions): Promise<FileInfo[]>;
|
|
5
18
|
export declare function listFiles(dir: string, options?: ListOptions): Promise<FileInfo[]>;
|
|
6
|
-
export declare function
|
|
19
|
+
export declare function createRegexFromPattern(pattern: string | RegExp, ignoreCase: boolean): RegExp;
|
|
20
|
+
export declare function createGrepResult(filePath: string, lineNumber: number, matchIndex: number, lineContent: string, lines: readonly string[], contextSize: number | undefined): GrepResult;
|
|
21
|
+
export declare function logVerboseError(filePath: string, error: unknown, verbose: boolean): void;
|
|
22
|
+
export declare function extractMatchesFromLine(line: string, lineIndex: number, regex: RegExp, filePath: string, allLines: readonly string[], contextSize: number | undefined): GrepResult[];
|
|
23
|
+
export declare function shouldStopSearching(currentCount: number, maxMatches: number | undefined): boolean;
|
|
24
|
+
export declare function searchFileContent(filePath: string, regex: RegExp, options: GrepOptions): Promise<GrepResult[]>;
|
|
25
|
+
export declare function searchInDirectory(path: string, regex: RegExp, options: GrepOptions): Promise<GrepResult[]>;
|
|
26
|
+
export declare function grep(pattern: string, path: string, options?: GrepOptions): Promise<GrepResult[]>;
|
|
27
|
+
export declare function grep(pattern: RegExp, path: string, options?: GrepOptions): Promise<GrepResult[]>;
|
package/dist/utils/logger.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
readonly ERROR: 0;
|
|
3
|
-
readonly WARN: 1;
|
|
4
|
-
readonly INFO: 2;
|
|
5
|
-
readonly DEBUG: 3;
|
|
6
|
-
};
|
|
7
|
-
export type LogLevelType = (typeof LogLevel)[keyof typeof LogLevel];
|
|
8
|
-
export interface LogData {
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
}
|
|
1
|
+
import { LogLevelType, LogData } from "./types";
|
|
11
2
|
export declare class Logger {
|
|
12
3
|
private level;
|
|
13
4
|
private name;
|
package/dist/utils/stream.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { DataFormat } from "./types";
|
|
2
|
-
export declare function processInput(format?: DataFormat): Promise<
|
|
2
|
+
export declare function processInput(format?: DataFormat): Promise<unknown>;
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface GrepOptions {
|
|
|
21
21
|
maxMatches?: number;
|
|
22
22
|
showLineNumbers?: boolean;
|
|
23
23
|
context?: number;
|
|
24
|
+
verbose?: boolean;
|
|
24
25
|
}
|
|
25
26
|
export interface GrepResult {
|
|
26
27
|
file: string;
|
|
@@ -29,10 +30,20 @@ export interface GrepResult {
|
|
|
29
30
|
match: string;
|
|
30
31
|
context?: string[];
|
|
31
32
|
}
|
|
32
|
-
export type DataFormat = "json" | "yaml" | "toml" | "csv" | "tsv" | "lines" | "text";
|
|
33
|
+
export type DataFormat = "json" | "json5" | "yaml" | "toml" | "xml" | "ini" | "csv" | "tsv" | "protobuf" | "javascript" | "typescript" | "env" | "ndjson" | "lines" | "text";
|
|
33
34
|
export interface ShortcutMapping {
|
|
34
35
|
short: string;
|
|
35
36
|
full: string;
|
|
36
37
|
description: string;
|
|
37
38
|
type: "array" | "object" | "string" | "any";
|
|
38
39
|
}
|
|
40
|
+
export declare const LogLevel: {
|
|
41
|
+
readonly ERROR: 0;
|
|
42
|
+
readonly WARN: 1;
|
|
43
|
+
readonly INFO: 2;
|
|
44
|
+
readonly DEBUG: 3;
|
|
45
|
+
};
|
|
46
|
+
export type LogLevelType = (typeof LogLevel)[keyof typeof LogLevel];
|
|
47
|
+
export interface LogData {
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"workspaces": [
|
|
3
|
-
"site"
|
|
4
|
-
],
|
|
5
2
|
"name": "1ls",
|
|
6
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
7
4
|
"description": "1 line script - Lightweight JSON CLI with JavaScript syntax",
|
|
8
5
|
"type": "module",
|
|
9
6
|
"main": "dist/index.js",
|
|
@@ -28,6 +25,10 @@
|
|
|
28
25
|
"dev": "bun run ./src/cli/index.ts",
|
|
29
26
|
"prepublishOnly": "bun run test && bun run build",
|
|
30
27
|
"test": "bun test",
|
|
28
|
+
"test:unit": "bun test test/unit/",
|
|
29
|
+
"test:integration": "bun test test/integration/",
|
|
30
|
+
"test:integration:docker": "cd test/integration && docker-compose up --build --abort-on-container-exit",
|
|
31
|
+
"test:integration:docker:clean": "cd test/integration && docker-compose down -v",
|
|
31
32
|
"typecheck": "tsc --noEmit",
|
|
32
33
|
"lint": "bunx oxlint src/",
|
|
33
34
|
"lint:fix": "bunx oxlint src/ --fix",
|
package/dist/parser/parser.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Token, RootNode } from "../types";
|
|
2
|
-
export declare class Parser {
|
|
3
|
-
private tokens;
|
|
4
|
-
private position;
|
|
5
|
-
private current;
|
|
6
|
-
constructor(tokens: Token[]);
|
|
7
|
-
parse(): RootNode;
|
|
8
|
-
private parseExpression;
|
|
9
|
-
private parsePrimary;
|
|
10
|
-
private parseAccessChain;
|
|
11
|
-
private parseBracketAccess;
|
|
12
|
-
private parseArrayAccess;
|
|
13
|
-
private parseObjectOperation;
|
|
14
|
-
private parseIdentifierOrFunction;
|
|
15
|
-
private parseArrowFunction;
|
|
16
|
-
private parseFunctionBody;
|
|
17
|
-
private parseBinaryExpression;
|
|
18
|
-
private parseFunctionTerm;
|
|
19
|
-
private parseMethodCall;
|
|
20
|
-
private parseFunctionParams;
|
|
21
|
-
private parsePostfix;
|
|
22
|
-
private parseNumber;
|
|
23
|
-
private advance;
|
|
24
|
-
private expect;
|
|
25
|
-
}
|
package/dist/utils/parsers.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DataFormat } from "./types";
|
|
2
|
-
export declare function detectFormat(input: string): DataFormat;
|
|
3
|
-
export declare function parseLines(input: string): string[];
|
|
4
|
-
export declare function parseCSV(input: string, delimiter?: string): any[];
|
|
5
|
-
export declare function parseTSV(input: string): any[];
|
|
6
|
-
export declare function parseYAML(input: string): any;
|
|
7
|
-
export declare function parseTOML(input: string): any;
|
|
8
|
-
export declare function parseInput(input: string, format?: DataFormat): any;
|