1ls 0.0.1 → 0.0.3
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 +141 -16
- package/dist/cli/constants.d.ts +3 -0
- package/dist/completions/1ls.bash +63 -0
- package/dist/completions/1ls.zsh +79 -0
- package/dist/completions/install-completions.sh +52 -0
- package/dist/expression/constants.d.ts +1 -0
- package/dist/expression/index.d.ts +43 -0
- package/dist/expression/utils.d.ts +5 -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/formatter/output.d.ts +1 -1
- package/dist/index.js +73 -28
- package/dist/interactive/app.d.ts +1 -0
- package/dist/interactive/builder.d.ts +10 -0
- package/dist/interactive/fuzzy.d.ts +6 -0
- package/dist/interactive/input.d.ts +7 -0
- package/dist/interactive/methods.d.ts +12 -0
- package/dist/interactive/navigator.d.ts +2 -0
- package/dist/interactive/renderer-builder.d.ts +3 -0
- package/dist/interactive/renderer.d.ts +2 -0
- package/dist/interactive/state.d.ts +5 -0
- package/dist/interactive/terminal.d.ts +19 -0
- package/dist/interactive/types.d.ts +45 -0
- 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/types.d.ts +1 -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 +14 -11
- package/dist/parser/parser.d.ts +0 -25
- package/dist/utils/parsers.d.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
3
|
+
var mn=Object.defineProperty;var N=(e,t)=>{for(var n in t)mn(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(r)=>t[n]=()=>r})};var O=(e,t)=>()=>(e&&(t=e(e=0)),t);var fn,gn,xn,bn,Xe,Sn,yn,wn,En,Nn,An,Tn,On,vn,In,Cn,Rn,Mn,Fn,ge,xe,I,qe,be,Ln,Pn,kn,_n,Bn,jn,S;var k=O(()=>{fn=/^-?\d+$/,gn=/^[+-]?\d+$/,xn=/^-?\d+\.\d+$/,bn=/^[+-]?\d+\.\d+$/,Xe=/^-?\d+(\.\d+)?$/,Sn=/(\w+)=["']([^"']+)["']/g,yn=/^<(\w+)([^>]*?)\/>/,wn=/^<(\w+)([^>]*)>([\s\S]*)<\/\1>$/,En=/<\w+/,Nn=/<\/\w+>$/,An=/^<\?xml[^>]+\?>\s*/,Tn=/,(\s*[}\]])/g,On=/(['"])?([a-zA-Z_$][a-zA-Z0-9_$]*)\1?\s*:/g,vn=/\/\/|\/\*|,\s*[}\]]/,In=/^\[[\w.\s]+\]$/m,Cn=/^\[[\w.]+\]$/m,Rn=/^\w+\s*=\s*"[^"]*"$/m,Mn=/=\s*["[{]/m,Fn=/^\w+\s*=\s*.+$/m,ge={INTEGER:fn,FLOAT:xn},xe={INTEGER:gn,FLOAT:bn},I={NUMBER:Xe,ATTRIBUTES:Sn,SELF_CLOSING:yn,OPEN_TAG:wn,NESTED_TAGS:En,COMPLETE_TAGS:Nn,XML_DECLARATION:An},qe={NUMBER:Xe},be={TRAILING_COMMA:Tn,UNQUOTED_KEY:On},Ln=/^\s*export\s+(const|let|var|function|class|default|type|interface|enum)/m,Pn=/:\s*(string|number|boolean|any|unknown|void|never|object|Array|Promise)/,kn=/^\s*interface\s+\w+/m,_n=/^\s*type\s+\w+\s*=/m,Bn=/^[A-Z_][A-Z0-9_]*\s*=/m,jn=/^\{.*\}\s*$/m,S={JSON5_FEATURES:vn,SECTION_HEADER:In,TOML_SECTION:Cn,TOML_QUOTED_VALUES:Rn,TOML_SYNTAX:Mn,INI_SYNTAX:Fn,JS_EXPORT:Ln,TS_TYPE_ANNOTATION:Pn,TS_INTERFACE:kn,TS_TYPE_ALIAS:_n,ENV_FEATURES:Bn,NDJSON_FEATURES:jn}});var et={};N(et,{stripJSON5Comments:()=>Ye,parseJSON5:()=>Jn,normalizeJSON5:()=>Ze});function Dn(e){return e==='"'||e==="'"}function Vn(e,t,n){let o=e.slice(t).findIndex((i)=>i===n);return o===-1?e.length-t:o}function $n(e,t){let n=2,r=e.length-t;while(n<r){let o=e[t+n],s=e[t+n+1];if(o==="*"&&s==="/")return n+1;n++}return n}function Gn(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 Wn(e,t,n,r,o){if(Dn(t))return e.result.push(t),{result:e.result,inString:!0,delimiter:t,skip:0};if(t==="/"&&n==="/"){let a=Vn(r,o,`
|
|
4
|
+
`);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:a}}if(t==="/"&&n==="*"){let a=$n(r,o);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:a}}return e.result.push(t),e}function Ye(e){let t=e.split("");return t.reduce((n,r,o)=>{if(n.skip>0)return{result:n.result,inString:n.inString,delimiter:n.delimiter,skip:n.skip-1};let i=t[o+1];return n.inString?Gn(n,r,i):Wn(n,r,i,t,o)},{result:[],inString:!1,delimiter:"",skip:0}).result.join("")}function Ze(e){let t=Ye(e);return t=t.replace(be.TRAILING_COMMA,"$1"),t=t.replace(be.UNQUOTED_KEY,'"$2":'),t=t.replace(/'/g,'"'),t}function Jn(e){let t=Ze(e);return JSON.parse(t)}var tt=O(()=>{k()});var Un,zn,Qn,Hn=(e)=>Un.includes(e),Kn=(e)=>zn.includes(e),Xn=(e)=>Qn.includes(e),$=(e)=>{if(Hn(e))return!0;if(Kn(e))return!1;return},G=(e)=>{if(Xn(e))return null;return},se=(e)=>{if(e==="")return;let t=Number(e);return isNaN(t)?void 0:t};var oe=O(()=>{Un=["true","yes","on"],zn=["false","no","off"],Qn=["null","~",""]});var rt={};N(rt,{parseYAMLValue:()=>W,parseYAML:()=>qn,findPreviousKey:()=>nt});function W(e){let t=e.startsWith('"')&&e.endsWith('"'),n=e.startsWith("'")&&e.endsWith("'");if(t||n)return e.slice(1,-1);let o=$(e);if(o!==void 0)return o;let s=G(e);if(s!==void 0)return s;if(ge.INTEGER.test(e))return parseInt(e,10);if(ge.FLOAT.test(e))return parseFloat(e);if(e.startsWith("[")&&e.endsWith("]"))return e.slice(1,-1).split(",").map((l)=>W(l.trim()));if(e.startsWith("{")&&e.endsWith("}")){let l={};return e.slice(1,-1).split(",").forEach((d)=>{let[h,g]=d.split(":").map((x)=>x.trim());if(h&&g)l[h]=W(g)}),l}return e}function nt(e,t){return Array.from({length:t},(r,o)=>t-1-o).reduce((r,o)=>{if(r!==null)return r;let s=e[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();if(!a.substring(l+1).trim())return p}return null},null)}function qn(e){let t=e.trim().split(`
|
|
5
|
+
`),n={},r=[n],o=[0],s=null,i=-1;return t.forEach((c,a)=>{let u=c,l=u.indexOf("#");if(l>=0){let w=u.substring(0,l);if((w.match(/["']/g)||[]).length%2===0)u=w}if(!u.trim())return;if(u.trim()==="---"||u.trim()==="...")return;let d=u.length-u.trimStart().length,h=u.trim();if(h.startsWith("- ")){let w=h.substring(2).trim();if(s!==null&&d===i){s.push(W(w));return}s=[W(w)],i=d;while(o.length>1&&o[o.length-1]>=d)r.pop(),o.pop();let E=r[r.length-1];if(typeof E==="object"&&!Array.isArray(E)){let P=nt(t,a);if(P)E[P]=s}return}if(!h.startsWith("- "))s=null,i=-1;let y=h.indexOf(":");if(y>0){let w=h.substring(0,y).trim(),L=h.substring(y+1).trim();while(o.length>1&&o[o.length-1]>=d)r.pop(),o.pop();let E=r[r.length-1];if(!L){let re=a+1;if(re<t.length){if(t[re].trim().startsWith("- "))return}let P={};E[w]=P,r.push(P),o.push(d)}else E[w]=W(L)}}),n}var st=O(()=>{k();oe()});var ot={};N(ot,{parseTOMLValue:()=>ie,parseTOML:()=>Yn});function ie(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(xe.INTEGER.test(e))return parseInt(e,10);if(xe.FLOAT.test(e))return parseFloat(e);if(e.startsWith("[")&&e.endsWith("]"))return e.slice(1,-1).split(",").map((a)=>ie(a.trim()));if(e.startsWith("{")&&e.endsWith("}")){let c={};return e.slice(1,-1).split(",").forEach((u)=>{let[l,p]=u.split("=").map((d)=>d.trim());if(l&&p)c[l]=ie(p)}),c}return e}function Yn(e){let t=e.trim().split(`
|
|
6
|
+
`),n={},r=n,o=[];return t.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]=ie(h)}}),n}var it=O(()=>{k()});var at={};N(at,{parseXMLValue:()=>z,parseXMLElement:()=>Se,parseXMLChildren:()=>ct,parseXMLAttributes:()=>ce,parseXML:()=>tr});function z(e){let t=e.trim();if(t==="true")return!0;if(t==="false")return!1;if(I.NUMBER.test(t))return parseFloat(t);return t}function ce(e){return Array.from(e.matchAll(I.ATTRIBUTES)).reduce((n,r)=>{let[,o,s]=r;return n[o]=z(s),n},{})}function Se(e){let t=e.trim(),n=t.match(I.SELF_CLOSING);if(n){let[,p,d]=n;if(d.trim().length>0)return{[p]:{_attributes:ce(d)}};return{[p]:null}}let r=t.match(I.OPEN_TAG);if(!r)return z(t);let[,o,s,i]=r,c=i.trim();if(!I.NESTED_TAGS.test(c)){if(s.trim().length>0)return{[o]:{_attributes:ce(s),_text:z(c)}};return{[o]:z(c)}}let u=ct(c);if(s.trim().length>0)return{[o]:{_attributes:ce(s),...u}};return{[o]:u}}function Zn(e){let t=e.split(""),n=t.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 g=t[c+1]==="/",x=e.slice(c).match(/^<[^>]+\/>/);if(g)return s.buffer.push(i),{elements:s.elements,buffer:s.buffer,depth:s.depth-1,skip:0};if(x){let w=x[0];if(w.split("").forEach((E)=>s.buffer.push(E)),s.depth===0){let E=s.buffer.join("").trim();s.elements.push(E),s.buffer.length=0}return{elements:s.elements,buffer:s.buffer,depth:s.depth,skip:w.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(I.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 er(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 ct(e){return Zn(e).reduce((n,r)=>{let o=Se(r);if(typeof o==="object"&&o!==null)Object.entries(o).forEach(([i,c])=>{er(n,i,c)});return n},{})}function tr(e){let t=e.trim(),n=t.match(I.XML_DECLARATION),r=n?t.slice(n[0].length):t;return Se(r)}var ut=O(()=>{k()});var lt={};N(lt,{parseINIValue:()=>ye,parseINI:()=>sr});function ye(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(qe.NUMBER.test(t))return parseFloat(t);return t}function nr(e){let t=e.indexOf(";"),n=e.indexOf("#");if(!(t>=0||n>=0))return e;let o=t>=0&&n>=0?Math.min(t,n):Math.max(t,n);return e.substring(0,o)}function rr(e,t){let r=nr(t).trim();if(!r)return e;if(r.startsWith("[")&&r.endsWith("]")){let a=r.slice(1,-1).trim();if(!e.result[a])e.result[a]={};return{result:e.result,currentSection:a}}let i=r.indexOf("=");if(i>0){let a=r.substring(0,i).trim(),u=r.substring(i+1).trim();if(e.currentSection.length>0){let p=e.result[e.currentSection];p[a]=ye(u)}else e.result[a]=ye(u)}return e}function sr(e){return e.trim().split(`
|
|
7
|
+
`).reduce((r,o)=>rr(r,o),{result:{},currentSection:""}).result}var pt=O(()=>{k()});var Ee={};N(Ee,{parseTSV:()=>or,parseCSVValue:()=>ht,parseCSVLine:()=>we,parseCSV:()=>mt});function we(e,t){let n=[],r="",o=!1,s=e.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===t&&!o){n.push(r),r="";return}r+=i}),n.push(r),n.map((i)=>i.trim())}function ht(e){let t=e.trim();if(t.startsWith('"')&&t.endsWith('"'))return t.slice(1,-1).replace(/""/g,'"');let r=se(t);if(r!==void 0)return r;let o=t.toLowerCase(),s=$(o);if(s!==void 0)return s;let i=G(o);if(i!==void 0)return i;return t}function mt(e,t=","){let n=e.trim().split(`
|
|
8
|
+
`);if(n.length===0)return[];let r=we(n[0],t);if(n.length===1)return[];return n.slice(1).reduce((o,s)=>{let i=we(s,t);if(i.length===0)return o;let c=Object.fromEntries(r.map((a,u)=>[a,ht(i[u]||"")]));return[...o,c]},[])}function or(e){return mt(e,"\t")}var Ne=O(()=>{oe()});var dt={};N(dt,{parseProtobufJSON:()=>cr,parseProtobuf:()=>ir});function ir(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 cr(e){return JSON.parse(e)}var ft={};N(ft,{stripJSComments:()=>ae,parseJavaScript:()=>mr});function ar(e){return e==='"'||e==="'"||e==="`"}function ur(e,t,n){let o=e.slice(t).findIndex((i)=>i===n);return o===-1?e.length-t:o}function lr(e,t){let n=2,r=e.length-t;while(n<r){let o=e[t+n],s=e[t+n+1];if(o==="*"&&s==="/")return n+1;n++}return n}function pr(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 hr(e,t,n,r,o){if(ar(t))return e.result.push(t),{result:e.result,inString:!0,delimiter:t,skip:0};if(t==="/"&&n==="/"){let a=ur(r,o,`
|
|
9
|
+
`);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:a}}if(t==="/"&&n==="*"){let a=lr(r,o);return{result:e.result,inString:e.inString,delimiter:e.delimiter,skip:a}}return e.result.push(t),e}function ae(e){let t=e.split("");return t.reduce((n,r,o)=>{if(n.skip>0)return{result:n.result,inString:n.inString,delimiter:n.delimiter,skip:n.skip-1};let i=t[o+1];return n.inString?pr(n,r,i):hr(n,r,i,t,o)},{result:[],inString:!1,delimiter:"",skip:0}).result.join("")}function mr(input){let withoutComments=ae(input),exportMatch=withoutComments.match(/export\s+default\s+([\s\S]+)/),code=exportMatch?exportMatch[1]:withoutComments,trimmed=code.trim().replace(/;$/,"");return eval(`(${trimmed})`)}var gt={};N(gt,{parseTypeScript:()=>fr});function dr(){if(ue!==null)return ue;return ue=new Bun.Transpiler({loader:"ts"}),ue}function fr(input){let withoutComments=ae(input),transpiler=dr(),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 ue=null;var xt=()=>{};var St={};N(St,{parseENVValue:()=>bt,parseENV:()=>br});function bt(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=$(t);if(s!==void 0)return s;let i=G(t);if(i!==void 0)return i;let c=se(t);if(c!==void 0)return c;return t}function gr(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 xr(e,t){let r=gr(t).trim();if(!r)return e;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();e.result[u]=bt(l)}return e}function br(e){return e.trim().split(`
|
|
11
|
+
`).reduce((r,o)=>xr(r,o),{result:{}}).result}var yt=O(()=>{oe()});var wt={};N(wt,{parseNDJSON:()=>Sr});function Sr(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 Qe=["json","yaml","csv","table"],He=["json","yaml","toml","csv","tsv","lines","text"];var dn={format:"json",pretty:!1,raw:!1,compact:!1,type:!1,recursive:!1,ignoreCase:!1,showLineNumbers:!1,inputFormat:void 0};function Ke(e){let t={...dn},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],i=Qe.includes(s);if(s&&i)t.format=s}break;case"--input-format":case"-if":if(n++,n<e.length){let s=e[n];if(He.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"--interactive":t.interactive=!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((i)=>i.startsWith(".")?i:`.${i}`)}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 fe(){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
|
+
`)}k();function yr(e){return e.trim().split(`
|
|
86
|
+
`).filter((t)=>t.length>0)}async function le(e,t){switch(t??wr(e)){case"json":return JSON.parse(e);case"json5":{let{parseJSON5:r}=await Promise.resolve().then(() => (tt(),et));return r(e)}case"yaml":{let{parseYAML:r}=await Promise.resolve().then(() => (st(),rt));return r(e)}case"toml":{let{parseTOML:r}=await Promise.resolve().then(() => (it(),ot));return r(e)}case"xml":{let{parseXML:r}=await Promise.resolve().then(() => (ut(),at));return r(e)}case"ini":{let{parseINI:r}=await Promise.resolve().then(() => (pt(),lt));return r(e)}case"csv":{let{parseCSV:r}=await Promise.resolve().then(() => (Ne(),Ee));return r(e)}case"tsv":{let{parseTSV:r}=await Promise.resolve().then(() => (Ne(),Ee));return r(e)}case"protobuf":{let{parseProtobuf:r}=await Promise.resolve().then(() => dt);return r(e)}case"javascript":{let{parseJavaScript:r}=await Promise.resolve().then(() => ft);return r(e)}case"typescript":{let{parseTypeScript:r}=await Promise.resolve().then(() => (xt(),gt));return r(e)}case"env":{let{parseENV:r}=await Promise.resolve().then(() => (yt(),St));return r(e)}case"ndjson":{let{parseNDJSON:r}=await Promise.resolve().then(() => wt);return r(e)}case"lines":return yr(e);case"text":default:return e}}function wr(e){let t=e.trim();if(S.TS_INTERFACE.test(t)||S.TS_TYPE_ALIAS.test(t)||S.TS_TYPE_ANNOTATION.test(t))return"typescript";if(S.JS_EXPORT.test(t))return"javascript";if(t.startsWith("<")&&t.includes(">")){let u=t.startsWith("<?xml"),l=/<\/\w+>/.test(t);if(u||l)return"xml"}if(t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]"))try{return JSON.parse(t),"json"}catch{if(S.JSON5_FEATURES.test(t))return"json5"}if(t.includes("=")){if(S.ENV_FEATURES.test(t))return"env";if(t.match(S.TOML_QUOTED_VALUES))return"toml";if(t.match(S.SECTION_HEADER)){if(t.match(S.TOML_SECTION)&&t.match(S.TOML_SYNTAX))return"toml";if(t.match(S.INI_SYNTAX))return"ini"}if(t.match(S.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 u=S.NDJSON_FEATURES.test(t),l=c.every((y)=>{let x=y.trim();if(!x)return!0;try{return JSON.parse(x),!0}catch{return!1}});if(u&&l)return"ndjson";let p=c[0],d=(p.match(/,/g)||[]).length,h=(p.match(/\t/g)||[]).length;if(h>0&&h>=d)return"tsv";if(d>0)return"csv";return"lines"}return"text"}async function Et(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 le(n,e)}import{readdir as Tr,stat as Tt}from"fs/promises";import{join as Or,extname as vr,basename as Ir}from"path";var Er=[".ts",".js",".tsx",".jsx"],Nr=[".json",".yml",".yaml"],Ar=[".md",".txt"],Nt=[...Er,...Nr,...Ar];var At=/[.*+?^${}()|[\]\\]/g;async function pe(e,t=!0){let r=await Bun.file(e).text();if(!t)return r;return le(r)}function Cr(e,t){return{path:e,name:Ir(e),ext:vr(e),size:Number(t.size),isDirectory:t.isDirectory(),isFile:t.isFile(),modified:t.mtime,created:t.birthtime}}async function Rr(e){let t=await Tt(e);return Cr(e,t)}function Mr(e){return e.startsWith(".")}function Fr(e,t){return t||!Mr(e)}function Lr(e,t){if(t===void 0)return!0;return t.includes(e)}function Pr(e,t){if(t===void 0)return!0;return t.test(e)}function kr(e,t,n){let r=Lr(e.ext,t),o=Pr(e.name,n);return r&&o}function _r(e,t){return e<=(t??1/0)}async function Br(e,t,n,r){if(!Fr(t,r.includeHidden??!1))return[];let s=Or(e,t),i=await Rr(s);if(i.isFile)return kr(i,r.extensions,r.pattern)?[i]:[];if(!i.isDirectory)return[];let a=r.recursive===!0?await Ot(s,n+1,r):[];return[i,...a]}async function Ot(e,t,n){if(!_r(t,n.maxDepth))return[];let o=await Tr(e);return(await Promise.all(o.map((i)=>Br(e,i,t,n)))).flat()}async function Ae(e,t={}){return Ot(e,0,t)}function jr(e,t){if(typeof e!=="string")return e;return new RegExp(e,t?"gi":"g")}function Dr(e,t,n,r,o,s){let i={file:e,line:t+1,column:n+1,match:r};if(s===void 0)return i;let a=Math.max(0,t-s),u=Math.min(o.length,t+s+1);return{...i,context:o.slice(a,u)}}function Vr(e,t,n){if(!n)return;let r=t instanceof Error?t.message:String(t);console.error(`Failed to search ${e}: ${r}`)}function $r(e,t,n,r,o,s){return[...e.matchAll(n)].map((c)=>Dr(r,t,c.index,e,o,s))}async function vt(e,t,n){try{let r=await pe(e,!1);if(typeof r!=="string")return[];let s=r.split(`
|
|
88
|
+
`),i=s.flatMap((a,u)=>$r(a,u,t,e,s,n.context)),c=n.maxMatches??1/0;return i.slice(0,c)}catch(r){return Vr(e,r,n.verbose??!1),[]}}async function Gr(e,t,n){let r=await Ae(e,{recursive:!0,extensions:[...Nt]});return(await Promise.all(r.filter((s)=>s.isFile).map((s)=>vt(s.path,t,n)))).flat()}async function It(e,t,n={}){let r=jr(e,n.ignoreCase??!1),o=await Tt(t);if(o.isFile())return vt(t,r,n);if(o.isDirectory()&&n.recursive)return Gr(t,r,n);return[]}var Rt={".":"DOT","[":"LEFT_BRACKET","]":"RIGHT_BRACKET","{":"LEFT_BRACE","}":"RIGHT_BRACE","(":"LEFT_PAREN",")":"RIGHT_PAREN",":":"COLON",",":"COMMA"},Mt="+-*/%<>!&|=",Ft=[" ","\t",`
|
|
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}:
|
|
94
|
+
${i}`;return`${n}${o}: ${i}`}).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((o)=>t.map((s)=>this.escapeCsvValue(o[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((i)=>Object.keys(i)))],n={};t.forEach((i)=>{n[i]=Math.max(i.length,...e.map((c)=>String(c[i]??"").length))});let r=t.map((i)=>i.padEnd(n[i])).join(" | "),o=t.map((i)=>"-".repeat(n[i])).join("-+-"),s=e.map((i)=>t.map((c)=>String(i[c]??"").padEnd(n[c])).join(" | "));return[r,o,...s].join(`
|
|
100
|
+
`)}}var j={ERROR:0,WARN:1,INFO:2,DEBUG:3};var ts={ERROR:j.ERROR,WARN:j.WARN,INFO:j.INFO,DEBUG:j.DEBUG},Yo=process.env.LOG_LEVEL?ts[process.env.LOG_LEVEL]||j.INFO:j.INFO;function Me(e){return e.replace(At,"\\$&")}var M=[{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"}],ui=new Map(M.map((e)=>[e.short,e.full])),li=new Map(M.map((e)=>[e.full,e.short])),ns=M.map((e)=>({regex:new RegExp(`${Me(e.short)}(?![a-zA-Z])`,"g"),replacement:e.full})).sort((e,t)=>t.replacement.length-e.replacement.length),rs=M.map((e)=>({regex:new RegExp(`${Me(e.full)}(?![a-zA-Z])`,"g"),replacement:e.short})).sort((e,t)=>t.regex.source.length-e.regex.source.length);function Y(e){return ns.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function Gt(e){return rs.reduce((t,{regex:n,replacement:r})=>t.replace(n,r),e)}function Wt(){let e=M.filter((s)=>s.type==="array"),t=M.filter((s)=>s.type==="object"),n=M.filter((s)=>s.type==="string"),r=M.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=`
|
|
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`
|
|
98
104
|
Shorthand Reference:
|
|
99
|
-
${
|
|
100
|
-
${
|
|
101
|
-
${
|
|
102
|
-
${
|
|
105
|
+
${o("Array Methods",e)}
|
|
106
|
+
${o("Object Methods",t)}
|
|
107
|
+
${o("String Methods",n)}
|
|
108
|
+
${o("Universal Methods",r)}
|
|
103
109
|
|
|
104
110
|
Examples:
|
|
105
111
|
echo '[1,2,3]' | 1ls '.mp(x => x * 2)' # Short form
|
|
@@ -107,4 +113,43 @@ 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
|
-
`}
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runInteractive: (data: unknown) => Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { State } from "./types";
|
|
2
|
+
export declare const enterBuildMode: (state: State) => State;
|
|
3
|
+
export declare const exitBuildMode: (state: State) => State;
|
|
4
|
+
export declare const updateBuildQuery: (state: State, query: string) => State;
|
|
5
|
+
export declare const updateArrowFnQuery: (state: State, query: string) => State;
|
|
6
|
+
export declare const selectMethod: (state: State, methodIndex: number) => State;
|
|
7
|
+
export declare const updateArrowFnExpression: (state: State, pathIndex: number) => State;
|
|
8
|
+
export declare const completeArrowFn: (state: State) => State;
|
|
9
|
+
export declare const cancelArrowFn: (state: State) => State;
|
|
10
|
+
export declare const undoLastSegment: (state: State) => State;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Method {
|
|
2
|
+
name: string;
|
|
3
|
+
signature: string;
|
|
4
|
+
description: string;
|
|
5
|
+
template?: string;
|
|
6
|
+
category?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const ARRAY_METHODS: Method[];
|
|
9
|
+
export declare const STRING_METHODS: Method[];
|
|
10
|
+
export declare const OBJECT_OPERATIONS: Method[];
|
|
11
|
+
export declare const NUMBER_METHODS: Method[];
|
|
12
|
+
export declare const getMethodsForType: (type: string) => Method[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { State, JsonPath } from "./types";
|
|
2
|
+
export declare const createInitialState: (paths: JsonPath[], originalData: unknown) => State;
|
|
3
|
+
export declare const updateQuery: (state: State, newQuery: string) => State;
|
|
4
|
+
export declare const updateSelection: (state: State, delta: number) => State;
|
|
5
|
+
export declare const getSelectedPath: (state: State) => JsonPath | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const clearScreen: () => void;
|
|
2
|
+
export declare const moveCursor: (x: number, y: number) => void;
|
|
3
|
+
export declare const hideCursor: () => void;
|
|
4
|
+
export declare const showCursor: () => void;
|
|
5
|
+
export declare const enableRawMode: () => void;
|
|
6
|
+
export declare const disableRawMode: () => void;
|
|
7
|
+
export declare const colors: {
|
|
8
|
+
reset: string;
|
|
9
|
+
bright: string;
|
|
10
|
+
dim: string;
|
|
11
|
+
cyan: string;
|
|
12
|
+
green: string;
|
|
13
|
+
yellow: string;
|
|
14
|
+
blue: string;
|
|
15
|
+
magenta: string;
|
|
16
|
+
gray: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const colorize: (text: string, color: string) => string;
|
|
19
|
+
export declare const highlightMatches: (text: string, matches: number[]) => string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface JsonPath {
|
|
2
|
+
path: string;
|
|
3
|
+
value: unknown;
|
|
4
|
+
type: string;
|
|
5
|
+
displayValue: string;
|
|
6
|
+
}
|
|
7
|
+
export type InteractiveMode = "explore" | "build" | "build-arrow-fn";
|
|
8
|
+
export interface ExpressionBuilder {
|
|
9
|
+
basePath: string;
|
|
10
|
+
baseValue: unknown;
|
|
11
|
+
baseType: string;
|
|
12
|
+
expression: string;
|
|
13
|
+
currentMethodIndex: number;
|
|
14
|
+
arrowFnContext: ArrowFnContext | null;
|
|
15
|
+
}
|
|
16
|
+
export interface ArrowFnContext {
|
|
17
|
+
paramName: string;
|
|
18
|
+
paramType: string;
|
|
19
|
+
paramValue: unknown;
|
|
20
|
+
paramPaths: JsonPath[];
|
|
21
|
+
expression: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Method {
|
|
24
|
+
name: string;
|
|
25
|
+
signature: string;
|
|
26
|
+
description: string;
|
|
27
|
+
template?: string;
|
|
28
|
+
category?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface State {
|
|
31
|
+
mode: InteractiveMode;
|
|
32
|
+
paths: JsonPath[];
|
|
33
|
+
matches: FuzzyMatch<JsonPath>[];
|
|
34
|
+
query: string;
|
|
35
|
+
selectedIndex: number;
|
|
36
|
+
builder: ExpressionBuilder | null;
|
|
37
|
+
originalData: unknown;
|
|
38
|
+
methodMatches: FuzzyMatch<Method>[];
|
|
39
|
+
propertyMatches: FuzzyMatch<JsonPath>[];
|
|
40
|
+
}
|
|
41
|
+
export interface FuzzyMatch<T> {
|
|
42
|
+
item: T;
|
|
43
|
+
score: number;
|
|
44
|
+
matches: number[];
|
|
45
|
+
}
|
|
@@ -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
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -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[]>;
|