import{a as e}from"./chunk-DXB73IDG-F_tmy-Lz.mjs";import{t}from"./chunk-SYMJJMQ4-jdmKoBFb.mjs";var n=e(t(),1);function r(){return Object.create(null)}function i(e,t,n){e[t]=n}function a(e){let t=r();for(let n of Object.keys(e)){let r=e[n];(typeof r==`string`||typeof r==`number`||typeof r==`boolean`||r===null)&&(t[n]=r)}return t}function o(e){let t=n.default.parse(e.trim(),{header:!0,dynamicTyping:!0,skipEmptyLines:!0}),r=t.data.map(e=>a(e));return{headers:t.meta.fields||[],data:r}}function s(e,t){return t.length===0?`${e.join(`,`)}
`:`${n.default.unparse(t,{columns:e}).replace(/\r\n/g,`
`)}
`}async function c(e,t){let n=e.find(e=>!e.startsWith(`-`)),r;if(!n||n===`-`)r=t.stdin;else try{let e=t.fs.resolvePath(t.cwd,n);r=await t.fs.readFile(e)}catch{return{headers:[],data:[],error:{stdout:``,stderr:`xan: ${n}: No such file or directory
`,exitCode:1}}}let{headers:i,data:a}=o(r);return{headers:i,data:a}}async function l(e,t){let n=0,r=[],i=[];for(let t=0;t<e.length;t++){let a=e[t];(a===`-l`||a===`--limit`)&&t+1<e.length?n=Number.parseInt(e[++t],10):(a===`-s`||a===`--select`)&&t+1<e.length?r=e[++t].split(`,`):a.startsWith(`-`)||i.push(a)}let{headers:a,data:o,error:s}=await c(i,t);if(s)return s;let l=r.length>0?r.filter(e=>a.includes(e)):a,u=n>0?o.slice(0,n):o,d=Math.max(...l.map(e=>e.length)),f=[],p=`─`.repeat(80);for(let e=0;e<u.length;e++){let t=u[e];f.push(`Row n\xB0${e}`),f.push(p);for(let e of l){let n=t[e],r=n==null?``:String(n);f.push(`${e.padEnd(d)} ${r}`)}e<u.length-1&&f.push(``)}return{stdout:`${f.join(`
`)}
`,stderr:``,exitCode:0}}async function u(e,t){let n=0,r=[];for(let t=0;t<e.length;t++){let i=e[t];i===`-n`&&t+1<e.length?n=Number.parseInt(e[++t],10):i.startsWith(`-`)||r.push(i)}let{headers:i,data:a,error:o}=await c(r,t);if(o)return o;let s=n>0?a.slice(0,n):a,l=i.map(e=>e.length);for(let e of s)for(let t=0;t<i.length;t++){let n=String(e[i[t]]??``);l[t]=Math.max(l[t],n.length)}let u=[];u.push(`\u250C${l.map(e=>`─`.repeat(e+2)).join(`┬`)}\u2510`);let d=i.map((e,t)=>` ${e.padEnd(l[t])} `).join(`│`);u.push(`│${d}│`),u.push(`\u251C${l.map(e=>`─`.repeat(e+2)).join(`┼`)}\u2524`);for(let e of s){let t=i.map((t,n)=>` ${String(e[t]??``).padEnd(l[n])} `).join(`│`);u.push(`│${t}│`)}return u.push(`\u2514${l.map(e=>`─`.repeat(e+2)).join(`┴`)}\u2518`),{stdout:`${u.join(`
`)}
`,stderr:``,exitCode:0}}export{o as a,u as c,l as i,s as n,c as o,i as r,r as s,a as t};
//# sourceMappingURL=chunk-F55TLFGB-BZSRX-Vi.mjs.map