just-bash 2.7.2 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +19 -1
  2. package/dist/Bash.d.ts +6 -0
  3. package/dist/banned-patterns-test.d.ts +8 -0
  4. package/dist/bin/chunks/awk2-OKD2P6CM.js +21 -0
  5. package/dist/bin/{shell/chunks/chunk-VHH2M5JC.js → chunks/chunk-CQZVMYQ3.js} +2 -2
  6. package/dist/bin/chunks/chunk-G43H2WGH.js +17 -0
  7. package/dist/bin/chunks/chunk-OBI37ZY4.js +9 -0
  8. package/dist/bin/{shell/chunks/chunk-XI5LBYFX.js → chunks/chunk-W2KVOOMM.js} +1 -1
  9. package/dist/bin/chunks/{expansion-LVCGISX6.js → expansion-D4M4UY4T.js} +1 -1
  10. package/dist/bin/chunks/{file-6PCTL3MH.js → file-MWSA2WYI.js} +12 -12
  11. package/dist/bin/chunks/{grep-X7UU5FD6.js → grep-BD56656Z.js} +1 -1
  12. package/dist/bin/chunks/help-L43ENI4H.js +16 -0
  13. package/dist/bin/{shell/chunks/jq-QR3PX7FE.js → chunks/jq-TJPN2INT.js} +1 -1
  14. package/dist/bin/chunks/{md5sum-2VAAFCTS.js → md5sum-VHPDBIVV.js} +1 -1
  15. package/dist/bin/chunks/{printf-XPBSFXJE.js → printf-4W7NDLLV.js} +1 -1
  16. package/dist/bin/{shell/chunks/rg-RSJPHAP5.js → chunks/rg-IZR5557M.js} +9 -9
  17. package/dist/bin/{shell/chunks/sed-356P4DZB.js → chunks/sed-E4QAUCYQ.js} +1 -1
  18. package/dist/bin/chunks/{sha1sum-67P4ME4N.js → sha1sum-4SVNPPXZ.js} +1 -1
  19. package/dist/bin/{shell/chunks/sha256sum-MV3WQ4QF.js → chunks/sha256sum-BM3AFTIE.js} +1 -1
  20. package/dist/bin/chunks/sort-QF3YLXRW.js +16 -0
  21. package/dist/bin/chunks/{split-JJFZRWRC.js → split-7UP7EATZ.js} +1 -1
  22. package/dist/bin/{shell/chunks/tr-FMT6JWLE.js → chunks/tr-IAUNBQKH.js} +3 -3
  23. package/dist/bin/chunks/xan-OR7RSXSZ.js +140 -0
  24. package/dist/bin/chunks/{yq-T255J4ZP.js → yq-WS7WDP36.js} +1 -1
  25. package/dist/bin/just-bash.js +195 -194
  26. package/dist/bin/shell/chunks/awk2-OKD2P6CM.js +21 -0
  27. package/dist/bin/{chunks/chunk-VHH2M5JC.js → shell/chunks/chunk-CQZVMYQ3.js} +2 -2
  28. package/dist/bin/shell/chunks/chunk-G43H2WGH.js +17 -0
  29. package/dist/bin/shell/chunks/chunk-OBI37ZY4.js +9 -0
  30. package/dist/bin/{chunks/chunk-XI5LBYFX.js → shell/chunks/chunk-W2KVOOMM.js} +1 -1
  31. package/dist/bin/shell/chunks/{expansion-LVCGISX6.js → expansion-D4M4UY4T.js} +1 -1
  32. package/dist/bin/shell/chunks/{file-6PCTL3MH.js → file-MWSA2WYI.js} +12 -12
  33. package/dist/bin/shell/chunks/{grep-X7UU5FD6.js → grep-BD56656Z.js} +1 -1
  34. package/dist/bin/shell/chunks/help-L43ENI4H.js +16 -0
  35. package/dist/bin/{chunks/jq-QR3PX7FE.js → shell/chunks/jq-TJPN2INT.js} +1 -1
  36. package/dist/bin/shell/chunks/{md5sum-2VAAFCTS.js → md5sum-VHPDBIVV.js} +1 -1
  37. package/dist/bin/shell/chunks/{printf-XPBSFXJE.js → printf-4W7NDLLV.js} +1 -1
  38. package/dist/bin/{chunks/rg-RSJPHAP5.js → shell/chunks/rg-IZR5557M.js} +9 -9
  39. package/dist/bin/{chunks/sed-356P4DZB.js → shell/chunks/sed-E4QAUCYQ.js} +1 -1
  40. package/dist/bin/shell/chunks/{sha1sum-67P4ME4N.js → sha1sum-4SVNPPXZ.js} +1 -1
  41. package/dist/bin/{chunks/sha256sum-MV3WQ4QF.js → shell/chunks/sha256sum-BM3AFTIE.js} +1 -1
  42. package/dist/bin/shell/chunks/sort-QF3YLXRW.js +16 -0
  43. package/dist/bin/shell/chunks/{split-JJFZRWRC.js → split-7UP7EATZ.js} +1 -1
  44. package/dist/bin/{chunks/tr-FMT6JWLE.js → shell/chunks/tr-IAUNBQKH.js} +3 -3
  45. package/dist/bin/shell/chunks/xan-OR7RSXSZ.js +140 -0
  46. package/dist/bin/shell/chunks/{yq-T255J4ZP.js → yq-WS7WDP36.js} +1 -1
  47. package/dist/bin/shell/shell.js +194 -194
  48. package/dist/bundle/browser.js +420 -420
  49. package/dist/bundle/chunks/awk2-YNEKUV4T.js +20 -0
  50. package/dist/bundle/chunks/chunk-EIZGF4BS.js +8 -0
  51. package/dist/bundle/chunks/chunk-VLGZJRPG.js +16 -0
  52. package/dist/bundle/chunks/{chunk-GMMICOEF.js → chunk-ZRCBN2U4.js} +2 -2
  53. package/dist/bundle/chunks/{chunk-PHXIZ5A4.js → chunk-ZWYFK7P5.js} +1 -1
  54. package/dist/bundle/chunks/{expansion-OP223NMV.js → expansion-6T6M7TZI.js} +1 -1
  55. package/dist/bundle/chunks/{file-NQP3CKRV.js → file-APPTAFMI.js} +12 -12
  56. package/dist/bundle/chunks/{grep-F7ILPL2H.js → grep-UTH3KDWL.js} +1 -1
  57. package/dist/bundle/chunks/help-UD3E73G5.js +15 -0
  58. package/dist/bundle/chunks/{jq-RIXCOULU.js → jq-2LEQ2SZJ.js} +1 -1
  59. package/dist/bundle/chunks/{md5sum-KLHZSRUA.js → md5sum-TGZPGVOK.js} +1 -1
  60. package/dist/bundle/chunks/{printf-OAPYPRGV.js → printf-4U5V2VHK.js} +1 -1
  61. package/dist/bundle/chunks/{rg-O3ZIRBAJ.js → rg-JNKRPEYR.js} +9 -9
  62. package/dist/bundle/chunks/{sed-P5OTD3EL.js → sed-4K5HXNXE.js} +1 -1
  63. package/dist/bundle/chunks/{sha1sum-WKWTIZGQ.js → sha1sum-37LOTSQP.js} +1 -1
  64. package/dist/bundle/chunks/{sha256sum-IUVNMBTA.js → sha256sum-I4J5BPZA.js} +1 -1
  65. package/dist/bundle/chunks/sort-LT2PE47K.js +15 -0
  66. package/dist/bundle/chunks/{split-YBTFW7MT.js → split-LGSGJHV5.js} +1 -1
  67. package/dist/bundle/chunks/{tr-P43NRVKL.js → tr-UJSEBPIQ.js} +3 -3
  68. package/dist/bundle/chunks/xan-I4Y5DD3C.js +139 -0
  69. package/dist/bundle/chunks/{yq-6SPP5BHS.js → yq-6RVO6I5Q.js} +1 -1
  70. package/dist/bundle/index.js +197 -197
  71. package/dist/commands/awk/builtins.d.ts +1 -1
  72. package/dist/commands/registry.d.ts +15 -3
  73. package/dist/index.d.ts +2 -2
  74. package/package.json +3 -2
  75. package/dist/bin/chunks/awk2-TV3KCXON.js +0 -21
  76. package/dist/bin/chunks/chunk-GANRM5LO.js +0 -17
  77. package/dist/bin/chunks/chunk-Y5QKO4KO.js +0 -9
  78. package/dist/bin/chunks/help-7C5JICNL.js +0 -16
  79. package/dist/bin/chunks/sort-KUHOCH5S.js +0 -16
  80. package/dist/bin/chunks/xan-UZG3SZON.js +0 -140
  81. package/dist/bin/shell/chunks/awk2-TV3KCXON.js +0 -21
  82. package/dist/bin/shell/chunks/chunk-GANRM5LO.js +0 -17
  83. package/dist/bin/shell/chunks/chunk-Y5QKO4KO.js +0 -9
  84. package/dist/bin/shell/chunks/help-7C5JICNL.js +0 -16
  85. package/dist/bin/shell/chunks/sort-KUHOCH5S.js +0 -16
  86. package/dist/bin/shell/chunks/xan-UZG3SZON.js +0 -140
  87. package/dist/bundle/chunks/awk2-PTU7M2NS.js +0 -20
  88. package/dist/bundle/chunks/chunk-GFLIVSUW.js +0 -8
  89. package/dist/bundle/chunks/chunk-TMKMSBKB.js +0 -16
  90. package/dist/bundle/chunks/help-75YOGKM4.js +0 -15
  91. package/dist/bundle/chunks/sort-EJUT5LXD.js +0 -15
  92. package/dist/bundle/chunks/xan-HKCQ46BH.js +0 -139
@@ -1,140 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as F,b,c as M,d as Ue,e as w,f as v,g as G,h as X}from"./chunk-GZHFXDDO.js";import{a as Qe}from"./chunk-QSDVMMYI.js";import{a as $}from"./chunk-XI5LBYFX.js";import"./chunk-4PRVMER6.js";import"./chunk-K5IXNHO5.js";import{a as H}from"./chunk-SE4C7FJY.js";import{a as Ve}from"./chunk-5WFYIUU2.js";import"./chunk-OBH7XN5N.js";import{a as D,b as K}from"./chunk-GTNBSMZR.js";import{b as De,d as Ye,e as Be,f as Ze}from"./chunk-KGOUQS5A.js";var q,We=De(()=>{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos<this.input.length;){let n=this.input[this.pos];if(n===" "||n===" "||n===`
3
- `||n==="\r")this.pos++;else if(n==="#")for(;this.pos<this.input.length&&this.input[this.pos]!==`
4
- `;)this.pos++;else break}}nextToken(){let n=this.pos,t=this.input[this.pos];if(t>="0"&&t<="9")return this.readNumber();if(t==='"'||t==="'"||t==="`")return this.readString(t);if(t==="b"&&this.pos+1<this.input.length){let r=this.input[this.pos+1];if(r==='"'||r==="'"||r==="`")return this.pos++,this.readString(r)}if(t==="/"){let r=this.tokens[this.tokens.length-1];return r&&(r.type==="int"||r.type==="float"||r.type==="string"||r.type==="ident"||r.type===")"||r.type==="]")?this.input[this.pos+1]==="/"?(this.pos+=2,{type:"//",value:"//",pos:n}):(this.pos++,{type:"/",value:"/",pos:n}):this.readRegex()}if(this.match("not in"))return{type:"not in",value:"not in",pos:n};if(this.match("=>"))return{type:"=>",value:"=>",pos:n};if(this.match("**"))return{type:"**",value:"**",pos:n};if(this.match("++"))return{type:"++",value:"++",pos:n};if(this.match("//"))return{type:"//",value:"//",pos:n};if(this.match("=="))return{type:"==",value:"==",pos:n};if(this.match("!="))return{type:"!=",value:"!=",pos:n};if(this.match("<="))return{type:"<=",value:"<=",pos:n};if(this.match(">="))return{type:">=",value:">=",pos:n};if(this.match("&&"))return{type:"&&",value:"&&",pos:n};if(this.match("||"))return{type:"||",value:"||",pos:n};let s={"(":"(",")":")","[":"[","]":"]","{":"{","}":"}",",":",",":":":",";":";","+":"+","-":"-","*":"*","%":"%","<":"<",">":">","!":"!",".":".","|":"|","=":"="};if(t in s)return this.pos++,{type:s[t],value:t,pos:n};if(this.isIdentStart(t))return this.readIdentifier();throw new Error(`Unexpected character '${t}' at position ${this.pos}`)}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){if(/^[a-zA-Z]/.test(n)){let t=this.input[this.pos+n.length];if(t&&this.isIdentChar(t))return!1}return this.pos+=n.length,!0}return!1}isIdentStart(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}isIdentChar(n){return this.isIdentStart(n)||n>="0"&&n<="9"}readNumber(){let n=this.pos,t=!1,s=!1;for(;this.pos<this.input.length;){let o=this.input[this.pos];if(o>="0"&&o<="9")this.pos++;else if(o==="_")this.pos++;else if(o==="."&&!t&&!s)t=!0,this.pos++;else if((o==="e"||o==="E")&&!s)s=!0,t=!0,this.pos++,this.pos<this.input.length&&(this.input[this.pos]==="+"||this.input[this.pos]==="-")&&this.pos++;else break}let r=this.input.slice(n,this.pos).replace(/_/g,"");return{type:t?"float":"int",value:r,pos:n}}readString(n){let t=this.pos;this.pos++;let s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r===n)return this.pos++,{type:"string",value:s,pos:t};if(r==="\\"){if(this.pos++,this.pos<this.input.length){let o=this.input[this.pos];switch(o){case"n":s+=`
5
- `;break;case"r":s+="\r";break;case"t":s+=" ";break;case"\\":s+="\\";break;case'"':s+='"';break;case"'":s+="'";break;case"`":s+="`";break;case"0":s+="\0";break;default:s+=o}this.pos++}}else s+=r,this.pos++}throw new Error(`Unterminated string starting at position ${t}`)}readRegex(){let n=this.pos;this.pos++;let t="",s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r==="/"){for(this.pos++;this.pos<this.input.length&&this.input[this.pos]==="i";)s+=this.input[this.pos],this.pos++;return{type:"regex",value:t+(s?`/${s}`:""),pos:n}}r==="\\"?(t+=r,this.pos++,this.pos<this.input.length&&(t+=this.input[this.pos],this.pos++)):(t+=r,this.pos++)}throw new Error(`Unterminated regex starting at position ${n}`)}readIdentifier(){let n=this.pos;for(;this.pos<this.input.length&&this.isIdentChar(this.input[this.pos]);)this.pos++;let t=!1;this.pos<this.input.length&&this.input[this.pos]==="?"&&(t=!0,this.pos++);let s=this.input.slice(n,t?this.pos-1:this.pos);t&&(s+="?");let r={true:"true",false:"false",null:"null",and:"and",or:"or",eq:"eq",ne:"ne",lt:"lt",le:"le",gt:"gt",ge:"ge",in:"in",as:"as",_:"_"},o=s.replace(/\?$/,"");return o in r&&!t?{type:r[o],value:o,pos:n}:{type:"ident",value:s,pos:n}}}});var qe={};Ye(qe,{parseMoonblade:()=>_,parseNamedExpressions:()=>V});function V(e){let n=[],s=new q(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},a=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){a();continue}let h=[],u=0,p=r;for(;o().type!=="eof";){let i=o();if((i.type===","||i.type==="as")&&u===0)break;(i.type==="("||i.type==="["||i.type==="{")&&u++,(i.type===")"||i.type==="]"||i.type==="}")&&u--,h.push(a())}h.push({type:"eof",value:"",pos:0});let f=new J(h).parse(),c;if(o().type==="as")if(a(),o().type==="("){a();let i=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(i.push(o().value),a()),o().type===","&&a();o().type===")"&&a(),c=i}else if(o().type==="ident"||o().type==="string")c=o().value,a();else throw new Error(`Expected name after 'as', got ${o().type}`);else c=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),f.type==="identifier"&&(c=f.name);n.push({expr:f,name:c})}return n}function _(e){let t=new q(e).tokenize();return new J(t).parse()}var R,J,U=De(()=>{"use strict";We();R={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},J=class{pos=0;tokens;constructor(n){this.tokens=n}parse(){let n=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return n}parseExpr(n){let t=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r<n)break;t=this.parseInfix(t,r)}return t}parsePrefix(){let n=this.peek();switch(n.type){case"int":return this.advance(),{type:"int",value:Number.parseInt(n.value,10)};case"float":return this.advance(),{type:"float",value:Number.parseFloat(n.value)};case"string":return this.advance(),{type:"string",value:n.value};case"regex":{this.advance();let t=n.value.split("/"),s=t.length>1?t[t.length-1]:"";return{type:"regex",pattern:t.slice(0,-1).join("/")||n.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let t=n.value,s=t.endsWith("?"),r=s?t.slice(0,-1):t;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let t=[];if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=this.peek().value;if(this.advance(),this.peek().type===","||this.peek().type===")"){for(t.push(r);this.peek().type===","&&(this.advance(),this.peek().type==="ident");)t.push(this.peek().value),this.advance();if(this.peek().type===")"&&(this.advance(),this.peek().type==="=>")){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:t,body:o},t)}this.pos-=t.length*2,t.length>1&&(this.pos=this.pos)}this.pos--}let s=this.parseExpr(0);return this.expect(")"),this.peek().type,s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let t=this.parseExpr(R.UNARY);return t.type==="int"?{type:"int",value:-t.value}:t.type==="float"?{type:"float",value:-t.value}:{type:"func",name:"neg",args:[{expr:t}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(R.UNARY)}]};default:throw new Error(`Unexpected token: ${n.type} (${n.value})`)}}parseFunctionCall(n){this.expect("(");let t=[];if(this.peek().type!==")")do{t.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,a=this.pos+1;a<this.tokens.length&&this.tokens[a].type==="="&&(s=o,this.advance(),this.advance())}let r=this.parseExpr(0);t.push({name:s,expr:r})}while(this.peek().type===",");return this.expect(")"),{type:"func",name:n.toLowerCase(),args:t}}parseList(){this.expect("[");let n=[];if(this.peek().type!=="]")do n.length>0&&this.peek().type===","&&this.advance(),n.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:n}}parseMap(){this.expect("{");let n=[];if(this.peek().type!=="}")do{n.length>0&&this.peek().type===","&&this.advance();let t;if(this.peek().type==="ident")t=this.peek().value,this.advance();else if(this.peek().type==="string")t=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);n.push({key:t,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:n}}parseInfix(n,t){let s=this.peek(),r={"+":"add","-":"sub","*":"mul","/":"div","//":"idiv","%":"mod","**":"pow","++":"concat","==":"==","!=":"!=","<":"<","<=":"<=",">":">",">=":">=",eq:"eq",ne:"ne",lt:"lt",le:"le",gt:"gt",ge:"ge","&&":"and",and:"and","||":"or",or:"or"};if(s.type in r){this.advance();let o=this.parseExpr(t+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:r[s.type],args:[{expr:n},{expr:o}]}}if(s.type==="|"){this.advance();let o=this.parseExpr(t);return this.handlePipe(n,o)}if(s.type===".")return this.advance(),this.handleDot(n);if(s.type==="[")return this.advance(),this.handleIndexing(n);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(n,t){if(t.type==="identifier")return{type:"func",name:t.name,args:[{expr:n}]};if(t.type==="func"){let s=this.countUnderscores(t);return s===0?t:s===1?this.fillUnderscore(t,n):{type:"pipeline",exprs:[n,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,n):t}handleDot(n){let t=this.peek();if(t.type==="ident"){let s=t.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:n}),r}return{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}if(t.type==="int"){let s=Number.parseInt(t.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"int",value:s}}]}}if(t.type==="string"){let s=t.value;return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(n){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:{type:"int",value:0}},{expr:s}]}}let t=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n},{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:t},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:n},{expr:t}]}}countUnderscores(n){return n.type==="underscore"?1:n.type==="func"?n.args.reduce((t,s)=>t+this.countUnderscores(s.expr),0):n.type==="list"?n.elements.reduce((t,s)=>t+this.countUnderscores(s),0):n.type==="map"?n.entries.reduce((t,s)=>t+this.countUnderscores(s.value),0):0}fillUnderscore(n,t){return n.type==="underscore"?t:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.fillUnderscore(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.fillUnderscore(s.value,t)}))}:n}bindLambdaArgs(n,t){return{...n,body:this.bindLambdaArgsInExpr(n.body,t)}}bindLambdaArgsInExpr(n,t){return n.type==="identifier"&&t.includes(n.name)?{type:"lambdaBinding",name:n.name}:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.bindLambdaArgsInExpr(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,t)}))}:n}getInfixPrec(n){switch(n){case"|":return R.PIPE;case"||":case"or":return R.OR;case"&&":case"and":return R.AND;case"==":case"!=":case"eq":case"ne":return R.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return R.COMPARISON;case"+":case"-":case"++":return R.ADDITIVE;case"*":case"/":case"//":case"%":return R.MULTIPLICATIVE;case"**":return R.POWER;case".":case"[":return R.POSTFIX;default:return-1}}isRightAssoc(n){return n==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}advance(){return this.tokens[this.pos++]}expect(n){let t=this.peek();if(t.type!==n)throw new Error(`Expected ${n}, got ${t.type}`);return this.advance()}}});U();function E(e,n){return n.length===0?k(e,[]):n.length===1?{type:"Pipe",left:n[0],right:k(e,[])}:{type:"Pipe",left:n[0],right:k(e,n.slice(1))}}var He={add:e=>S("+",e[0],e[1]),sub:e=>S("-",e[0],e[1]),mul:e=>S("*",e[0],e[1]),div:e=>S("/",e[0],e[1]),mod:e=>S("%",e[0],e[1]),idiv:e=>k("floor",[S("/",e[0],e[1])]),pow:e=>E("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>S("==",e[0],e[1]),"!=":e=>S("!=",e[0],e[1]),"<":e=>S("<",e[0],e[1]),"<=":e=>S("<=",e[0],e[1]),">":e=>S(">",e[0],e[1]),">=":e=>S(">=",e[0],e[1]),eq:e=>S("==",P(e[0]),P(e[1])),ne:e=>S("!=",P(e[0]),P(e[1])),lt:e=>S("<",P(e[0]),P(e[1])),le:e=>S("<=",P(e[0]),P(e[1])),gt:e=>S(">",P(e[0]),P(e[1])),ge:e=>S(">=",P(e[0]),P(e[1])),and:e=>S("and",e[0],e[1]),or:e=>S("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>E("length",e),length:e=>E("length",e),upper:e=>E("ascii_upcase",e),lower:e=>E("ascii_downcase",e),trim:e=>E("trim",e),ltrim:e=>e.length===0?k("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?k("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("rtrimstr",[{type:"Literal",value:" "}])},split:e=>E("split",e),join:e=>e.length===1?k("join",[{type:"Literal",value:""}]):E("join",e),concat:e=>S("+",e[0],e[1]),startswith:e=>E("startswith",e),endswith:e=>E("endswith",e),contains:e=>E("contains",e),replace:e=>E("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:S("+",e[1],e[2])},abs:e=>E("fabs",e),floor:e=>E("floor",e),ceil:e=>E("ceil",e),round:e=>E("round",e),sqrt:e=>E("sqrt",e),log:e=>E("log",e),log10:e=>E("log10",e),log2:e=>E("log2",e),exp:e=>E("exp",e),sin:e=>E("sin",e),cos:e=>E("cos",e),tan:e=>E("tan",e),asin:e=>E("asin",e),acos:e=>E("acos",e),atan:e=>E("atan",e),min:e=>E("min",e),max:e=>E("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>k("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>k("select",e),empty:()=>k("empty",[]),count:()=>k("length",[]),sum:e=>e.length===0?k("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:k("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},type:"type",isnull:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:null}):S("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:""}):S("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?k("tonumber",[]):k("tonumber",e),tostring:e=>e.length===0?k("tostring",[]):k("tostring",e),if:e=>_e(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let[n,...t]=e,s=S("and",S("!=",n,{type:"Literal",value:null}),S("!=",n,{type:"Literal",value:""}));return _e(s,n,t.length===1?t[0]:He.coalesce(t))},index:()=>({type:"Field",name:"_row_index"}),now:()=>k("now",[]),fmt:e=>k("tostring",e),format:e=>k("tostring",e)};function S(e,n,t){return{type:"BinaryOp",op:e,left:n,right:t}}function k(e,n){return{type:"Call",name:e,args:n}}var et="then";function _e(e,n,t){let s={type:"Cond",cond:e,elifs:[],else:t||{type:"Literal",value:null}};return s[et]=n,s}function P(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function L(e,n=!0){switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return n?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{let t=e.args.map(r=>L(r.expr,n)),s=He[e.name];return typeof s=="function"?s(t):k(typeof s=="string"?s:e.name,t)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((t,s,r)=>{let o=L(s,n);return r===0?o:{type:"Comma",left:t,right:o}},null)};case"map":return{type:"Object",entries:e.entries.map(t=>({key:t.key,value:L(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?L(e.start,n):void 0,end:e.end?L(e.end,n):void 0};case"lambda":return L(e.body,n);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function B(e){let n=[],t=0;for(;t<e.length;){for(;t<e.length&&(e[t]===" "||e[t]===",");)t++;if(t>=e.length)break;let s=t;for(;t<e.length&&/\w/.test(e[t]);)t++;let r=e.slice(s,t);for(;t<e.length&&e[t]===" ";)t++;if(e[t]!=="(")break;t++;let o=1,a=t;for(;t<e.length&&o>0;)e[t]==="("?o++:e[t]===")"&&o--,o>0&&t++;let h=e.slice(a,t).trim();for(t++;t<e.length&&e[t]===" ";)t++;let u="";if(e.slice(t,t+3).toLowerCase()==="as "){for(t+=3;t<e.length&&e[t]===" ";)t++;let p=t;for(;t<e.length&&/\w/.test(e[t]);)t++;u=e.slice(p,t)}u||(u=h?`${r}(${h})`:`${r}()`),n.push({func:r,expr:h,alias:u})}return n}function Je(e){return/^\w+$/.test(e)}function Y(e,n,t){let s=L(_(n)),r=$(e,s,t);return r.length>0?r[0]:null}function Z(e,n,t={}){let{func:s,expr:r}=n;if(s==="count"&&!r)return e.length;let o;switch(Je(r)?o=e.map(a=>a[r]).filter(a=>a!=null):o=e.map(a=>Y(a,r,t)).filter(a=>a!=null),s){case"count":return Je(r)?o.length:o.filter(a=>!!a).length;case"sum":return o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h))).reduce((h,u)=>h+u,0);case"mean":case"avg":{let a=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return a.length>0?a.reduce((h,u)=>h+u,0)/a.length:0}case"min":{let a=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return a.length>0?Math.min(...a):null}case"max":{let a=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return a.length>0?Math.max(...a):null}case"first":return o.length>0?o[0]:null;case"last":return o.length>0?o[o.length-1]:null;case"median":{let a=o.map(u=>typeof u=="number"?u:Number.parseFloat(String(u))).filter(u=>!Number.isNaN(u)).sort((u,p)=>u-p);if(a.length===0)return null;let h=Math.floor(a.length/2);return a.length%2===0?(a[h-1]+a[h])/2:a[h]}case"mode":{let a=new Map;for(let p of o){let l=String(p);a.set(l,(a.get(l)||0)+1)}let h=0,u=null;for(let[p,l]of a)l>h&&(h=l,u=p);return u}case"cardinality":return new Set(o.map(h=>String(h))).size;case"values":return o.map(a=>String(a)).join("|");case"distinct_values":return[...new Set(o.map(h=>String(h)))].sort().join("|");case"all":{if(e.length===0)return!0;for(let a of e)if(!Y(a,r,t))return!1;return!0}case"any":{for(let a of e)if(Y(a,r,t))return!0;return!1}default:return null}}function ze(e,n,t={}){let s=F();for(let r of n)b(s,r.alias,Z(e,r,t));return s}async function Q(e,n){let t="",s=[];for(let l of e)l.startsWith("-")||(t?s.push(l):t=l);if(!t)return{stdout:"",stderr:`xan agg: no aggregation expression
6
- `,exitCode:1};let{data:r,error:o}=await v(s,n);if(o)return o;let a={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},h=B(t),u=h.map(l=>l.alias),p=ze(r,h,a);return{stdout:w(u,[p]),stderr:"",exitCode:0}}async function ee(e,n){let t="",s="",r=[];for(let d=0;d<e.length;d++){let m=e[d];m==="--sorted"||m.startsWith("-")||(t?s?r.push(m):s=m:t=m)}if(!t||!s)return{stdout:"",stderr:`xan groupby: usage: xan groupby COLS EXPR [FILE]
7
- `,exitCode:1};let{data:o,error:a}=await v(r,n);if(a)return a;let h={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},u=t.split(","),p=B(s),l=[],f=new Map;for(let d of o){let m=u.map(g=>String(d[g])).join("\0");f.has(m)||(f.set(m,[]),l.push(m)),f.get(m)?.push(d)}let c=[...u,...p.map(d=>d.alias)],i=[];for(let d of l){let m=f.get(d);if(!m)continue;let g=F();for(let y of u)b(g,y,m[0][y]);for(let y of p)b(g,y.alias,Z(m,y,h));i.push(g)}return{stdout:w(c,i),stderr:"",exitCode:0}}async function te(e,n){let t=[],s="",r=10,o=!1,a=[];for(let i=0;i<e.length;i++){let d=e[i];(d==="-s"||d==="--select")&&i+1<e.length?t=e[++i].split(","):(d==="-g"||d==="--groupby")&&i+1<e.length?s=e[++i]:(d==="-l"||d==="--limit")&&i+1<e.length?r=Number.parseInt(e[++i],10):d==="--no-extra"?o=!0:d==="-A"||d==="--all"?r=0:d.startsWith("-")||a.push(d)}let{headers:h,data:u,error:p}=await v(a,n);if(p)return p;let l=t.length>0?t:h.filter(i=>i!==s);s&&t.length===0&&(l=h.filter(i=>i!==s));let f=[],c=s?["field",s,"value","count"]:["field","value","count"];if(s){let i=new Map;for(let d of u){let m=String(d[s]??"");i.has(m)||i.set(m,[]),i.get(m)?.push(d)}for(let d of l)for(let[m,g]of i){let y=new Map;for(let I of g){let N=I[d],C=N===""||N===null||N===void 0?"":String(N);y.set(C,(y.get(C)||0)+1)}let x=[...y.entries()].sort((I,N)=>N[1]!==I[1]?N[1]-I[1]:I[0].localeCompare(N[0]));o&&(x=x.filter(([I])=>I!=="")),r>0&&(x=x.slice(0,r));for(let[I,N]of x)f.push({field:d,[s]:m,value:I===""?"<empty>":I,count:N})}}else for(let i of l){let d=new Map;for(let g of u){let y=g[i],x=y===""||y===null||y===void 0?"":String(y);d.set(x,(d.get(x)||0)+1)}let m=[...d.entries()].sort((g,y)=>y[1]!==g[1]?y[1]-g[1]:g[0].localeCompare(y[0]));o&&(m=m.filter(([g])=>g!=="")),r>0&&(m=m.slice(0,r));for(let[g,y]of m)f.push({field:i,value:g===""?"<empty>":g,count:y})}return{stdout:w(c,f),stderr:"",exitCode:0}}async function ne(e,n){let t=[],s=[];for(let l=0;l<e.length;l++){let f=e[l];f==="-s"&&l+1<e.length?t=e[++l].split(","):f.startsWith("-")||s.push(f)}let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=t.length>0?t:r,u=["field","type","count","min","max","mean"],p=[];for(let l of h){let f=o.map(d=>d[l]).filter(d=>d!=null),c=f.map(d=>typeof d=="number"?d:Number.parseFloat(String(d))).filter(d=>!Number.isNaN(d)),i=c.length===f.length&&c.length>0;p.push({field:l,type:i?"Number":"String",count:f.length,min:i?Math.min(...c):"",max:i?Math.max(...c):"",mean:i?Math.round(c.reduce((d,m)=>d+m,0)/c.length*1e10)/1e10:""})}return{stdout:w(u,p),stderr:"",exitCode:0}}U();function Ke(e){let n=_(e);return L(n)}function tt(e){let t=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return H(`^${t}$`)}function z(e,n){let t=[],s=new Set;for(let r of e.split(",")){let o=r.trim();if(o.startsWith("!")){let p=o.slice(1),l=z(p,n);for(let f of l)s.add(f);continue}if(o==="*"){for(let p of n)t.includes(p)||t.push(p);continue}if(o.includes("*")){let p=tt(o);for(let l of n)p.test(l)&&!t.includes(l)&&t.push(l);continue}let a=o.match(/^([^:]*):([^:]*)$/);if(a&&(a[1]||a[2])){let p=a[1],l=a[2],f=p?n.indexOf(p):0,c=l?n.indexOf(l):n.length-1;if(f!==-1&&c!==-1){let i=f<=c?1:-1;for(let d=f;i>0?d<=c:d>=c;d+=i)t.includes(n[d])||t.push(n[d])}continue}let h=o.match(/^(\d+)-(\d+)$/);if(h){let p=Number.parseInt(h[1],10),l=Number.parseInt(h[2],10);for(let f=p;f<=l&&f<n.length;f++)t.push(n[f]);continue}let u=Number.parseInt(o,10);if(!Number.isNaN(u)&&u>=0&&u<n.length){t.push(n[u]);continue}n.includes(o)&&t.push(o)}return s.size>0?t.filter(r=>!s.has(r)):t}async function se(e,n){let t="",s=[];for(let p of e)p.startsWith("-")||(t?s.push(p):t=p);if(!t)return{stdout:"",stderr:`xan select: no columns specified
8
- `,exitCode:1};let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=z(t,r),u=o.map(p=>{let l=F();for(let f of h)b(l,f,p[f]);return l});return{stdout:w(h,u),stderr:"",exitCode:0}}async function re(e,n){let t="",s=[];for(let l of e)l.startsWith("-")||(t?s.push(l):t=l);if(!t)return{stdout:"",stderr:`xan drop: no columns specified
9
- `,exitCode:1};let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=new Set(z(t,r)),u=r.filter(l=>!h.has(l)),p=o.map(l=>{let f=F();for(let c of u)b(f,c,l[c]);return f});return{stdout:w(u,p),stderr:"",exitCode:0}}async function oe(e,n){let t="",s="",r=[];for(let l=0;l<e.length;l++){let f=e[l];f==="-s"&&l+1<e.length?s=e[++l]:f.startsWith("-")||(t?r.push(f):t=f)}if(!t)return{stdout:"",stderr:`xan rename: no new name(s) specified
10
- `,exitCode:1};let{headers:o,data:a,error:h}=await v(r,n);if(h)return h;let u;if(s){let l=s.split(","),f=t.split(","),c=new Map;for(let i=0;i<l.length&&i<f.length;i++)c.set(l[i],f[i]);u=o.map(i=>c.get(i)||i)}else{let l=t.split(",");u=o.map((f,c)=>c<l.length?l[c]:f)}let p=a.map(l=>{let f=F();for(let c=0;c<o.length;c++)b(f,u[c],l[o[c]]);return f});return{stdout:w(u,p),stderr:"",exitCode:0}}async function ie(e,n){let t="index",s=[];for(let p=0;p<e.length;p++)e[p]==="-c"&&p+1<e.length?t=e[++p]:s.push(e[p]);let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=[t,...r],u=o.map((p,l)=>{let f=F();b(f,t,l);for(let c of r)b(f,c,p[c]);return f});return{stdout:w(h,u),stderr:"",exitCode:0}}async function ae(e,n){let t=e.includes("-j")||e.includes("--just-names"),{headers:s,error:r}=await v(e.filter(a=>a!=="-j"&&a!=="--just-names"),n);return r||{stdout:t?`${s.map(a=>a).join(`
11
- `)}
12
- `:`${s.map((a,h)=>`${h} ${a}`).join(`
13
- `)}
14
- `,stderr:"",exitCode:0}}async function le(e,n){let{data:t,error:s}=await v(e,n);return s||{stdout:`${t.length}
15
- `,stderr:"",exitCode:0}}async function ue(e,n){let t=10,s=[];for(let u=0;u<e.length;u++)(e[u]==="-l"||e[u]==="-n")&&u+1<e.length?t=Number.parseInt(e[++u],10):s.push(e[u]);let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=o.slice(0,t);return{stdout:w(r,h),stderr:"",exitCode:0}}async function ce(e,n){let t=10,s=[];for(let u=0;u<e.length;u++)(e[u]==="-l"||e[u]==="-n")&&u+1<e.length?t=Number.parseInt(e[++u],10):s.push(e[u]);let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=o.slice(-t);return{stdout:w(r,h),stderr:"",exitCode:0}}async function pe(e,n){let t,s,r,o=[];for(let c=0;c<e.length;c++){let i=e[c];(i==="-s"||i==="--start")&&c+1<e.length?t=Number.parseInt(e[++c],10):(i==="-e"||i==="--end")&&c+1<e.length?s=Number.parseInt(e[++c],10):(i==="-l"||i==="--len")&&c+1<e.length?r=Number.parseInt(e[++c],10):i.startsWith("-")||o.push(i)}let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;let p=t??0,l;r!==void 0?l=p+r:s!==void 0?l=s:l=h.length;let f=h.slice(p,l);return{stdout:w(a,f),stderr:"",exitCode:0}}async function fe(e,n){let{headers:t,data:s,error:r}=await v(e,n);if(r)return r;let o=[...s].reverse();return{stdout:w(t,o),stderr:"",exitCode:0}}var de=Be(Qe(),1);async function he(e,n){let t=e.filter(p=>!p.startsWith("-")),{headers:s,data:r,error:o}=await v(t,n);if(o)return o;if(r.length===0){let p=["column"],l=s.map(f=>({column:f}));return{stdout:w(p,l),stderr:"",exitCode:0}}let a=s[0],h=[a,...r.map((p,l)=>String(p[a]??`row_${l}`))],u=[];for(let p=1;p<s.length;p++){let l=s[p],f=F();b(f,a,l);for(let c=0;c<r.length;c++)b(f,h[c+1],r[c][l]);u.push(f)}return{stdout:w(h,u),stderr:"",exitCode:0}}async function me(e,n){let t=null,s=[];for(let l=0;l<e.length;l++){let f=e[l];f==="--seed"&&l+1<e.length?t=Number.parseInt(e[++l],10):f.startsWith("-")||s.push(f)}let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=t!==null?t:Date.now(),u=()=>(h=h*1103515245+12345&2147483647,h/2147483647),p=[...o];for(let l=p.length-1;l>0;l--){let f=Math.floor(u()*(l+1));[p[l],p[f]]=[p[f],p[l]]}return{stdout:w(r,p),stderr:"",exitCode:0}}async function ge(e,n){let t=null,s="",r=[];for(let i=0;i<e.length;i++){let d=e[i];(d==="-l"||d==="--length")&&i+1<e.length?t=Number.parseInt(e[++i],10):(d==="-d"||d==="--default")&&i+1<e.length?s=e[++i]:d.startsWith("-")||r.push(d)}let o=r[0],a;if(!o||o==="-")a=n.stdin;else try{let i=n.fs.resolvePath(n.cwd,o);a=await n.fs.readFile(i)}catch{return{stdout:"",stderr:`xan fixlengths: ${o}: No such file or directory
16
- `,exitCode:1}}let u=de.default.parse(a.trim(),{header:!1,skipEmptyLines:!0}).data;if(u.length===0)return{stdout:"",stderr:"",exitCode:0};let p=Math.max(...u.map(i=>i.length)),l=t??p,f=u.map(i=>i.length===l?i:i.length<l?[...i,...Array(l-i.length).fill(s)]:i.slice(0,l));return{stdout:`${de.default.unparse(f).replace(/\r\n/g,`
17
- `)}
18
- `,stderr:"",exitCode:0}}async function ye(e,n){let t=null,s=null,r=".",o=[];for(let c=0;c<e.length;c++){let i=e[c];(i==="-c"||i==="--chunks")&&c+1<e.length?t=Number.parseInt(e[++c],10):(i==="-S"||i==="--size")&&c+1<e.length?s=Number.parseInt(e[++c],10):(i==="-o"||i==="--output")&&c+1<e.length?r=e[++c]:i.startsWith("-")||o.push(i)}if(!t&&!s)return{stdout:"",stderr:`xan split: must specify -c or -S
19
- `,exitCode:1};let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;let p=[];if(t){let c=Math.ceil(h.length/t);for(let i=0;i<t;i++)p.push(h.slice(i*c,(i+1)*c))}else if(s)for(let c=0;c<h.length;c+=s)p.push(h.slice(c,c+s));let l=p.filter(c=>c.length>0),f=o[0]?.replace(/\.csv$/,"")||"part";try{let c=n.fs.resolvePath(n.cwd,r);for(let i=0;i<l.length;i++){let d=`${f}_${String(i+1).padStart(3,"0")}.csv`,m=n.fs.resolvePath(c,d);await n.fs.writeFile(m,w(a,l[i]))}return{stdout:`Split into ${l.length} parts
20
- `,stderr:"",exitCode:0}}catch{return{stdout:`${l.map((i,d)=>`Part ${d+1}: ${i.length} rows`).join(`
21
- `)}
22
- `,stderr:"",exitCode:0}}}async function xe(e,n){let t="",s=".",r=[];for(let p=0;p<e.length;p++){let l=e[p];(l==="-o"||l==="--output")&&p+1<e.length?s=e[++p]:l.startsWith("-")||(t?r.push(l):t=l)}if(!t)return{stdout:"",stderr:`xan partition: usage: xan partition COLUMN [FILE]
23
- `,exitCode:1};let{headers:o,data:a,error:h}=await v(r,n);if(h)return h;if(!o.includes(t))return{stdout:"",stderr:`xan partition: column '${t}' not found
24
- `,exitCode:1};let u=new Map;for(let p of a){let l=String(p[t]??"");u.has(l)||u.set(l,[]),u.get(l)?.push(p)}try{let p=n.fs.resolvePath(n.cwd,s);for(let[l,f]of u){let i=`${l.replace(/[^a-zA-Z0-9_-]/g,"_")||"empty"}.csv`,d=n.fs.resolvePath(p,i);await n.fs.writeFile(d,w(o,f))}return{stdout:`Partitioned into ${u.size} files by '${t}'
25
- `,stderr:"",exitCode:0}}catch{return{stdout:`${Array.from(u.entries()).map(([l,f])=>`${l}: ${f.length} rows`).join(`
26
- `)}
27
- `,stderr:"",exitCode:0}}}async function we(e,n){if(e.length===0)return{stdout:"",stderr:`xan to: usage: xan to <format> [FILE]
28
- `,exitCode:1};let t=e[0],s=e.slice(1);return t==="json"?nt(s,n):{stdout:"",stderr:`xan to: unsupported format '${t}'
29
- `,exitCode:1}}async function nt(e,n){let t=e.filter(a=>!a.startsWith("-")),{data:s,error:r}=await v(t,n);return r||{stdout:`${JSON.stringify(s,null,2)}
30
- `,stderr:"",exitCode:0}}async function ve(e,n){let t="",s=[];for(let r=0;r<e.length;r++){let o=e[r];(o==="-f"||o==="--format")&&r+1<e.length?t=e[++r]:o.startsWith("-")||s.push(o)}return t?t==="json"?st(s,n):{stdout:"",stderr:`xan from: unsupported format '${t}'
31
- `,exitCode:1}:{stdout:"",stderr:`xan from: usage: xan from -f <format> [FILE]
32
- `,exitCode:1}}async function st(e,n){let t=e[0],s;if(!t||t==="-")s=n.stdin;else try{let r=n.fs.resolvePath(n.cwd,t);s=await n.fs.readFile(r)}catch{return{stdout:"",stderr:`xan from: ${t}: No such file or directory
33
- `,exitCode:1}}try{let r=JSON.parse(s.trim());if(!Array.isArray(r))return{stdout:"",stderr:`xan from: JSON input must be an array
34
- `,exitCode:1};if(r.length===0)return{stdout:`
35
- `,stderr:"",exitCode:0};if(Array.isArray(r[0])){let[a,...h]=r,u=h.map(p=>{let l=F();for(let f=0;f<a.length;f++)b(l,a[f],p[f]);return l});return{stdout:w(a,u),stderr:"",exitCode:0}}let o=Object.keys(r[0]).sort();return{stdout:w(o,r),stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`xan from: invalid JSON input
36
- `,exitCode:1}}}async function Ce(e,n){let t=!1,s=0,r="",o=[];for(let c=0;c<e.length;c++){let i=e[c];if(i==="-v"||i==="--invert")t=!0;else if((i==="-l"||i==="--limit")&&c+1<e.length)s=Number.parseInt(e[++c],10);else{if(i==="--help")return D({name:"xan filter",summary:"Filter rows by expression",usage:"xan filter [OPTIONS] EXPR [FILE]",description:"Filter CSV rows using moonblade expressions.",options:["-v, --invert invert match","-l, --limit N limit output to N rows"," --help display help"]});i.startsWith("-")||(r?o.push(i):r=i)}}if(!r)return{stdout:"",stderr:`xan filter: no expression specified
37
- `,exitCode:1};let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;let p={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},l=Ke(r),f=[];for(let c of h){if(s>0&&f.length>=s)break;let i=$(c,l,p),d=i.length>0&&i.some(m=>!!m);(t?!d:d)&&f.push(c)}return{stdout:w(a,f),stderr:"",exitCode:0}}async function be(e,n){let t="",s=!1,r=!1,o=[];for(let l=0;l<e.length;l++){let f=e[l];f==="-N"||f==="--numeric"?s=!0:f==="-R"||f==="-r"||f==="--reverse"?r=!0:f==="-s"&&l+1<e.length?t=e[++l]:f.startsWith("-")||o.push(f)}let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;!t&&a.length>0&&(t=a[0]);let p=[...h].sort((l,f)=>{let c=l[t],i=f[t],d;if(s){let m=typeof c=="number"?c:Number.parseFloat(String(c)),g=typeof i=="number"?i:Number.parseFloat(String(i));d=m-g}else d=String(c).localeCompare(String(i));return r?-d:d});return{stdout:w(a,p),stderr:"",exitCode:0}}async function Se(e,n){let t="",s=[];for(let p=0;p<e.length;p++){let l=e[p];l==="-s"&&p+1<e.length?t=e[++p]:l.startsWith("-")||s.push(l)}let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let h=new Set,u=o.filter(p=>{let l=t?String(p[t]):JSON.stringify(p);return h.has(l)?!1:(h.add(l),!0)});return{stdout:w(r,u),stderr:"",exitCode:0}}async function Ie(e,n){let t=10,s="",r=!1,o=[];for(let f=0;f<e.length;f++){let c=e[f];(c==="-l"||c==="-n")&&f+1<e.length?t=Number.parseInt(e[++f],10):c==="-R"||c==="-r"||c==="--reverse"?r=!0:c.startsWith("-")||(s?o.push(c):s=c)}let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;!s&&a.length>0&&(s=a[0]);let l=[...h].sort((f,c)=>{let i=f[s],d=c[s],m=typeof i=="number"?i:Number.parseFloat(String(i)),g=typeof d=="number"?d:Number.parseFloat(String(d));return r?m-g:g-m}).slice(0,t);return{stdout:w(a,l),stderr:"",exitCode:0}}U();async function ke(e,n){let t="",s=!1,r=!1,o=[];for(let d=0;d<e.length;d++){let m=e[d];m==="-O"||m==="--overwrite"?s=!0:m==="--filter"?r=!0:m.startsWith("-")||(t?o.push(m):t=m)}if(!t)return{stdout:"",stderr:`xan map: no expression specified
38
- `,exitCode:1};let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;let l=V(t).map(({expr:d,name:m})=>({alias:typeof m=="string"?m:m[0],ast:L(d)})),f={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},c;if(s){c=[...a];for(let d of l)a.includes(d.alias)||c.push(d.alias)}else c=[...a,...l.map(d=>d.alias)];let i=[];for(let d=0;d<h.length;d++){let m=h[d],g=M(m),y=!1,x={...m,_row_index:d};for(let I of l){let N=$(x,I.ast,f),C=N.length>0?N[0]:null;if(r&&C==null){y=!0;break}b(g,I.alias,C)}y||i.push(g)}return{stdout:w(c,i),stderr:"",exitCode:0}}async function Ne(e,n){let t="",s="",r="",o=[];for(let m=0;m<e.length;m++){let g=e[m];(g==="-r"||g==="--rename")&&m+1<e.length?r=e[++m]:g.startsWith("-")||(t?s?o.push(g):s=g:t=g)}if(!t||!s)return{stdout:"",stderr:`xan transform: usage: xan transform COLUMN EXPR [FILE]
39
- `,exitCode:1};let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;let p=t.split(",").map(m=>m.trim()),l=r?r.split(",").map(m=>m.trim()):[];for(let m of p)if(!a.includes(m))return{stdout:"",stderr:`xan transform: column '${m}' not found
40
- `,exitCode:1};let f=L(V(s)[0]?.expr||(U(),Ze(qe)).parseMoonblade(s)),c={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},i=a.map(m=>{let g=p.indexOf(m);return g!==-1&&l[g]?l[g]:m}),d=[];for(let m of h){let g=M(m);for(let y=0;y<p.length;y++){let x=p[y],I={...m,_:m[x]},N=$(I,f,c),C=N.length>0?N[0]:null,A=l[y]||x;A!==x&&delete g[x],b(g,A,C)}d.push(g)}return{stdout:w(i,d),stderr:"",exitCode:0}}async function Ee(e,n){let t="",s="|",r=!1,o="",a=[];for(let i=0;i<e.length;i++){let d=e[i];(d==="-s"||d==="--separator")&&i+1<e.length?s=e[++i]:d==="--drop-empty"?r=!0:(d==="-r"||d==="--rename")&&i+1<e.length?o=e[++i]:d.startsWith("-")||(t?a.push(d):t=d)}if(!t)return{stdout:"",stderr:`xan explode: usage: xan explode COLUMN [FILE]
41
- `,exitCode:1};let{headers:h,data:u,error:p}=await v(a,n);if(p)return p;if(!h.includes(t))return{stdout:"",stderr:`xan explode: column '${t}' not found
42
- `,exitCode:1};let l=o?h.map(i=>i===t?o:i):h,f=o||t,c=[];for(let i of u){let d=i[t],m=d==null?"":String(d);if(m===""){if(!r){let g=M(i);o&&(delete g[t],b(g,f,"")),c.push(g)}}else{let g=m.split(s);for(let y of g){let x=M(i);o&&delete x[t],b(x,f,y),c.push(x)}}}return{stdout:w(l,c),stderr:"",exitCode:0}}async function Ae(e,n){let t="",s="|",r="",o=[];for(let g=0;g<e.length;g++){let y=e[g];(y==="-s"||y==="--sep")&&g+1<e.length?s=e[++g]:(y==="-r"||y==="--rename")&&g+1<e.length?r=e[++g]:y.startsWith("-")||(t?o.push(y):t=y)}if(!t)return{stdout:"",stderr:`xan implode: usage: xan implode COLUMN [FILE]
43
- `,exitCode:1};let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;if(!a.includes(t))return{stdout:"",stderr:`xan implode: column '${t}' not found
44
- `,exitCode:1};let p=a.filter(g=>g!==t),l=r?a.map(g=>g===t?r:g):a,f=r||t,c=[],i=null,d=[],m=null;for(let g of h){let y=p.map(N=>String(g[N]??"")).join("\0"),x=g[t],I=x==null?"":String(x);if(y!==i){if(m!==null){let N=M(m);r&&delete N[t],b(N,f,d.join(s)),c.push(N)}i=y,d=[I],m=g}else d.push(I)}if(m!==null){let g=M(m);r&&delete g[t],b(g,f,d.join(s)),c.push(g)}return{stdout:w(l,c),stderr:"",exitCode:0}}async function Fe(e,n){let t="",s="",r="",o="",a="inner",h="",u=0;for(let C=0;C<e.length;C++){let A=e[C];A==="--left"?a="left":A==="--right"?a="right":A==="--full"?a="full":(A==="-D"||A==="--default")&&C+1<e.length?h=e[++C]:A.startsWith("-")||(u++,u===1?t=A:u===2?s=A:u===3?r=A:u===4&&(o=A))}if(!t||!s||!r||!o)return{stdout:"",stderr:`xan join: usage: xan join KEY1 FILE1 KEY2 FILE2 [OPTIONS]
45
- `,exitCode:1};let p=await v([s],n);if(p.error)return p.error;let l=await v([o],n);if(l.error)return l.error;let{headers:f,data:c}=p,{headers:i,data:d}=l;if(!f.includes(t))return{stdout:"",stderr:`xan join: column '${t}' not found in first file
46
- `,exitCode:1};if(!i.includes(r))return{stdout:"",stderr:`xan join: column '${r}' not found in second file
47
- `,exitCode:1};let m=new Map;for(let C of d){let A=String(C[r]??"");m.has(A)||m.set(A,[]),m.get(A)?.push(C)}let g=new Set(f),y=i.filter(C=>!g.has(C)),x=[...f,...y],I=[],N=new Set;for(let C of c){let A=String(C[t]??""),j=m.get(A);if(j&&j.length>0){N.add(A);for(let O of j){let T=F();for(let W of f)b(T,W,C[W]);for(let W of y)b(T,W,O[W]);I.push(T)}}else if(a==="left"||a==="full"){let O=F();for(let T of f)b(O,T,C[T]);for(let T of y)b(O,T,h);I.push(O)}}if(a==="right"||a==="full")for(let C of d){let A=String(C[r]??"");if(!N.has(A)){let j=F();for(let O of f)b(j,O,i.includes(O)?C[O]:h);for(let O of y)b(j,O,C[O]);I.push(j)}}return{stdout:w(x,I),stderr:"",exitCode:0}}async function Le(e,n){let t="",s="",r=[],o=[];for(let y=0;y<e.length;y++){let x=e[y];(x==="-g"||x==="--groupby")&&y+1<e.length?r=e[++y].split(",").map(I=>I.trim()):x.startsWith("-")||(t?s?o.push(x):s=x:t=x)}if(!t||!s)return{stdout:"",stderr:`xan pivot: usage: xan pivot COLUMN AGG_EXPR [OPTIONS] [FILE]
48
- `,exitCode:1};let{headers:a,data:h,error:u}=await v(o,n);if(u)return u;if(!a.includes(t))return{stdout:"",stderr:`xan pivot: column '${t}' not found
49
- `,exitCode:1};let p=s.match(/^(\w+)\((\w+)\)$/);if(!p)return{stdout:"",stderr:`xan pivot: invalid aggregation expression '${s}'
50
- `,exitCode:1};let[,l,f]=p;r.length===0&&(r=a.filter(y=>y!==t&&y!==f));let c=[];for(let y of h){let x=String(y[t]??"");c.includes(x)||c.push(x)}let i=new Map,d=[];for(let y of h){let x=r.map(A=>String(y[A]??"")).join("\0"),I=String(y[t]??""),N=y[f];i.has(x)||(i.set(x,new Map),d.push(x));let C=i.get(x);C&&(C.has(I)||C.set(I,[]),C.get(I)?.push(N))}let m=[...r,...c],g=[];for(let y of d){let x=y.split("\0"),I=i.get(y);if(!I)continue;let N=F();for(let C=0;C<r.length;C++)b(N,r[C],x[C]);for(let C of c){let A=I.get(C)||[];b(N,C,rt(l,A))}g.push(N)}return{stdout:w(m,g),stderr:"",exitCode:0}}function rt(e,n){let t=n.filter(s=>s!=null).map(s=>typeof s=="number"?s:Number.parseFloat(String(s))).filter(s=>!Number.isNaN(s));switch(e){case"count":return n.length;case"sum":return t.reduce((s,r)=>s+r,0);case"mean":case"avg":return t.length>0?t.reduce((s,r)=>s+r,0)/t.length:null;case"min":return t.length>0?Math.min(...t):null;case"max":return t.length>0?Math.max(...t):null;case"first":return n.length>0?String(n[0]??""):null;case"last":return n.length>0?String(n[n.length-1]??""):null;default:return null}}async function Oe(e,n){let t="",s=[];for(let h=0;h<e.length;h++){let u=e[h];(u==="-s"||u==="--sort")&&h+1<e.length?t=e[++h]:u.startsWith("-")||s.push(u)}if(s.length<2)return{stdout:"",stderr:`xan merge: usage: xan merge [OPTIONS] FILE1 FILE2 ...
51
- `,exitCode:1};let r=[],o=null;for(let h of s){let u=await v([h],n);if(u.error)return u.error;if(o===null)o=u.headers;else if(JSON.stringify(o)!==JSON.stringify(u.headers))return{stdout:"",stderr:`xan merge: all files must have the same headers
52
- `,exitCode:1};r.push({headers:u.headers,data:u.data})}if(!o)return{stdout:"",stderr:"",exitCode:0};let a=[];for(let{data:h}of r)a=a.concat(h);if(t){if(!o.includes(t))return{stdout:"",stderr:`xan merge: column '${t}' not found
53
- `,exitCode:1};a.sort((h,u)=>{let p=h[t],l=u[t],f=typeof p=="number"?p:Number.parseFloat(String(p)),c=typeof l=="number"?l:Number.parseFloat(String(l));return!Number.isNaN(f)&&!Number.isNaN(c)?f-c:String(p??"").localeCompare(String(l??""))})}return{stdout:w(o,a),stderr:"",exitCode:0}}U();async function Pe(e,n){let t=e.filter(u=>!u.startsWith("-")),{headers:s,data:r,error:o}=await v(t,n);return o||(r.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:r.map(u=>s.map(p=>u[p])).map(u=>u.map(p=>ot(p)).join(",")).join(`
54
- `)+`
55
- `,stderr:"",exitCode:0})}function ot(e){if(e==null)return"";let n=String(e);return n.includes(",")||n.includes('"')||n.includes(`
56
- `)?`"${n.replace(/"/g,'""')}"`:n}async function Re(e,n){let t=null,s=null,r=[];for(let c=0;c<e.length;c++){let i=e[c];if(i==="--seed"&&c+1<e.length)s=Number.parseInt(e[++c],10);else if(!i.startsWith("-")){let d=Number.parseInt(i,10);t===null&&!Number.isNaN(d)&&d>0?t=d:r.push(i)}}if(t===null)return{stdout:"",stderr:`xan sample: usage: xan sample <sample-size> [FILE]
57
- `,exitCode:1};let{headers:o,data:a,error:h}=await v(r,n);if(h)return h;if(a.length<=t)return{stdout:w(o,a),stderr:"",exitCode:0};let u=s!==null?s:Date.now(),p=()=>(u=u*1103515245+12345&2147483647,u/2147483647),l=a.map((c,i)=>i);for(let c=l.length-1;c>0;c--){let i=Math.floor(p()*(c+1));[l[c],l[i]]=[l[i],l[c]]}let f=l.slice(0,t).sort((c,i)=>c-i).map(c=>a[c]);return{stdout:w(o,f),stderr:"",exitCode:0}}async function Me(e,n){let t=!1,s=[];for(let u=0;u<e.length;u++){let p=e[u];p==="-p"||p==="--pad"?t=!0:p.startsWith("-")||s.push(p)}if(s.length===0)return{stdout:"",stderr:`xan cat: no files specified
58
- `,exitCode:1};let r=await Ve(n,s,{cmdName:"xan cat",stopOnError:!0});if(r.exitCode!==0)return{stdout:"",stderr:r.stderr,exitCode:r.exitCode};let o=[],a=[];for(let{content:u}of r.files){let{headers:p,data:l}=Ue(u);o.push({headers:p,data:l});for(let f of p)a.includes(f)||a.push(f)}if(!t){let u=JSON.stringify(o[0].headers);for(let p=1;p<o.length;p++)if(JSON.stringify(o[p].headers)!==u)return{stdout:"",stderr:`xan cat: headers do not match (use -p to pad)
59
- `,exitCode:1};a=o[0].headers}let h=[];for(let{headers:u,data:p}of o)for(let l of p){let f=F();for(let c of a)b(f,c,u.includes(c)?l[c]:"");h.push(f)}return{stdout:w(a,h),stderr:"",exitCode:0}}async function $e(e,n){let t="",s=[],r=!1,o=!1,a=[];for(let i=0;i<e.length;i++){let d=e[i];(d==="-s"||d==="--select")&&i+1<e.length?s=e[++i].split(","):d==="-v"||d==="--invert"?r=!0:d==="-i"||d==="--ignore-case"?o=!0:d==="-r"||d==="--regex"||d.startsWith("-")||(t?a.push(d):t=d)}if(!t)return{stdout:"",stderr:`xan search: no pattern specified
60
- `,exitCode:1};let{headers:h,data:u,error:p}=await v(a,n);if(p)return p;let l=s.length>0?s:h,f;try{f=H(t,o?"i":"")}catch{return{stdout:"",stderr:`xan search: invalid regex pattern '${t}'
61
- `,exitCode:1}}let c=u.filter(i=>{let d=l.some(m=>{let g=i[m];return g!=null&&f.test(String(g))});return r?!d:d});return{stdout:w(h,c),stderr:"",exitCode:0}}async function Te(e,n){let t="",s=[];for(let c of e)c.startsWith("-")||(t?s.push(c):t=c);if(!t)return{stdout:"",stderr:`xan flatmap: no expression specified
62
- `,exitCode:1};let{headers:r,data:o,error:a}=await v(s,n);if(a)return a;let u=V(t).map(({expr:c,name:i})=>({alias:typeof i=="string"?i:i[0],ast:L(c)})),p={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},l=[...r,...u.map(c=>c.alias)],f=[];for(let c of o){let i=[],d=1;for(let m of u){let g=$(c,m.ast,p),y=g.length>0&&Array.isArray(g[0])?g[0]:g;i.push(y),d=Math.max(d,y.length)}for(let m=0;m<d;m++){let g=M(c);for(let y=0;y<u.length;y++){let x=i[y][m]??null;b(g,u[y].alias,x)}f.push(g)}}return{stdout:w(l,f),stderr:"",exitCode:0}}async function je(e,n){let{cmdView:t}=await import("./xan-view-5SZBYPLG.js");return t(e,n)}var Xe=new Set(["fuzzy-join","glob","hist","input","parallel","plot","progress","range","scrape","tokenize","union-find"]),it=new Set(["agg","behead","cat","count","dedup","drop","enum","explode","f","filter","fixlengths","flatmap","flatten","fmt","frequency","freq","from","groupby","head","headers","implode","join","map","merge","partition","pivot","rename","reverse","sample","search","select","shuffle","slice","sort","split","stats","tail","to","top","transform","transpose","view",...Xe]),Ge={name:"xan",summary:"CSV toolkit for data manipulation",usage:"xan <COMMAND> [OPTIONS] [FILE]",description:`xan is a collection of commands for working with CSV data.
63
- It provides a simple, ergonomic interface for common data operations.
64
-
65
- COMMANDS:
66
- Core:
67
- headers Show column names
68
- count Count rows
69
- head Show first N rows
70
- tail Show last N rows
71
- slice Extract row range
72
- reverse Reverse row order
73
- behead Remove header row
74
- sample Random sample of rows
75
-
76
- Column operations:
77
- select Select columns (supports glob, ranges, negation)
78
- drop Drop columns
79
- rename Rename columns
80
- enum Add row index column
81
-
82
- Row operations:
83
- filter Filter rows by expression
84
- search Filter rows by regex match
85
- sort Sort rows
86
- dedup Remove duplicates
87
- top Get top N by column
88
-
89
- Transformations:
90
- map Add computed columns
91
- transform Modify existing columns
92
- explode Split column into multiple rows
93
- implode Combine rows, join column values
94
- flatmap Map returning multiple rows
95
- pivot Reshape rows into columns
96
- transpose Swap rows and columns
97
-
98
- Aggregation:
99
- agg Aggregate values
100
- groupby Group and aggregate
101
- frequency Count value occurrences
102
- stats Show column statistics
103
-
104
- Multi-file:
105
- cat Concatenate CSV files
106
- join Join two CSV files on key
107
- merge Merge sorted CSV files
108
- split Split into multiple files
109
- partition Split by column value
110
-
111
- Data conversion:
112
- to Convert CSV to other formats (json)
113
- from Convert other formats to CSV (json)
114
- shuffle Randomly reorder rows
115
- fixlengths Fix ragged CSV files
116
-
117
- Output:
118
- view Pretty print as table
119
- flatten Display records vertically (alias: f)
120
- fmt Format output
121
-
122
- EXAMPLES:
123
- xan headers data.csv
124
- xan count data.csv
125
- xan head -n 5 data.csv
126
- xan select name,email data.csv
127
- xan select 'vec_*' data.csv # glob pattern
128
- xan select 'a:c' data.csv # column range
129
- xan filter 'age > 30' data.csv
130
- xan search -r '^foo' data.csv
131
- xan sort -N price data.csv
132
- xan agg 'sum(amount) as total' data.csv
133
- xan groupby region 'count() as n' data.csv
134
- xan explode tags data.csv
135
- xan join id file1.csv id file2.csv
136
- xan pivot year 'sum(sales)' data.csv`,options:[" --help display this help and exit"]},at={headers:{name:"xan headers",summary:"Show column names",usage:"xan headers [OPTIONS] [FILE]",description:"Display column names from a CSV file.",options:["-j, --just-names show names only (no index)"]},count:{name:"xan count",summary:"Count rows",usage:"xan count [FILE]",description:"Count the number of data rows (excluding header).",options:[]},filter:{name:"xan filter",summary:"Filter rows by expression",usage:"xan filter [OPTIONS] EXPR [FILE]",description:"Filter CSV rows using moonblade expressions.",options:["-v, --invert invert match","-l, --limit N limit output rows"]},search:{name:"xan search",summary:"Filter rows by regex",usage:"xan search [OPTIONS] PATTERN [FILE]",description:"Filter CSV rows by regex match on columns.",options:["-s, --select COLS search only these columns","-v, --invert invert match","-i, --ignore-case case insensitive"]},select:{name:"xan select",summary:"Select columns",usage:"xan select COLS [FILE]",description:"Select columns by name, index, glob, or range.",options:["Supports: col names, indices (0,1), ranges (a:c), globs (vec_*), negation (!col)"]},explode:{name:"xan explode",summary:"Split column into rows",usage:"xan explode COLUMN [OPTIONS] [FILE]",description:"Split delimited column values into multiple rows.",options:["-s, --separator SEP separator (default: |)","--drop-empty drop empty values","-r, --rename NAME rename column"]},implode:{name:"xan implode",summary:"Combine rows",usage:"xan implode COLUMN [OPTIONS] [FILE]",description:"Combine consecutive rows, joining column values.",options:["-s, --sep SEP separator (default: |)","-r, --rename NAME rename column"]},join:{name:"xan join",summary:"Join CSV files",usage:"xan join KEY1 FILE1 KEY2 FILE2 [OPTIONS]",description:"Join two CSV files on key columns.",options:["--left left outer join","--right right outer join","--full full outer join","-D, --default VAL default for missing"]},pivot:{name:"xan pivot",summary:"Reshape to columns",usage:"xan pivot COLUMN AGG_EXPR [OPTIONS] [FILE]",description:"Turn row values into columns.",options:["-g, --groupby COLS group by columns"]}},ln={name:"xan",async execute(e,n){if(e.length===0||K(e))return D(Ge);let t=e[0],s=e.slice(1);if(K(s)){let r=at[t];return r?D(r):D(Ge)}if(Xe.has(t))return{stdout:"",stderr:`xan ${t}: not yet implemented
137
- `,exitCode:1};switch(t){case"headers":return ae(s,n);case"count":return le(s,n);case"head":return ue(s,n);case"tail":return ce(s,n);case"slice":return pe(s,n);case"reverse":return fe(s,n);case"behead":return Pe(s,n);case"sample":return Re(s,n);case"select":return se(s,n);case"drop":return re(s,n);case"rename":return oe(s,n);case"enum":return ie(s,n);case"filter":return Ce(s,n);case"search":return $e(s,n);case"sort":return be(s,n);case"dedup":return Se(s,n);case"top":return Ie(s,n);case"map":return ke(s,n);case"transform":return Ne(s,n);case"explode":return Ee(s,n);case"implode":return Ae(s,n);case"flatmap":return Te(s,n);case"pivot":return Le(s,n);case"agg":return Q(s,n);case"groupby":return ee(s,n);case"frequency":case"freq":return te(s,n);case"stats":return ne(s,n);case"cat":return Me(s,n);case"join":return Fe(s,n);case"merge":return Oe(s,n);case"split":return ye(s,n);case"partition":return xe(s,n);case"to":return we(s,n);case"from":return ve(s,n);case"transpose":return he(s,n);case"shuffle":return me(s,n);case"fixlengths":return ge(s,n);case"view":return X(s,n);case"flatten":case"f":return G(s,n);case"fmt":return je(s,n);default:return it.has(t)?{stdout:"",stderr:`xan ${t}: not yet implemented
138
- `,exitCode:1}:{stdout:"",stderr:`xan: unknown command '${t}'
139
- Run 'xan --help' for usage.
140
- `,exitCode:1}}}};export{ln as xanCommand};
@@ -1,20 +0,0 @@
1
- import{a as se}from"./chunk-OJDRYQWQ.js";import{k as b}from"./chunk-PSW6BMXW.js";import{a as m,b as P}from"./chunk-YNYSPYQ5.js";import{a as re,b as ie,c as j}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var be=1e4,Oe=100,Le=new P(/\s+/);function Q(e={}){let{fieldSep:t=Le,maxIterations:n=be,maxRecursionDepth:i=Oe,fs:a,cwd:s,exec:o}=e;return{FS:" ",OFS:" ",ORS:`
2
- `,OFMT:"%.6g",NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:Object.create(null),arrays:Object.create(null),arrayAliases:new Map,ARGC:0,ARGV:Object.create(null),ENVIRON:Object.create(null),functions:new Map,fieldSep:t,maxIterations:n,maxRecursionDepth:i,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:a,cwd:s,exec:o}}function ae(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":return t!==0?e/t:0;case"%":return t!==0?e%t:0;case"^":case"**":return e**t;default:return 0}}function C(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function v(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}async function x(e,t){if(e.type==="regex")return e.pattern;let n=v(await t.evalExpr(e));return n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)),n}async function ce(e,t){return e?e.type==="variable"?e.name:e.type==="field"?`$${Math.floor(C(await t.evalExpr(e.index)))}`:"$0":"$0"}function le(e,t){if(e==="$0")return t.line;if(e.startsWith("$")){let n=parseInt(e.slice(1),10)-1;return t.fields[n]||""}return v(t.vars[e]??"")}function ue(e,t,n){if(e==="$0")n.line=t,n.fields=n.FS===" "?t.trim().split(/\s+/).filter(Boolean):n.fieldSep.split(t),n.NF=n.fields.length;else if(e.startsWith("$")){let i=parseInt(e.slice(1),10)-1;for(;n.fields.length<=i;)n.fields.push("");n.fields[i]=t,n.NF=n.fields.length,n.line=n.fields.join(n.OFS)}else n.vars[e]=t}async function Pe(e,t,n){return e.length===0?t.line.length:v(await n.evalExpr(e[0])).length}async function Me(e,t,n){if(e.length<2)return"";let i=v(await n.evalExpr(e[0])),a=Math.floor(C(await n.evalExpr(e[1])))-1;if(e.length>=3){let s=Math.floor(C(await n.evalExpr(e[2])));return i.substr(Math.max(0,a),s)}return i.substr(Math.max(0,a))}async function Te(e,t,n){if(e.length<2)return 0;let i=v(await n.evalExpr(e[0])),a=v(await n.evalExpr(e[1])),s=i.indexOf(a);return s===-1?0:s+1}async function Fe(e,t,n){if(e.length<2)return 0;let i=v(await n.evalExpr(e[0])),a=e[1];if(a.type!=="variable")return 0;let s=a.name,o=t.FS;if(e.length>=3){let h=e[2];if(h.type==="regex")o=m(h.pattern);else{let N=v(await n.evalExpr(h));o=N===" "?m("\\s+"):N}}else t.FS===" "&&(o=m("\\s+"));let l=typeof o=="string"?i.split(o):o.split(i);t.arrays[s]=Object.create(null);for(let h=0;h<l.length;h++)t.arrays[s][String(h+1)]=l[h];return l.length}async function _e(e,t,n){if(e.length<2)return 0;let i=await x(e[0],n),a=v(await n.evalExpr(e[1])),s=await ce(e[2],n),o=le(s,t);try{let h=m(i).replace(o,he(a)),N=h!==o?1:0;return ue(s,h,t),N}catch{return 0}}async function Ge(e,t,n){if(e.length<2)return 0;let i=await x(e[0],n),a=v(await n.evalExpr(e[1])),s=await ce(e[2],n),o=le(s,t);try{let l=m(i,"g"),h=l.match(o),N=h?h.length:0,k=l.replace(o,he(a));return ue(s,k,t),N}catch{return 0}}function he(e){return t=>{let n="",i=0;for(;i<e.length;)if(e[i]==="\\"&&i+1<e.length){let a=e[i+1];a==="&"?(n+="&",i+=2):a==="\\"?(n+="\\",i+=2):(n+=e[i+1],i+=2)}else e[i]==="&"?(n+=t,i++):(n+=e[i],i++);return n}}async function De(e,t,n){if(e.length<2)return t.RSTART=0,t.RLENGTH=-1,0;let i=v(await n.evalExpr(e[0])),a=await x(e[1],n);try{let o=m(a).exec(i);if(o)return t.RSTART=o.index+1,t.RLENGTH=o[0].length,t.RSTART}catch{}return t.RSTART=0,t.RLENGTH=-1,0}async function xe(e,t,n){if(e.length<3)return"";let i=await x(e[0],n),a=v(await n.evalExpr(e[1])),s=v(await n.evalExpr(e[2])),o=e.length>=4?v(await n.evalExpr(e[3])):t.line;try{let l=s.toLowerCase()==="g",h=l?0:parseInt(s,10)||1;if(l)return m(i,"g").replace(o,(k,...y)=>oe(a,k,y.slice(0,-2)));{let N=0;return m(i,"g").replace(o,(y,...I)=>(N++,N===h?oe(a,y,I.slice(0,-2)):y))}}catch{return o}}function oe(e,t,n){let i="",a=0;for(;a<e.length;)if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];if(s==="&")i+="&",a+=2;else if(s==="0")i+=t,a+=2;else if(s>="1"&&s<="9"){let o=parseInt(s,10)-1;i+=n[o]||"",a+=2}else s==="n"?(i+=`
3
- `,a+=2):s==="t"?(i+=" ",a+=2):(i+=s,a+=2)}else e[a]==="&"?(i+=t,a++):(i+=e[a],a++);return i}async function Ue(e,t,n){return e.length===0?"":v(await n.evalExpr(e[0])).toLowerCase()}async function Be(e,t,n){return e.length===0?"":v(await n.evalExpr(e[0])).toUpperCase()}async function He(e,t,n){if(e.length===0)return"";let i=v(await n.evalExpr(e[0])),a=[];for(let s=1;s<e.length;s++)a.push(await n.evalExpr(e[s]));return U(i,a)}async function $e(e,t,n){return e.length===0?0:Math.floor(C(await n.evalExpr(e[0])))}async function We(e,t,n){return e.length===0?0:Math.sqrt(C(await n.evalExpr(e[0])))}async function Ve(e,t,n){return e.length===0?0:Math.sin(C(await n.evalExpr(e[0])))}async function Ke(e,t,n){return e.length===0?0:Math.cos(C(await n.evalExpr(e[0])))}async function Xe(e,t,n){let i=e.length>0?C(await n.evalExpr(e[0])):0,a=e.length>1?C(await n.evalExpr(e[1])):0;return Math.atan2(i,a)}async function je(e,t,n){return e.length===0?0:Math.log(C(await n.evalExpr(e[0])))}async function Qe(e,t,n){return e.length===0?1:Math.exp(C(await n.evalExpr(e[0])))}function qe(e,t,n){return t.random?t.random():Math.random()}async function ze(e,t,n){let i=e.length>0?C(await n.evalExpr(e[0])):Date.now();return t.vars._srand_seed=i,i}function Je(e,t){return()=>{throw new Error(`${e}() is not supported - ${t}`)}}function q(e){return()=>{throw new Error(`function '${e}()' is not implemented`)}}function U(e,t){let n=0,i="",a=0;for(;a<e.length;)if(e[a]==="%"&&a+1<e.length){let s=a+1,o="",l="",h="",N,k=s;for(;s<e.length&&/\d/.test(e[s]);)s++;s>k&&e[s]==="$"?(N=parseInt(e.substring(k,s),10)-1,s++):s=k;let y=()=>{if(s<e.length){if(s+1<e.length&&(e[s]==="h"&&e[s+1]==="h"||e[s]==="l"&&e[s+1]==="l")){s+=2;return}/[lzjh]/.test(e[s])&&s++}};for(;s<e.length&&/[-+ #0]/.test(e[s]);)o+=e[s++];if(e[s]==="*"){let c=t[n++],p=c!==void 0?Math.floor(Number(c)):0;p<0?(o+="-",l=String(-p)):l=String(p),s++}else for(;s<e.length&&/\d/.test(e[s]);)l+=e[s++];if(e[s]===".")if(s++,e[s]==="*"){let c=t[n++];h=String(c!==void 0?Math.floor(Number(c)):0),s++}else for(;s<e.length&&/\d/.test(e[s]);)h+=e[s++];y();let I=e[s],w=t[N!==void 0?N:n];switch(I){case"s":{let c=w!==void 0?String(w):"";if(h&&(c=c.substring(0,parseInt(h,10))),l){let p=parseInt(l,10);o.includes("-")?c=c.padEnd(p):c=c.padStart(p)}i+=c,N===void 0&&n++;break}case"d":case"i":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=c<0,E=Math.abs(c).toString();if(h){let O=parseInt(h,10);E=E.padStart(O,"0")}let d="";p?d="-":o.includes("+")?d="+":o.includes(" ")&&(d=" ");let R=d+E;if(l){let O=parseInt(l,10);o.includes("-")?R=R.padEnd(O):o.includes("0")&&!h?R=d+E.padStart(O-d.length,"0"):R=R.padStart(O)}i+=R,N===void 0&&n++;break}case"f":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c.toFixed(p);if(l){let d=parseInt(l,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"e":case"E":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c.toExponential(p);if(I==="E"&&(E=E.toUpperCase()),l){let d=parseInt(l,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"g":case"G":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c!==0?Math.floor(Math.log10(Math.abs(c))):0,d;if(c===0?d="0":E<-4||E>=p?(d=c.toExponential(p-1),I==="G"&&(d=d.toUpperCase())):d=c.toPrecision(p),d.includes(".")&&(d=d.replace(/\.?0+$/,"").replace(/\.?0+e/,"e")),d.includes("e")&&(d=d.replace(/\.?0+e/,"e")),l){let R=parseInt(l,10);o.includes("-")?d=d.padEnd(R):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"x":case"X":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=Math.abs(c).toString(16);if(I==="X"&&(p=p.toUpperCase()),h){let R=parseInt(h,10);p=p.padStart(R,"0")}let E=c<0?"-":"",d=E+p;if(l){let R=parseInt(l,10);o.includes("-")?d=d.padEnd(R):o.includes("0")&&!h?d=E+p.padStart(R-E.length,"0"):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"o":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=Math.abs(c).toString(8);if(h){let R=parseInt(h,10);p=p.padStart(R,"0")}let E=c<0?"-":"",d=E+p;if(l){let R=parseInt(l,10);o.includes("-")?d=d.padEnd(R):o.includes("0")&&!h?d=E+p.padStart(R-E.length,"0"):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"c":{typeof w=="number"?i+=String.fromCharCode(w):i+=String(w??"").charAt(0)||"",N===void 0&&n++;break}case"%":i+="%";break;default:i+=e.substring(a,s+1)}a=s+1}else if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];switch(s){case"n":i+=`
4
- `;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=s}a+=2}else i+=e[a++];return i}var pe={length:Pe,substr:Me,index:Te,split:Fe,sub:_e,gsub:Ge,match:De,gensub:xe,tolower:Ue,toupper:Be,sprintf:He,int:$e,sqrt:We,sin:Ve,cos:Ke,atan2:Xe,log:je,exp:Qe,rand:qe,srand:ze,system:Je("system","shell execution not allowed in sandboxed environment"),close:()=>0,fflush:()=>0,systime:q("systime"),mktime:q("mktime"),strftime:q("strftime")};function g(e){return typeof e=="number"?e!==0:!(e===""||e==="0")}function A(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function S(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}function z(e){if(typeof e=="number")return!0;let t=String(e).trim();return t===""?!1:!Number.isNaN(Number(t))}function _(e,t){try{return m(e).test(t)}catch{return!1}}function fe(e,t){return t===""?[]:e.FS===" "?t.trim().split(/\s+/).filter(Boolean):e.fieldSep.split(t)}function B(e,t){return t===0?e.line:t<0||t>e.fields.length?"":e.fields[t-1]??""}function J(e,t,n){if(t===0)e.line=S(n),e.fields=fe(e,e.line),e.NF=e.fields.length;else if(t>0){for(;e.fields.length<t;)e.fields.push("");e.fields[t-1]=S(n),e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}}function M(e,t){e.line=t,e.fields=fe(e,t),e.NF=e.fields.length}function de(e,t){if(e.FS=t,t===" ")e.fieldSep=new P(/\s+/);else try{e.fieldSep=m(t)}catch{e.fieldSep=m(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))}}function H(e,t){switch(t){case"FS":return e.FS;case"OFS":return e.OFS;case"ORS":return e.ORS;case"OFMT":return e.OFMT;case"NR":return e.NR;case"NF":return e.NF;case"FNR":return e.FNR;case"FILENAME":return e.FILENAME;case"RSTART":return e.RSTART;case"RLENGTH":return e.RLENGTH;case"SUBSEP":return e.SUBSEP;case"ARGC":return e.ARGC}return e.vars[t]??""}function T(e,t,n){switch(t){case"FS":de(e,S(n));return;case"OFS":e.OFS=S(n);return;case"ORS":e.ORS=S(n);return;case"OFMT":e.OFMT=S(n);return;case"NR":e.NR=Math.floor(A(n));return;case"NF":{let i=Math.floor(A(n));if(i<e.NF)e.fields=e.fields.slice(0,i),e.line=e.fields.join(e.OFS);else if(i>e.NF){for(;e.fields.length<i;)e.fields.push("");e.line=e.fields.join(e.OFS)}e.NF=i;return}case"FNR":e.FNR=Math.floor(A(n));return;case"FILENAME":e.FILENAME=S(n);return;case"RSTART":e.RSTART=Math.floor(A(n));return;case"RLENGTH":e.RLENGTH=Math.floor(A(n));return;case"SUBSEP":e.SUBSEP=S(n);return}e.vars[t]=n}function G(e,t){let n=t,i=new Set,a=e.arrayAliases.get(n);for(;a!==void 0&&!i.has(n);)i.add(n),n=a,a=e.arrayAliases.get(n);return n}function $(e,t,n){if(t==="ARGV")return e.ARGV[n]??"";if(t==="ENVIRON")return e.ENVIRON[n]??"";let i=G(e,t);return e.arrays[i]?.[n]??""}function Z(e,t,n,i){let a=G(e,t);e.arrays[a]||(e.arrays[a]=Object.create(null)),e.arrays[a][n]=i}function Ee(e,t,n){if(t==="ARGV")return e.ARGV[n]!==void 0;if(t==="ENVIRON")return e.ENVIRON[n]!==void 0;let i=G(e,t);return e.arrays[i]?.[n]!==void 0}function Ne(e,t,n){let i=G(e,t);e.arrays[i]&&delete e.arrays[i][n]}function Se(e,t){let n=G(e,t);delete e.arrays[n]}var Y=null;function ye(e){Y=e}async function f(e,t){switch(t.type){case"number":return t.value;case"string":return t.value;case"regex":return _(t.pattern,e.line)?1:0;case"field":return Ze(e,t);case"variable":return H(e,t.name);case"array_access":return Ye(e,t);case"binary":return et(e,t);case"unary":return rt(e,t);case"ternary":return g(await f(e,t.condition))?await f(e,t.consequent):await f(e,t.alternate);case"call":return it(e,t.name,t.args);case"assignment":return at(e,t);case"pre_increment":return ot(e,t.operand);case"pre_decrement":return ct(e,t.operand);case"post_increment":return lt(e,t.operand);case"post_decrement":return ut(e,t.operand);case"in":return ht(e,t.key,t.array);case"getline":return pt(e,t.variable,t.file,t.command);case"tuple":return Et(e,t.elements);default:return""}}async function Ze(e,t){let n=Math.floor(A(await f(e,t.index)));return B(e,n)}async function Ye(e,t){let n=S(await f(e,t.key));return $(e,t.array,n)}async function et(e,t){let n=t.operator;if(n==="||")return g(await f(e,t.left))||g(await f(e,t.right))?1:0;if(n==="&&")return g(await f(e,t.left))&&g(await f(e,t.right))?1:0;if(n==="~"){let l=await f(e,t.left),h=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return m(h).test(S(l))?1:0}catch{return 0}}if(n==="!~"){let l=await f(e,t.left),h=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return m(h).test(S(l))?0:1}catch{return 1}}let i=await f(e,t.left),a=await f(e,t.right);if(n===" ")return S(i)+S(a);if(tt(n))return nt(i,a,n);let s=A(i),o=A(a);return ae(s,o,n)}function tt(e){return["<","<=",">",">=","==","!="].includes(e)}function nt(e,t,n){let i=z(e),a=z(t);if(i&&a){let l=A(e),h=A(t);switch(n){case"<":return l<h?1:0;case"<=":return l<=h?1:0;case">":return l>h?1:0;case">=":return l>=h?1:0;case"==":return l===h?1:0;case"!=":return l!==h?1:0}}let s=S(e),o=S(t);switch(n){case"<":return s<o?1:0;case"<=":return s<=o?1:0;case">":return s>o?1:0;case">=":return s>=o?1:0;case"==":return s===o?1:0;case"!=":return s!==o?1:0}return 0}async function rt(e,t){let n=await f(e,t.operand);switch(t.operator){case"!":return g(n)?0:1;case"-":return-A(n);case"+":return+A(n);default:return n}}async function it(e,t,n){let i=pe[t];if(i)return i(n,e,{evalExpr:s=>f(e,s)});let a=e.functions.get(t);return a?st(e,a,n):""}async function st(e,t,n){if(e.currentRecursionDepth++,e.currentRecursionDepth>e.maxRecursionDepth)throw e.currentRecursionDepth--,new b(`awk: recursion depth exceeded maximum (${e.maxRecursionDepth})`,"recursion",e.output);let i=Object.create(null);for(let o of t.params)i[o]=e.vars[o];let a=[];for(let o=0;o<t.params.length;o++){let l=t.params[o];if(o<n.length){let h=n[o];h.type==="variable"&&(e.arrayAliases.set(l,h.name),a.push(l));let N=await f(e,h);e.vars[l]=N}else e.vars[l]=""}e.hasReturn=!1,e.returnValue=void 0,Y&&await Y(e,t.body.statements);let s=e.returnValue??"";for(let o of t.params)i[o]!==void 0?e.vars[o]=i[o]:delete e.vars[o];for(let o of a)e.arrayAliases.delete(o);return e.hasReturn=!1,e.returnValue=void 0,e.currentRecursionDepth--,s}async function at(e,t){let n=await f(e,t.value),i=t.target,a=t.operator,s;if(a==="=")s=n;else{let o;if(i.type==="field"){let N=Math.floor(A(await f(e,i.index)));o=B(e,N)}else if(i.type==="variable")o=H(e,i.name);else{let N=S(await f(e,i.key));o=$(e,i.array,N)}let l=A(o),h=A(n);switch(a){case"+=":s=l+h;break;case"-=":s=l-h;break;case"*=":s=l*h;break;case"/=":s=h!==0?l/h:0;break;case"%=":s=h!==0?l%h:0;break;case"^=":s=l**h;break;default:s=n}}if(i.type==="field"){let o=Math.floor(A(await f(e,i.index)));J(e,o,s)}else if(i.type==="variable")T(e,i.name,s);else{let o=S(await f(e,i.key));Z(e,i.array,o,s)}return s}async function W(e,t,n,i){let a;if(t.type==="field"){let s=Math.floor(A(await f(e,t.index)));a=A(B(e,s)),J(e,s,a+n)}else if(t.type==="variable")a=A(H(e,t.name)),T(e,t.name,a+n);else{let s=S(await f(e,t.key));a=A($(e,t.array,s)),Z(e,t.array,s,a+n)}return i?a+n:a}async function ot(e,t){return W(e,t,1,!0)}async function ct(e,t){return W(e,t,-1,!0)}async function lt(e,t){return W(e,t,1,!1)}async function ut(e,t){return W(e,t,-1,!1)}async function ht(e,t,n){let i;if(t.type==="tuple"){let a=[];for(let s of t.elements)a.push(S(await f(e,s)));i=a.join(e.SUBSEP)}else i=S(await f(e,t));return Ee(e,n,i)?1:0}async function pt(e,t,n,i){if(i)return ft(e,t,i);if(n)return dt(e,t,n);if(!e.lines||e.lineIndex===void 0)return-1;let a=e.lineIndex+1;if(a>=e.lines.length)return 0;let s=e.lines[a];return t?T(e,t,s):M(e,s),e.NR++,e.lineIndex=a,1}async function ft(e,t,n){if(!e.exec)return-1;let i=S(await f(e,n)),a=`__cmd_${i}`,s=`__cmdi_${i}`,o,l;if(e.vars[a]===void 0)try{o=(await e.exec(i)).stdout.split(`
5
- `),o.length>0&&o[o.length-1]===""&&o.pop(),e.vars[a]=JSON.stringify(o),e.vars[s]=-1,l=-1}catch{return-1}else o=JSON.parse(e.vars[a]),l=e.vars[s];let h=l+1;if(h>=o.length)return 0;let N=o[h];return e.vars[s]=h,t?T(e,t,N):M(e,N),1}async function dt(e,t,n){if(!e.fs||!e.cwd)return-1;let i=S(await f(e,n));if(i==="/dev/null")return 0;let a=e.fs.resolvePath(e.cwd,i),s=`__fc_${a}`,o=`__fi_${a}`,l,h;if(e.vars[s]===void 0)try{l=(await e.fs.readFile(a)).split(`
6
- `),l.length>0&&l[l.length-1]===""&&l.pop(),e.vars[s]=JSON.stringify(l),e.vars[o]=-1,h=-1}catch{return-1}else l=JSON.parse(e.vars[s]),h=e.vars[o];let N=h+1;if(N>=l.length)return 0;let k=l[N];return e.vars[o]=N,t?T(e,t,k):M(e,k),1}async function Et(e,t){if(t.length===0)return"";for(let n=0;n<t.length-1;n++)await f(e,t[n]);return f(e,t[t.length-1])}ye(F);async function F(e,t){for(let n of t)if(await L(e,n),Nt(e))break}function Nt(e){return e.shouldExit||e.shouldNext||e.shouldNextFile||e.loopBreak||e.loopContinue||e.hasReturn}async function L(e,t){switch(t.type){case"block":await F(e,t.statements);break;case"expr_stmt":await f(e,t.expression);break;case"print":await St(e,t.args,t.output);break;case"printf":await yt(e,t.format,t.args,t.output);break;case"if":await Rt(e,t);break;case"while":await At(e,t);break;case"do_while":await mt(e,t);break;case"for":await It(e,t);break;case"for_in":await wt(e,t);break;case"break":e.loopBreak=!0;break;case"continue":e.loopContinue=!0;break;case"next":e.shouldNext=!0;break;case"nextfile":e.shouldNextFile=!0;break;case"exit":e.shouldExit=!0,e.exitCode=t.code?Math.floor(A(await f(e,t.code))):0;break;case"return":e.hasReturn=!0,e.returnValue=t.value?await f(e,t.value):"";break;case"delete":await vt(e,t.target);break}}async function St(e,t,n){let i=[];for(let s of t){let o=await f(e,s);typeof o=="number"?Number.isInteger(o)&&Math.abs(o)<Number.MAX_SAFE_INTEGER?i.push(String(o)):i.push(U(e.OFMT,[o])):i.push(S(o))}let a=i.join(e.OFS)+e.ORS;n?await Re(e,n.redirect,n.file,a):e.output+=a}async function yt(e,t,n,i){let a=S(await f(e,t)),s=[];for(let l of n)s.push(await f(e,l));let o=U(a,s);i?await Re(e,i.redirect,i.file,o):e.output+=o}async function Re(e,t,n,i){if(!e.fs||!e.cwd){e.output+=i;return}let a=S(await f(e,n)),s=e.fs.resolvePath(e.cwd,a);t===">"?e.openedFiles.has(s)?await e.fs.appendFile(s,i):(await e.fs.writeFile(s,i),e.openedFiles.add(s)):(e.openedFiles.has(s)||e.openedFiles.add(s),await e.fs.appendFile(s,i))}async function Rt(e,t){g(await f(e,t.condition))?await L(e,t.consequent):t.alternate&&await L(e,t.alternate)}async function At(e,t){let n=0;for(;g(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new b(`awk: while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await L(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function mt(e,t){let n=0;do{if(n++,n>e.maxIterations)throw new b(`awk: do-while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await L(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}while(g(await f(e,t.condition)))}async function It(e,t){t.init&&await f(e,t.init);let n=0;for(;!t.condition||g(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new b(`awk: for loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await L(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break;t.update&&await f(e,t.update)}}async function wt(e,t){let n=e.arrays[t.array];if(n)for(let i of Object.keys(n)){if(e.vars[t.variable]=i,e.loopContinue=!1,await L(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function vt(e,t){if(t.type==="array_access"){let n=S(await f(e,t.key));Ne(e,t.array,n)}else t.type==="variable"&&Se(e,t.name)}var D=class{ctx;program=null;rangeStates=[];constructor(t){this.ctx=t}execute(t){this.program=t,this.ctx.output="";for(let n of t.functions)this.ctx.functions.set(n.name,n);this.rangeStates=t.rules.map(()=>!1)}async executeBegin(){if(this.program){for(let t of this.program.rules)if(t.pattern?.type==="begin"&&(await F(this.ctx,t.action.statements),this.ctx.shouldExit))break}}async executeLine(t){if(!(!this.program||this.ctx.shouldExit)){M(this.ctx,t),this.ctx.NR++,this.ctx.FNR++,this.ctx.shouldNext=!1;for(let n=0;n<this.program.rules.length&&!(this.ctx.shouldExit||this.ctx.shouldNext||this.ctx.shouldNextFile);n++){let i=this.program.rules[n];i.pattern?.type==="begin"||i.pattern?.type==="end"||await this.matchesRule(i,n)&&await F(this.ctx,i.action.statements)}}}async executeEnd(){if(this.program&&!this.ctx.inEndBlock){this.ctx.inEndBlock=!0,this.ctx.shouldExit=!1;for(let t of this.program.rules)if(t.pattern?.type==="end"&&(await F(this.ctx,t.action.statements),this.ctx.shouldExit))break;this.ctx.inEndBlock=!1}}getOutput(){return this.ctx.output}getExitCode(){return this.ctx.exitCode}getContext(){return this.ctx}async matchesRule(t,n){let i=t.pattern;if(!i)return!0;switch(i.type){case"begin":case"end":return!1;case"regex_pattern":return _(i.pattern,this.ctx.line);case"expr_pattern":return g(await f(this.ctx,i.expression));case"range":{let a=await this.matchPattern(i.start),s=await this.matchPattern(i.end);return this.rangeStates[n]?(s&&(this.rangeStates[n]=!1),!0):a?(this.rangeStates[n]=!0,s&&(this.rangeStates[n]=!1),!0):!1}default:return!1}}async matchPattern(t){switch(t.type){case"regex_pattern":return _(t.pattern,this.ctx.line);case"expr_pattern":return g(await f(this.ctx,t.expression));default:return!1}}};var r;(function(e){e.NUMBER="NUMBER",e.STRING="STRING",e.REGEX="REGEX",e.IDENT="IDENT",e.BEGIN="BEGIN",e.END="END",e.IF="IF",e.ELSE="ELSE",e.WHILE="WHILE",e.DO="DO",e.FOR="FOR",e.IN="IN",e.BREAK="BREAK",e.CONTINUE="CONTINUE",e.NEXT="NEXT",e.NEXTFILE="NEXTFILE",e.EXIT="EXIT",e.RETURN="RETURN",e.DELETE="DELETE",e.FUNCTION="FUNCTION",e.PRINT="PRINT",e.PRINTF="PRINTF",e.GETLINE="GETLINE",e.PLUS="PLUS",e.MINUS="MINUS",e.STAR="STAR",e.SLASH="SLASH",e.PERCENT="PERCENT",e.CARET="CARET",e.EQ="EQ",e.NE="NE",e.LT="LT",e.GT="GT",e.LE="LE",e.GE="GE",e.MATCH="MATCH",e.NOT_MATCH="NOT_MATCH",e.AND="AND",e.OR="OR",e.NOT="NOT",e.ASSIGN="ASSIGN",e.PLUS_ASSIGN="PLUS_ASSIGN",e.MINUS_ASSIGN="MINUS_ASSIGN",e.STAR_ASSIGN="STAR_ASSIGN",e.SLASH_ASSIGN="SLASH_ASSIGN",e.PERCENT_ASSIGN="PERCENT_ASSIGN",e.CARET_ASSIGN="CARET_ASSIGN",e.INCREMENT="INCREMENT",e.DECREMENT="DECREMENT",e.QUESTION="QUESTION",e.COLON="COLON",e.COMMA="COMMA",e.SEMICOLON="SEMICOLON",e.NEWLINE="NEWLINE",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.DOLLAR="DOLLAR",e.APPEND="APPEND",e.PIPE="PIPE",e.EOF="EOF"})(r||(r={}));var gt=new Map([["BEGIN",r.BEGIN],["END",r.END],["if",r.IF],["else",r.ELSE],["while",r.WHILE],["do",r.DO],["for",r.FOR],["in",r.IN],["break",r.BREAK],["continue",r.CONTINUE],["next",r.NEXT],["nextfile",r.NEXTFILE],["exit",r.EXIT],["return",r.RETURN],["delete",r.DELETE],["function",r.FUNCTION],["print",r.PRINT],["printf",r.PRINTF],["getline",r.GETLINE]]);function kt(e){return e.replace(/\[\[:space:\]\]/g,"[ \\t\\n\\r\\f\\v]").replace(/\[\[:blank:\]\]/g,"[ \\t]").replace(/\[\[:alpha:\]\]/g,"[a-zA-Z]").replace(/\[\[:digit:\]\]/g,"[0-9]").replace(/\[\[:alnum:\]\]/g,"[a-zA-Z0-9]").replace(/\[\[:upper:\]\]/g,"[A-Z]").replace(/\[\[:lower:\]\]/g,"[a-z]").replace(/\[\[:punct:\]\]/g,"[!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~]").replace(/\[\[:xdigit:\]\]/g,"[0-9A-Fa-f]").replace(/\[\[:graph:\]\]/g,"[!-~]").replace(/\[\[:print:\]\]/g,"[ -~]").replace(/\[\[:cntrl:\]\]/g,"[\\x00-\\x1f\\x7f]")}var V=class{input;pos=0;line=1;column=1;lastTokenType=null;constructor(t){this.input=t}tokenize(){let t=[];for(;this.pos<this.input.length;){let n=this.nextToken();n&&(t.push(n),this.lastTokenType=n.type)}return t.push(this.makeToken(r.EOF,"")),t}makeToken(t,n){return{type:t,value:n,line:this.line,column:this.column}}peek(t=0){return this.input[this.pos+t]||""}advance(){let t=this.input[this.pos++]||"";return t===`
7
- `?(this.line++,this.column=1):this.column++,t}skipWhitespace(){for(;this.pos<this.input.length;){let t=this.peek();if(t===" "||t===" "||t==="\r")this.advance();else if(t==="\\")if(this.peek(1)===`
8
- `)this.advance(),this.advance();else break;else if(t==="#")for(;this.pos<this.input.length&&this.peek()!==`
9
- `;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let t=this.line,n=this.column,i=this.peek();return i===`
10
- `?(this.advance(),{type:r.NEWLINE,value:`
11
- `,line:t,column:n}):i==='"'?this.readString():i==="/"&&this.canBeRegex()?this.readRegex():this.isDigit(i)||i==="."&&this.isDigit(this.peek(1))?this.readNumber():this.isAlpha(i)||i==="_"?this.readIdentifier():this.readOperator()}canBeRegex(){return new Set([null,r.NEWLINE,r.SEMICOLON,r.LBRACE,r.RBRACE,r.LPAREN,r.LBRACKET,r.COMMA,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.AND,r.OR,r.NOT,r.MATCH,r.NOT_MATCH,r.QUESTION,r.COLON,r.LT,r.GT,r.LE,r.GE,r.EQ,r.NE,r.PLUS,r.MINUS,r.STAR,r.PERCENT,r.CARET,r.PRINT,r.PRINTF,r.IF,r.WHILE,r.DO,r.FOR,r.RETURN]).has(this.lastTokenType)}readString(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=='"';)if(this.peek()==="\\"){this.advance();let a=this.advance();switch(a){case"n":i+=`
12
- `;break;case"t":i+=" ";break;case"r":i+="\r";break;case"f":i+="\f";break;case"b":i+="\b";break;case"v":i+="\v";break;case"a":i+="\x07";break;case"\\":i+="\\";break;case'"':i+='"';break;case"/":i+="/";break;case"x":{let s="";for(;s.length<2&&/[0-9a-fA-F]/.test(this.peek());)s+=this.advance();s.length>0?i+=String.fromCharCode(parseInt(s,16)):i+="x";break}default:if(/[0-7]/.test(a)){let s=a;for(;s.length<3&&/[0-7]/.test(this.peek());)s+=this.advance();i+=String.fromCharCode(parseInt(s,8))}else i+=a}}else i+=this.advance();return this.peek()==='"'&&this.advance(),{type:r.STRING,value:i,line:t,column:n}}readRegex(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=="/";)if(this.peek()==="\\")i+=this.advance(),this.pos<this.input.length&&(i+=this.advance());else{if(this.peek()===`
13
- `)break;i+=this.advance()}return this.peek()==="/"&&this.advance(),i=kt(i),{type:r.REGEX,value:i,line:t,column:n}}readNumber(){let t=this.line,n=this.column,i="";for(;this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(i+=this.advance();this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(i+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(i+=this.advance());this.isDigit(this.peek());)i+=this.advance();return{type:r.NUMBER,value:parseFloat(i),line:t,column:n}}readIdentifier(){let t=this.line,n=this.column,i="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)i+=this.advance();let a=gt.get(i);return a!==void 0?{type:a,value:i,line:t,column:n}:{type:r.IDENT,value:i,line:t,column:n}}readOperator(){let t=this.line,n=this.column,i=this.advance(),a=this.peek();switch(i){case"+":return a==="+"?(this.advance(),{type:r.INCREMENT,value:"++",line:t,column:n}):a==="="?(this.advance(),{type:r.PLUS_ASSIGN,value:"+=",line:t,column:n}):{type:r.PLUS,value:"+",line:t,column:n};case"-":return a==="-"?(this.advance(),{type:r.DECREMENT,value:"--",line:t,column:n}):a==="="?(this.advance(),{type:r.MINUS_ASSIGN,value:"-=",line:t,column:n}):{type:r.MINUS,value:"-",line:t,column:n};case"*":return a==="*"?(this.advance(),{type:r.CARET,value:"**",line:t,column:n}):a==="="?(this.advance(),{type:r.STAR_ASSIGN,value:"*=",line:t,column:n}):{type:r.STAR,value:"*",line:t,column:n};case"/":return a==="="?(this.advance(),{type:r.SLASH_ASSIGN,value:"/=",line:t,column:n}):{type:r.SLASH,value:"/",line:t,column:n};case"%":return a==="="?(this.advance(),{type:r.PERCENT_ASSIGN,value:"%=",line:t,column:n}):{type:r.PERCENT,value:"%",line:t,column:n};case"^":return a==="="?(this.advance(),{type:r.CARET_ASSIGN,value:"^=",line:t,column:n}):{type:r.CARET,value:"^",line:t,column:n};case"=":return a==="="?(this.advance(),{type:r.EQ,value:"==",line:t,column:n}):{type:r.ASSIGN,value:"=",line:t,column:n};case"!":return a==="="?(this.advance(),{type:r.NE,value:"!=",line:t,column:n}):a==="~"?(this.advance(),{type:r.NOT_MATCH,value:"!~",line:t,column:n}):{type:r.NOT,value:"!",line:t,column:n};case"<":return a==="="?(this.advance(),{type:r.LE,value:"<=",line:t,column:n}):{type:r.LT,value:"<",line:t,column:n};case">":return a==="="?(this.advance(),{type:r.GE,value:">=",line:t,column:n}):a===">"?(this.advance(),{type:r.APPEND,value:">>",line:t,column:n}):{type:r.GT,value:">",line:t,column:n};case"&":return a==="&"?(this.advance(),{type:r.AND,value:"&&",line:t,column:n}):{type:r.IDENT,value:"&",line:t,column:n};case"|":return a==="|"?(this.advance(),{type:r.OR,value:"||",line:t,column:n}):{type:r.PIPE,value:"|",line:t,column:n};case"~":return{type:r.MATCH,value:"~",line:t,column:n};case"?":return{type:r.QUESTION,value:"?",line:t,column:n};case":":return{type:r.COLON,value:":",line:t,column:n};case",":return{type:r.COMMA,value:",",line:t,column:n};case";":return{type:r.SEMICOLON,value:";",line:t,column:n};case"(":return{type:r.LPAREN,value:"(",line:t,column:n};case")":return{type:r.RPAREN,value:")",line:t,column:n};case"{":return{type:r.LBRACE,value:"{",line:t,column:n};case"}":return{type:r.RBRACE,value:"}",line:t,column:n};case"[":return{type:r.LBRACKET,value:"[",line:t,column:n};case"]":return{type:r.RBRACKET,value:"]",line:t,column:n};case"$":return{type:r.DOLLAR,value:"$",line:t,column:n};default:return{type:r.IDENT,value:i,line:t,column:n}}}isDigit(t){return t>="0"&&t<="9"}isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isAlphaNumeric(t){return this.isDigit(t)||this.isAlpha(t)}};var u={LPAREN:"LPAREN",RPAREN:"RPAREN",QUESTION:"QUESTION",NEWLINE:"NEWLINE",SEMICOLON:"SEMICOLON",RBRACE:"RBRACE",COMMA:"COMMA",PIPE:"PIPE",GT:"GT",APPEND:"APPEND",AND:"AND",OR:"OR",ASSIGN:"ASSIGN",PLUS_ASSIGN:"PLUS_ASSIGN",MINUS_ASSIGN:"MINUS_ASSIGN",STAR_ASSIGN:"STAR_ASSIGN",SLASH_ASSIGN:"SLASH_ASSIGN",PERCENT_ASSIGN:"PERCENT_ASSIGN",CARET_ASSIGN:"CARET_ASSIGN",RBRACKET:"RBRACKET",COLON:"COLON",IN:"IN",PRINT:"PRINT",PRINTF:"PRINTF",IDENT:"IDENT",LT:"LT",LE:"LE",GE:"GE",EQ:"EQ",NE:"NE",MATCH:"MATCH",NOT_MATCH:"NOT_MATCH",NUMBER:"NUMBER",STRING:"STRING",DOLLAR:"DOLLAR",NOT:"NOT",MINUS:"MINUS",PLUS:"PLUS",INCREMENT:"INCREMENT",DECREMENT:"DECREMENT"};function ve(e){e.expect(u.PRINT);let t=[];if(e.check(u.NEWLINE)||e.check(u.SEMICOLON)||e.check(u.RBRACE)||e.check(u.PIPE)||e.check(u.GT)||e.check(u.APPEND))t.push({type:"field",index:{type:"number",value:0}});else for(t.push(K(e));e.check(u.COMMA);)e.advance(),t.push(K(e));let n;return e.check(u.GT)?(e.advance(),n={redirect:">",file:e.parsePrimary()}):e.check(u.APPEND)&&(e.advance(),n={redirect:">>",file:e.parsePrimary()}),{type:"print",args:t,output:n}}function K(e){return Ct(e)?ee(e,!0):ee(e,!1)}function ee(e,t){let n=t?e.parseTernary():bt(e);if(e.match(u.ASSIGN,u.PLUS_ASSIGN,u.MINUS_ASSIGN,u.STAR_ASSIGN,u.SLASH_ASSIGN,u.PERCENT_ASSIGN,u.CARET_ASSIGN)){let i=e.advance(),a=ee(e,t);if(n.type!=="variable"&&n.type!=="field"&&n.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[i.value],target:n,value:a}}return n}function Ct(e){let t=0,n=e.pos;for(;n<e.tokens.length;){let i=e.tokens[n];if(i.type===u.LPAREN&&t++,i.type===u.RPAREN&&t--,i.type===u.QUESTION&&t===0)return!0;if(i.type===u.NEWLINE||i.type===u.SEMICOLON||i.type===u.RBRACE||i.type===u.COMMA||i.type===u.PIPE)return!1;n++}return!1}function bt(e){let t=Ae(e);for(;e.check(u.OR);){e.advance();let n=Ae(e);t={type:"binary",operator:"||",left:t,right:n}}return t}function Ae(e){let t=me(e);for(;e.check(u.AND);){e.advance();let n=me(e);t={type:"binary",operator:"&&",left:t,right:n}}return t}function me(e){let t=Ot(e);if(e.check(u.IN)){e.advance();let n=String(e.expect(u.IDENT).value);return{type:"in",key:t,array:n}}return t}function Ot(e){let t=Ie(e);for(;Lt(e)&&!Pt(e);){let n=Ie(e);t={type:"binary",operator:" ",left:t,right:n}}return t}function Ie(e){let t=we(e);for(;e.match(u.MATCH,u.NOT_MATCH);){let n=e.advance().type===u.MATCH?"~":"!~",i=we(e);t={type:"binary",operator:n,left:t,right:i}}return t}function we(e){let t=e.parseAddSub();for(;e.match(u.LT,u.LE,u.GE,u.EQ,u.NE);){let n=e.advance(),i=e.parseAddSub();t={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[n.value],left:t,right:i}}return t}function Lt(e){return e.match(u.NUMBER,u.STRING,u.IDENT,u.DOLLAR,u.LPAREN,u.NOT,u.MINUS,u.PLUS,u.INCREMENT,u.DECREMENT)}function Pt(e){return e.match(u.AND,u.OR,u.QUESTION,u.ASSIGN,u.PLUS_ASSIGN,u.MINUS_ASSIGN,u.STAR_ASSIGN,u.SLASH_ASSIGN,u.PERCENT_ASSIGN,u.CARET_ASSIGN,u.COMMA,u.SEMICOLON,u.NEWLINE,u.RBRACE,u.RPAREN,u.RBRACKET,u.COLON,u.PIPE,u.APPEND,u.GT,u.IN)}function ge(e){e.expect(u.PRINTF);let t=e.check(u.LPAREN);t&&(e.advance(),e.skipNewlines());let n=t?e.parseExpression():K(e),i=[];for(;e.check(u.COMMA);)e.advance(),t&&e.skipNewlines(),i.push(t?e.parseExpression():K(e));t&&(e.skipNewlines(),e.expect(u.RPAREN));let a;return e.check(u.GT)?(e.advance(),a={redirect:">",file:e.parsePrimary()}):e.check(u.APPEND)&&(e.advance(),a={redirect:">>",file:e.parsePrimary()}),{type:"printf",format:n,args:i,output:a}}var X=class{tokens=[];pos=0;parse(t){let n=new V(t);return this.tokens=n.tokenize(),this.pos=0,this.parseProgram()}setPos(t){this.pos=t}current(){return this.tokens[this.pos]||{type:r.EOF,value:"",line:0,column:0}}advance(){let t=this.current();return this.pos<this.tokens.length&&this.pos++,t}match(...t){return t.includes(this.current().type)}check(t){return this.current().type===t}expect(t,n){if(!this.check(t)){let i=this.current();throw new Error(n||`Expected ${t}, got ${i.type} at line ${i.line}:${i.column}`)}return this.advance()}skipNewlines(){for(;this.check(r.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(r.NEWLINE)||this.check(r.SEMICOLON);)this.advance()}parseProgram(){let t=[],n=[];for(this.skipNewlines();!this.check(r.EOF)&&(this.skipNewlines(),!this.check(r.EOF));)this.check(r.FUNCTION)?t.push(this.parseFunction()):n.push(this.parseRule()),this.skipTerminators();return{functions:t,rules:n}}parseFunction(){this.expect(r.FUNCTION);let t=this.expect(r.IDENT).value;this.expect(r.LPAREN);let n=[];if(!this.check(r.RPAREN))for(n.push(this.expect(r.IDENT).value);this.check(r.COMMA);)this.advance(),n.push(this.expect(r.IDENT).value);this.expect(r.RPAREN),this.skipNewlines();let i=this.parseBlock();return{name:t,params:n,body:i}}parseRule(){let t;if(this.check(r.BEGIN))this.advance(),t={type:"begin"};else if(this.check(r.END))this.advance(),t={type:"end"};else if(this.check(r.LBRACE))t=void 0;else if(this.check(r.REGEX)){let i=this.advance();if(this.check(r.AND)||this.check(r.OR)){let a={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:i.value}};t={type:"expr_pattern",expression:this.parseLogicalOrRest(a)}}else{let a={type:"regex_pattern",pattern:i.value};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}}else{let a={type:"expr_pattern",expression:this.parseExpression()};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}this.skipNewlines();let n;return this.check(r.LBRACE)?n=this.parseBlock():n={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:t,action:n}}parseBlock(){this.expect(r.LBRACE),this.skipNewlines();let t=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);)t.push(this.parseStatement()),this.skipTerminators();return this.expect(r.RBRACE),{type:"block",statements:t}}parseStatement(){if(this.check(r.SEMICOLON)||this.check(r.NEWLINE))return this.advance(),{type:"block",statements:[]};if(this.check(r.LBRACE))return this.parseBlock();if(this.check(r.IF))return this.parseIf();if(this.check(r.WHILE))return this.parseWhile();if(this.check(r.DO))return this.parseDoWhile();if(this.check(r.FOR))return this.parseFor();if(this.check(r.BREAK))return this.advance(),{type:"break"};if(this.check(r.CONTINUE))return this.advance(),{type:"continue"};if(this.check(r.NEXT))return this.advance(),{type:"next"};if(this.check(r.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(r.EXIT)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"exit",code:n}}if(this.check(r.RETURN)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"return",value:n}}if(this.check(r.DELETE)){this.advance();let n=this.parsePrimary();if(n.type!=="array_access"&&n.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:n}}return this.check(r.PRINT)?ve(this):this.check(r.PRINTF)?ge(this):{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(r.IF),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();this.skipTerminators();let i;return this.check(r.ELSE)&&(this.advance(),this.skipNewlines(),i=this.parseStatement()),{type:"if",condition:t,consequent:n,alternate:i}}parseWhile(){this.expect(r.WHILE),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();return{type:"while",condition:t,body:n}}parseDoWhile(){this.expect(r.DO),this.skipNewlines();let t=this.parseStatement();this.skipNewlines(),this.expect(r.WHILE),this.expect(r.LPAREN);let n=this.parseExpression();return this.expect(r.RPAREN),{type:"do_while",body:t,condition:n}}parseFor(){if(this.expect(r.FOR),this.expect(r.LPAREN),this.check(r.IDENT)){let s=this.advance();if(this.check(r.IN)){this.advance();let o=this.expect(r.IDENT).value;this.expect(r.RPAREN),this.skipNewlines();let l=this.parseStatement();return{type:"for_in",variable:s.value,array:o,body:l}}this.pos--}let t;this.check(r.SEMICOLON)||(t=this.parseExpression()),this.expect(r.SEMICOLON);let n;this.check(r.SEMICOLON)||(n=this.parseExpression()),this.expect(r.SEMICOLON);let i;this.check(r.RPAREN)||(i=this.parseExpression()),this.expect(r.RPAREN),this.skipNewlines();let a=this.parseStatement();return{type:"for",init:t,condition:n,update:i,body:a}}parseExpression(){return this.parseAssignment()}parseAssignment(){let t=this.parseTernary();if(this.match(r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN)){let n=this.advance(),i=this.parseAssignment();if(t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[n.value],target:t,value:i}}return t}parseTernary(){let t=this.parsePipeGetline();if(this.check(r.QUESTION)){this.advance();let n=this.parseExpression();this.expect(r.COLON);let i=this.parseExpression();t={type:"ternary",condition:t,consequent:n,alternate:i}}return t}parsePipeGetline(){let t=this.parseOr();if(this.check(r.PIPE)){if(this.advance(),!this.check(r.GETLINE))throw new Error("Expected 'getline' after '|' in expression context");this.advance();let n;return this.check(r.IDENT)&&(n=this.advance().value),{type:"getline",command:t,variable:n}}return t}parseOr(){let t=this.parseAnd();for(;this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalOrRest(t){for(t=this.parseLogicalAndRest(t);this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalAndRest(t){for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseAnd(){let t=this.parseIn();for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseIn(){let t=this.parseConcatenation();if(this.check(r.IN)){this.advance();let n=this.expect(r.IDENT).value;return{type:"in",key:t,array:n}}return t}parseConcatenation(){let t=this.parseMatch();for(;this.canStartExpression()&&!this.isConcatTerminator();){let n=this.parseMatch();t={type:"binary",operator:" ",left:t,right:n}}return t}parseMatch(){let t=this.parseComparison();for(;this.match(r.MATCH,r.NOT_MATCH);){let n=this.advance().type===r.MATCH?"~":"!~",i=this.parseComparison();t={type:"binary",operator:n,left:t,right:i}}return t}parseComparison(){let t=this.parseAddSub();for(;this.match(r.LT,r.LE,r.GT,r.GE,r.EQ,r.NE);){let n=this.advance(),i=this.parseAddSub();t={type:"binary",operator:{"<":"<","<=":"<=",">":">",">=":">=","==":"==","!=":"!="}[n.value],left:t,right:i}}return t}canStartExpression(){return this.match(r.NUMBER,r.STRING,r.IDENT,r.DOLLAR,r.LPAREN,r.NOT,r.MINUS,r.PLUS,r.INCREMENT,r.DECREMENT)}isConcatTerminator(){return this.match(r.AND,r.OR,r.QUESTION,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.COMMA,r.SEMICOLON,r.NEWLINE,r.RBRACE,r.RPAREN,r.RBRACKET,r.COLON,r.PIPE,r.APPEND,r.IN)}parseAddSub(){let t=this.parseMulDiv();for(;this.match(r.PLUS,r.MINUS);){let n=this.advance().value,i=this.parseMulDiv();t={type:"binary",operator:n,left:t,right:i}}return t}parseMulDiv(){let t=this.parseUnary();for(;this.match(r.STAR,r.SLASH,r.PERCENT);){let n=this.advance(),i=this.parseUnary();t={type:"binary",operator:{"*":"*","/":"/","%":"%"}[n.value],left:t,right:i}}return t}parseUnary(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseUnary();return{type:"unary",operator:t,operand:n}}return this.parsePower()}parsePower(){let t=this.parsePostfix();if(this.check(r.CARET)){this.advance();let n=this.parsePower();t={type:"binary",operator:"^",left:t,right:n}}return t}parsePostfix(){let t=this.parsePrimary();if(this.check(r.INCREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid increment operand");return{type:"post_increment",operand:t}}if(this.check(r.DECREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid decrement operand");return{type:"post_decrement",operand:t}}return t}parseFieldIndex(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseFieldIndex();return{type:"unary",operator:t,operand:n}}return this.parseFieldIndexPower()}parseFieldIndexPower(){let t=this.parseFieldIndexPrimary();if(this.check(r.CARET)){this.advance();let n=this.parseFieldIndexPower();t={type:"binary",operator:"^",left:t,right:n}}return t}parseFieldIndexPrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();return this.expect(r.RPAREN),t}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=this.parseExpression();if(this.check(r.COMMA)){let i=[n];for(;this.check(r.COMMA);)this.advance(),i.push(this.parseExpression());this.expect(r.RBRACKET);let a=i.reduce((s,o)=>({type:"binary",operator:" ",left:{type:"binary",operator:" ",left:s,right:{type:"variable",name:"SUBSEP"}},right:o}));return{type:"array_access",array:t,key:a}}return this.expect(r.RBRACKET),{type:"array_access",array:t,key:n}}return{type:"variable",name:t}}throw new Error(`Unexpected token in field index: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}parsePrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();if(this.check(r.COMMA)){let n=[t];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"tuple",elements:n}}return this.expect(r.RPAREN),t}if(this.check(r.GETLINE)){this.advance();let t,n;return this.check(r.IDENT)&&(t=this.advance().value),this.check(r.LT)&&(this.advance(),n=this.parsePrimary()),{type:"getline",variable:t,file:n}}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(this.skipNewlines(),!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseExpression());return this.skipNewlines(),this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=[this.parseExpression()];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());this.expect(r.RBRACKET);let i;if(n.length===1)i=n[0];else{i=n[0];for(let a=1;a<n.length;a++)i={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:i,right:{type:"variable",name:"SUBSEP"}},right:n[a]}}return{type:"array_access",array:t,key:i}}return{type:"variable",name:t}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}};var Mt={name:"awk",summary:"pattern scanning and text processing language",usage:"awk [OPTIONS] 'PROGRAM' [FILE...]",options:["-F FS use FS as field separator","-v VAR=VAL assign VAL to variable VAR"," --help display this help and exit"]},kn={name:"awk",async execute(e,t){if(ie(e))return re(Mt);let n=new P(/\s+/),i=" ",a=Object.create(null),s=0;for(let c=0;c<e.length;c++){let p=e[c];if(p==="-F"&&c+1<e.length)i=te(e[++c]),n=ke(i),s=c+1;else if(p.startsWith("-F"))i=te(p.slice(2)),n=ke(i),s=c+1;else if(p==="-v"&&c+1<e.length){let E=e[++c],d=E.indexOf("=");if(d>0){let R=E.slice(0,d),O=te(E.slice(d+1));a[R]=O}s=c+1}else{if(p.startsWith("--"))return j("awk",p);if(p.startsWith("-")&&p.length>1){let E=p[1];if(E!=="F"&&E!=="v")return j("awk",`-${E}`);s=c+1}else if(!p.startsWith("-")){s=c;break}}}if(s>=e.length)return{stdout:"",stderr:`awk: missing program
14
- `,exitCode:1};let o=e[s],l=e.slice(s+1),h=new X,N;try{N=h.parse(o)}catch(c){return{stdout:"",stderr:`awk: ${c instanceof Error?c.message:String(c)}
15
- `,exitCode:1}}let k={readFile:t.fs.readFile.bind(t.fs),writeFile:t.fs.writeFile.bind(t.fs),appendFile:async(c,p)=>{try{let E=await t.fs.readFile(c);await t.fs.writeFile(c,E+p)}catch{await t.fs.writeFile(c,p)}},resolvePath:t.fs.resolvePath.bind(t.fs)},y=Q({fieldSep:n,maxIterations:t.limits?.maxAwkIterations,fs:k,cwd:t.cwd,exec:t.exec?c=>t.exec(c,{cwd:t.cwd}):void 0});y.FS=i,y.vars=Object.assign(Object.create(null),a),y.ARGC=l.length+1,y.ARGV=Object.create(null),y.ARGV[0]="awk";for(let c=0;c<l.length;c++)y.ARGV[String(c+1)]=l[c];y.ENVIRON=se(t.env);let I=new D(y);I.execute(N);let ne=N.rules.some(c=>c.pattern?.type!=="begin"&&c.pattern?.type!=="end"),w=N.rules.some(c=>c.pattern?.type==="end");try{if(await I.executeBegin(),y.shouldExit)return await I.executeEnd(),{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()};if(!ne&&!w)return{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()};let c=[];if(l.length>0)for(let p of l)try{let E=t.fs.resolvePath(t.cwd,p),R=(await t.fs.readFile(E)).split(`
16
- `);R.length>0&&R[R.length-1]===""&&R.pop(),c.push({filename:p,lines:R})}catch{return{stdout:"",stderr:`awk: ${p}: No such file or directory
17
- `,exitCode:1}}else{let p=t.stdin.split(`
18
- `);p.length>0&&p[p.length-1]===""&&p.pop(),c.push({filename:"",lines:p})}for(let p of c){for(y.FILENAME=p.filename,y.FNR=0,y.lines=p.lines,y.lineIndex=-1,y.shouldNextFile=!1;y.lineIndex<p.lines.length-1&&(y.lineIndex++,await I.executeLine(p.lines[y.lineIndex]),!(y.shouldExit||y.shouldNextFile)););if(y.shouldExit)break}return await I.executeEnd(),{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()}}catch(c){let p=c instanceof Error?c.message:String(c),E=c instanceof b?b.EXIT_CODE:2;return{stdout:I.getOutput(),stderr:`awk: ${p}
19
- `,exitCode:E}}}};function te(e){return e.replace(/\\t/g," ").replace(/\\n/g,`
20
- `).replace(/\\r/g,"\r").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\a/g,"\x07").replace(/\\v/g,"\v").replace(/\\\\/g,"\\")}function ke(e){if(e===" ")return m("\\s+");if(/[[\](){}.*+?^$|\\]/.test(e))try{return m(e)}catch{return m(Ce(e))}return m(Ce(e))}function Ce(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}export{kn as awkCommand2};
@@ -1,8 +0,0 @@
1
- import{a as $,b as m,c as C}from"./chunk-74CEPOFO.js";var k={sha1:"SHA-1",sha256:"SHA-256"};function L(n){function h(a,u){return a<<u|a>>>32-u}let p=new Uint32Array([3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745]),A=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],g=n.length*8,o=(n.length%64<56?56:120)-n.length%64,s=new Uint8Array(n.length+o+8);s.set(n),s[n.length]=128;let d=new DataView(s.buffer);d.setUint32(s.length-8,g>>>0,!0),d.setUint32(s.length-4,Math.floor(g/4294967296),!0);let b=1732584193,l=4023233417,w=2562383102,e=271733878;for(let a=0;a<s.length;a+=64){let u=new Uint32Array(16);for(let t=0;t<16;t++)u[t]=d.getUint32(a+t*4,!0);let y=b,r=l,x=w,c=e;for(let t=0;t<64;t++){let i,U;t<16?(i=r&x|~r&c,U=t):t<32?(i=c&r|~c&x,U=(5*t+1)%16):t<48?(i=r^x^c,U=(3*t+5)%16):(i=x^(r|~c),U=7*t%16),i=i+y+p[t]+u[U]>>>0,y=c,c=x,x=r,r=r+h(i,A[t])>>>0}b=b+y>>>0,l=l+r>>>0,w=w+x>>>0,e=e+c>>>0}let f=new Uint8Array(16);return new DataView(f.buffer).setUint32(0,b,!0),new DataView(f.buffer).setUint32(4,l,!0),new DataView(f.buffer).setUint32(8,w,!0),new DataView(f.buffer).setUint32(12,e,!0),Array.from(f).map(a=>a.toString(16).padStart(2,"0")).join("")}async function F(n,h){if(n==="md5")return L(h);let p=await globalThis.crypto.subtle.digest(k[n],new Uint8Array(h).buffer);return Array.from(new Uint8Array(p)).map(A=>A.toString(16).padStart(2,"0")).join("")}function S(n,h,p){let A={name:n,summary:p,usage:`${n} [OPTION]... [FILE]...`,options:["-c, --check read checksums from FILEs and check them"," --help display this help and exit"]};return{name:n,async execute(g,o){if(m(g))return $(A);let s=!1,d=[];for(let e of g)if(e==="-c"||e==="--check")s=!0;else if(!(e==="-b"||e==="-t"||e==="--binary"||e==="--text")){if(e.startsWith("-")&&e!=="-")return C(n,e);d.push(e)}d.length===0&&d.push("-");let b=async e=>{if(e==="-")return Uint8Array.from(o.stdin,f=>f.charCodeAt(0));try{return await o.fs.readFileBuffer(o.fs.resolvePath(o.cwd,e))}catch{return null}};if(s){let e=0,f="";for(let a of d){let u=a==="-"?o.stdin:await o.fs.readFile(o.fs.resolvePath(o.cwd,a)).catch(()=>null);if(u===null)return{stdout:"",stderr:`${n}: ${a}: No such file or directory
2
- `,exitCode:1};for(let y of u.split(`
3
- `)){let r=y.match(/^([a-fA-F0-9]+)\s+[* ]?(.+)$/);if(!r)continue;let[,x,c]=r,t=await b(c);if(t===null){f+=`${c}: FAILED open or read
4
- `,e++;continue}let i=await F(h,t)===x.toLowerCase();f+=`${c}: ${i?"OK":"FAILED"}
5
- `,i||e++}}return e>0&&(f+=`${n}: WARNING: ${e} computed checksum${e>1?"s":""} did NOT match
6
- `),{stdout:f,stderr:"",exitCode:e>0?1:0}}let l="",w=0;for(let e of d){let f=await b(e);if(f===null){l+=`${n}: ${e}: No such file or directory
7
- `,w=1;continue}l+=`${await F(h,f)} ${e}
8
- `}return{stdout:l,stderr:"",exitCode:w}}}}export{S as a};
@@ -1,16 +0,0 @@
1
- import{a as N}from"./chunk-YNYSPYQ5.js";function B(n,t){return n.replace(/\$(&|\d+|<([^>]+)>)/g,(e,i,s)=>{if(i==="&")return t[0];if(s!==void 0)return t.groups?.[s]??"";let h=parseInt(i,10);return t[h]??""})}function D(n,t,e={}){let{invertMatch:i=!1,showLineNumbers:s=!1,countOnly:h=!1,countMatches:d=!1,filename:a="",onlyMatching:m=!1,beforeContext:I=0,afterContext:R=0,maxCount:S=0,contextSeparator:F="--",showColumn:O=!1,vimgrep:G=!1,showByteOffset:P=!1,replace:k=null,passthru:y=!1,multiline:j=!1,kResetGroup:A}=e;if(j)return Q(n,t,{invertMatch:i,showLineNumbers:s,countOnly:h,countMatches:d,filename:a,onlyMatching:m,beforeContext:I,afterContext:R,maxCount:S,contextSeparator:F,showColumn:O,showByteOffset:P,replace:k,kResetGroup:A});let x=n.split(`
2
- `),Z=x.length,v=Z>0&&x[Z-1]===""?Z-1:Z;if(h||d){let f=0,r=(d||m)&&!i;for(let l=0;l<v;l++)if(t.lastIndex=0,r)for(let u=t.exec(x[l]);u!==null;u=t.exec(x[l]))f++,u[0].length===0&&t.lastIndex++;else t.test(x[l])!==i&&f++;return{output:`${a?`${a}:${f}`:String(f)}
3
- `,matched:f>0,matchCount:f}}if(I===0&&R===0&&!y){let f=[],r=!1,o=0,l=0;for(let u=0;u<v&&!(S>0&&o>=S);u++){let L=x[u];if(t.lastIndex=0,t.test(L)!==i)if(r=!0,o++,m){t.lastIndex=0;for(let $=t.exec(L);$!==null;$=t.exec(L)){let b=A!==void 0?$[A]??"":$[0],T=k!==null?B(k,$):b,z=a?`${a}:`:"";P&&(z+=`${l+$.index}:`),s&&(z+=`${u+1}:`),O&&(z+=`${$.index+1}:`),f.push(z+T),$[0].length===0&&t.lastIndex++}}else if(G){t.lastIndex=0;for(let $=t.exec(L);$!==null;$=t.exec(L)){let b=a?`${a}:`:"";P&&(b+=`${l+$.index}:`),s&&(b+=`${u+1}:`),O&&(b+=`${$.index+1}:`),f.push(b+L),$[0].length===0&&t.lastIndex++}}else{t.lastIndex=0;let $=t.exec(L),b=$?$.index+1:1,T=L;k!==null&&(t.lastIndex=0,T=t.replace(L,(...M)=>{if(M[0].length===0)return"";let U=M,_=M[M.length-1];return typeof _=="object"&&_!==null?(U.groups=_,U.input=M[M.length-2],U.index=M[M.length-3]):(U.input=M[M.length-1],U.index=M[M.length-2]),B(k,U)}));let z=a?`${a}:`:"";P&&(z+=`${l+($?$.index:0)}:`),s&&(z+=`${u+1}:`),O&&(z+=`${b}:`),f.push(z+T)}l+=L.length+1}return{output:f.length>0?`${f.join(`
4
- `)}
5
- `:"",matched:r,matchCount:o}}if(y){let f=[],r=!1,o=0;for(let l=0;l<v;l++){let u=x[l];t.lastIndex=0;let E=t.test(u)!==i;E&&(r=!0,o++);let $=E?":":"-",b=a?`${a}${$}`:"";s&&(b+=`${l+1}${$}`),f.push(b+u)}return{output:f.length>0?`${f.join(`
6
- `)}
7
- `:"",matched:r,matchCount:o}}let g=[],w=0,p=new Set,C=-1,c=[];for(let f=0;f<v&&!(S>0&&w>=S);f++)t.lastIndex=0,t.test(x[f])!==i&&(c.push(f),w++);for(let f of c){let r=Math.max(0,f-I);C>=0&&r>C+1&&g.push(F);for(let l=r;l<f;l++)if(!p.has(l)){p.add(l),C=l;let u=x[l];s&&(u=`${l+1}-${u}`),a&&(u=`${a}-${u}`),g.push(u)}if(!p.has(f)){p.add(f),C=f;let l=x[f];if(m){t.lastIndex=0;for(let u=t.exec(l);u!==null;u=t.exec(l)){let L=A!==void 0?u[A]??"":u[0],E=k!==null?k:L,$=a?`${a}:`:"";s&&($+=`${f+1}:`),O&&($+=`${u.index+1}:`),g.push($+E),u[0].length===0&&t.lastIndex++}}else{let u=l;s&&(u=`${f+1}:${u}`),a&&(u=`${a}:${u}`),g.push(u)}}let o=Math.min(v-1,f+R);for(let l=f+1;l<=o;l++)if(!p.has(l)){p.add(l),C=l;let u=x[l];s&&(u=`${l+1}-${u}`),a&&(u=`${a}-${u}`),g.push(u)}}return{output:g.length>0?`${g.join(`
8
- `)}
9
- `:"",matched:w>0,matchCount:w}}function Q(n,t,e){let{invertMatch:i,showLineNumbers:s,countOnly:h,countMatches:d,filename:a,onlyMatching:m,beforeContext:I,afterContext:R,maxCount:S,contextSeparator:F,showColumn:O,showByteOffset:G,replace:P,kResetGroup:k}=e,y=n.split(`
10
- `),j=y.length,A=j>0&&y[j-1]===""?j-1:j,x=[0];for(let c=0;c<n.length;c++)n[c]===`
11
- `&&x.push(c+1);let Z=c=>{let f=0;for(let r=0;r<x.length&&!(x[r]>c);r++)f=r;return f},v=c=>{let f=Z(c);return c-x[f]+1},g=[];t.lastIndex=0;for(let c=t.exec(n);c!==null&&!(S>0&&g.length>=S);c=t.exec(n)){let f=Z(c.index),r=Z(c.index+Math.max(0,c[0].length-1)),o=k!==void 0?c[k]??"":c[0];g.push({startLine:f,endLine:r,byteOffset:c.index,column:v(c.index),matchText:o}),c[0].length===0&&t.lastIndex++}if(h||d){let c;if(d)c=i?0:g.length;else{let r=new Set;for(let o of g)for(let l=o.startLine;l<=o.endLine;l++)r.add(l);c=i?A-r.size:r.size}return{output:`${a?`${a}:${c}`:String(c)}
12
- `,matched:c>0,matchCount:c}}if(i){let c=new Set;for(let r of g)for(let o=r.startLine;o<=r.endLine;o++)c.add(o);let f=[];for(let r=0;r<A;r++)if(!c.has(r)){let o=y[r];s&&(o=`${r+1}:${o}`),a&&(o=`${a}:${o}`),f.push(o)}return{output:f.length>0?`${f.join(`
13
- `)}
14
- `:"",matched:f.length>0,matchCount:f.length}}if(g.length===0)return{output:"",matched:!1,matchCount:0};let w=new Set,p=-1,C=[];for(let c of g){let f=Math.max(0,c.startLine-I),r=Math.min(A-1,c.endLine+R);p>=0&&f>p+1&&C.push(F);for(let o=f;o<c.startLine;o++)if(!w.has(o)){w.add(o),p=o;let l=y[o];s&&(l=`${o+1}-${l}`),a&&(l=`${a}-${l}`),C.push(l)}if(m){let o=P!==null?P:c.matchText,l=a?`${a}:`:"";G&&(l+=`${c.byteOffset}:`),s&&(l+=`${c.startLine+1}:`),O&&(l+=`${c.column}:`),C.push(l+o);for(let u=c.startLine;u<=c.endLine;u++)w.add(u),p=u}else for(let o=c.startLine;o<=c.endLine&&o<A;o++)if(!w.has(o)){w.add(o),p=o;let l=y[o];P!==null&&o===c.startLine&&(t.lastIndex=0,l=t.replace(l,P));let u=a?`${a}:`:"";G&&o===c.startLine&&(u+=`${c.byteOffset}:`),s&&(u+=`${o+1}:`),O&&o===c.startLine&&(u+=`${c.column}:`),C.push(u+l)}for(let o=c.endLine+1;o<=r;o++)if(!w.has(o)){w.add(o),p=o;let l=y[o];s&&(l=`${o+1}-${l}`),a&&(l=`${a}-${l}`),C.push(l)}}return{output:C.length>0?`${C.join(`
15
- `)}
16
- `:"",matched:!0,matchCount:g.length}}var q={alpha:"a-zA-Z",digit:"0-9",alnum:"a-zA-Z0-9",lower:"a-z",upper:"A-Z",xdigit:"0-9A-Fa-f",space:" \\t\\n\\r\\f\\v",blank:" \\t",punct:"!-/:-@\\[-`{-~",graph:"!-~",print:" -~",cntrl:"\\x00-\\x1F\\x7F",ascii:"\\x00-\\x7F",word:"a-zA-Z0-9_"};function K(n){let t="",e=0;for(;e<n.length;){if(n.slice(e,e+7)==="[[:<:]]"){t+="\\b",e+=7;continue}if(n.slice(e,e+7)==="[[:>:]]"){t+="\\b",e+=7;continue}if(n[e]==="["){let i="[";for(e++,e<n.length&&(n[e]==="^"||n[e]==="!")&&(i+="^",e++),e<n.length&&n[e]==="]"&&(i+="\\]",e++);e<n.length&&n[e]!=="]";){if(n[e]==="["&&e+1<n.length&&n[e+1]===":"){let s=n.indexOf(":]",e+2);if(s!==-1){let h=n.slice(e+2,s),d=q[h];if(d){i+=d,e=s+2;continue}}}if(n[e]==="\\"&&e+1<n.length){i+=n[e]+n[e+1],e+=2;continue}i+=n[e],e++}e<n.length&&n[e]==="]"&&(i+="]",e++),t+=i;continue}if(n[e]==="\\"&&e+1<n.length){t+=n[e]+n[e+1],e+=2;continue}t+=n[e],e++}return t}function W(n,t){let e,i;switch(t.mode){case"fixed":e=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");break;case"extended":case"perl":{if(e=K(n),e=e.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),t.mode==="perl"){e=X(e),e=H(e),e=J(e);let d=ne(e);e=d.pattern,i=d.kResetGroup}break}default:e=K(n),e=se(e);break}t.wholeWord&&(e=`\\b(?:${e})\\b`),t.lineRegexp&&(e=`^${e}$`);let s=/\\u\{[0-9A-Fa-f]+\}/.test(e),h="g"+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.multilineDotall?"s":"")+(s?"u":"");return{regex:N(e,h),kResetGroup:i}}function X(n){let t="",e=0;for(;e<n.length;)if(n[e]==="\\"&&e+1<n.length&&n[e+1]==="Q"){e+=2;let i="";for(;e<n.length;){if(n[e]==="\\"&&e+1<n.length&&n[e+1]==="E"){e+=2;break}i+=n[e],e++}t+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}else t+=n[e],e++;return t}function H(n){return n.replace(/\\x\{([0-9A-Fa-f]+)\}/g,"\\u{$1}")}function J(n){let t="",e=0;for(;e<n.length;){if(n[e]==="("&&e+1<n.length&&n[e+1]==="?"){let i=n.slice(e).match(/^\(\?([imsx]*)(-[imsx]*)?(:|$|\))/);if(i){let s=i[1]||"",h=i[2]||"",d=i[3];if(d===":"){let a=e+i[0].length-1,m=V(n,e);if(m!==-1){let I=n.slice(a+1,m),R=Y(I,s,h);t+=`(?:${R})`,e=m+1;continue}}else if(d===")"||d===""){e+=i[0].length;continue}}}t+=n[e],e++}return t}function V(n,t){let e=0,i=t;for(;i<n.length;){if(n[i]==="\\"){i+=2;continue}if(n[i]==="["){for(i++;i<n.length&&n[i]!=="]";)n[i]==="\\"&&i++,i++;i++;continue}if(n[i]==="(")e++;else if(n[i]===")"&&(e--,e===0))return i;i++}return-1}function Y(n,t,e){let i=n;return t.includes("i")&&(i=ee(i)),i}function ee(n){let t="",e=0;for(;e<n.length;){let i=n[e];if(i==="\\"){e+1<n.length?(t+=i+n[e+1],e+=2):(t+=i,e++);continue}if(i==="["){t+=i,e++,e<n.length&&n[e]==="^"&&(t+=n[e],e++);let s=[];for(;e<n.length&&n[e]!=="]";)if(n[e]==="\\")s.push(n[e]),e++,e<n.length&&(s.push(n[e]),e++);else if(n[e]==="-"&&s.length>0&&e+1<n.length&&n[e+1]!=="]"){let h=s[s.length-1],d=n[e+1];s.push("-"),s.push(d),/[a-z]/.test(h)&&/[a-z]/.test(d)?(s.push(h.toUpperCase()),s.push("-"),s.push(d.toUpperCase())):/[A-Z]/.test(h)&&/[A-Z]/.test(d)&&(s.push(h.toLowerCase()),s.push("-"),s.push(d.toLowerCase())),e+=2}else{let h=n[e];if(s.push(h),/[a-zA-Z]/.test(h)){let d=h===h.toLowerCase()?h.toUpperCase():h.toLowerCase();s.includes(d)||s.push(d)}e++}t+=s.join(""),e<n.length&&(t+=n[e],e++);continue}if(/[a-zA-Z]/.test(i)){let s=i.toLowerCase(),h=i.toUpperCase();t+=`[${h}${s}]`}else t+=i;e++}return t}function ne(n){let t=te(n);if(t===-1)return{pattern:n};let e=n.slice(0,t),i=n.slice(t+2),s=ie(e);return{pattern:`(?:${e})(${i})`,kResetGroup:s+1}}function te(n){let t=0;for(;t<n.length-1;)if(n[t]==="\\"){if(n[t+1]==="K"){let e=0,i=t-1;for(;i>=0&&n[i]==="\\";)e++,i--;if(e%2===0)return t}t+=2}else t++;return-1}function ie(n){let t=0,e=0;for(;e<n.length;){if(n[e]==="\\"){e+=2;continue}if(n[e]==="["){for(e++;e<n.length&&n[e]!=="]";)n[e]==="\\"&&e++,e++;e++;continue}if(n[e]==="(")if(e+1<n.length&&n[e+1]==="?"){if(e+2<n.length){let i=n[e+2];if(i===":"||i==="="||i==="!"){e++;continue}if(i==="<"&&e+3<n.length){let s=n[e+3];if(s==="="||s==="!"){e++;continue}t++,e++;continue}}}else t++;e++}return t}function le(n){let t=n.replace(/\$\{0\}|\$0(?![0-9])/g,"$$&");return t=t.replace(/\$\{([^0-9}][^}]*)\}/g,"$$<$1>"),t=t.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)(?![>0-9])/g,"$$<$1>"),t}function se(n){let t="",e=0,i=!0,s=0;for(;e<n.length;){let h=n[e];if(h==="["){for(t+=h,e++,e<n.length&&(n[e]==="^"||n[e]==="!")&&(t+=n[e],e++),e<n.length&&n[e]==="]"&&(t+=n[e],e++);e<n.length&&n[e]!=="]";)n[e]==="\\"&&e+1<n.length?(t+=n[e]+n[e+1],e+=2):(t+=n[e],e++);e<n.length&&n[e]==="]"&&(t+=n[e],e++),i=!1;continue}if(h==="\\"&&e+1<n.length){let d=n[e+1];if(d==="|"){t+="|",e+=2,i=!0;continue}if(d==="("){t+="(",e+=2,s++,i=!0;continue}if(d===")"){t+=")",e+=2,s=Math.max(0,s-1),i=!1;continue}if(d==="{"){let m=n.slice(e).match(/^\\{(\d+)(,(\d*)?)?\\}/);if(m){let I=m[1],R=m[2]!==void 0,S=m[3]||"";R?t+=`{${I},${S}}`:t+=`{${I}}`,e+=m[0].length,i=!1;continue}t+="\\{",e+=2,i=!1;continue}if(d==="}"){t+="\\}",e+=2,i=!1;continue}t+=h+d,e+=2,i=!1;continue}if(h==="*"&&i){t+="\\*",e++;continue}if(h==="^"){if(i){t+="^",e++;continue}t+="\\^",e++;continue}if(h==="$"){let d=e===n.length-1,a=e+2<n.length&&n[e+1]==="\\"&&n[e+2]===")";d||a?t+="$":t+="\\$",e++,i=!1;continue}h==="+"||h==="?"||h==="|"||h==="("||h===")"||h==="{"||h==="}"?t+=`\\${h}`:t+=h,e++,i=!1}return t}export{D as a,W as b,le as c};
@@ -1,15 +0,0 @@
1
- import"./chunk-DXB73IDG.js";var r={"File operations":["ls","cat","head","tail","wc","touch","mkdir","rm","cp","mv","ln","chmod","stat","readlink"],"Text processing":["grep","sed","awk","sort","uniq","cut","tr","tee","diff"],Search:["find"],"Navigation & paths":["pwd","basename","dirname","tree","du"],"Environment & shell":["echo","printf","env","printenv","export","alias","unalias","history","clear","true","false","bash","sh"],"Data processing":["xargs","jq","base64","date"],Network:["curl","html-to-markdown"]};function l(t){let e=[],n=new Set(t);e.push(`Available commands:
2
- `);let s=[];for(let[o,c]of Object.entries(r)){let a=c.filter(i=>n.has(i));if(a.length>0){e.push(` ${o}:`),e.push(` ${a.join(", ")}
3
- `);for(let i of a)n.delete(i)}}for(let o of n)s.push(o);return s.length>0&&(e.push(" Other:"),e.push(` ${s.sort().join(", ")}
4
- `)),e.push("Use '<command> --help' for details on a specific command."),`${e.join(`
5
- `)}
6
- `}var d={name:"help",async execute(t,e){if(t.includes("--help")||t.includes("-h"))return{stdout:`help - display available commands
7
-
8
- Usage: help [command]
9
-
10
- Options:
11
- -h, --help Show this help message
12
-
13
- If a command name is provided, shows help for that command.
14
- Otherwise, lists all available commands.
15
- `,stderr:"",exitCode:0};if(t.length>0&&e.exec){let s=t[0];return e.exec(`${s} --help`,{cwd:e.cwd})}let n=e.getRegisteredCommands?.()??[];return{stdout:l(n),stderr:"",exitCode:0}}};export{d as helpCommand};
@@ -1,15 +0,0 @@
1
- import{b as O}from"./chunk-7L36YK2X.js";import"./chunk-NUFRM6SI.js";import{a as F,b as N,c as k}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var P={"":1,k:1024,m:1048576,g:1073741824,t:1099511627776,p:0x4000000000000,e:1152921504606847e3},V={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12};function w(u){let r=u.trim(),e=r.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!e){let n=parseFloat(r);return Number.isNaN(n)?0:n}let l=parseFloat(e[1]),s=(e[2]||"").toLowerCase(),i=P[s]||1;return l*i}function L(u){let r=u.trim().toLowerCase().slice(0,3);return V[r]||0}function D(u,r){let e=u.split(/(\d+)/),l=r.split(/(\d+)/),s=Math.max(e.length,l.length);for(let i=0;i<s;i++){let n=e[i]||"",d=l[i]||"",o=/^\d+$/.test(n)?parseInt(n,10):null,c=/^\d+$/.test(d)?parseInt(d,10):null;if(o!==null&&c!==null){if(o!==c)return o-c}else if(n!==d)return n.localeCompare(d)}return 0}function x(u){return u.replace(/[^a-zA-Z0-9\s]/g,"")}function v(u,r,e){let l=e!==null?e:/\s+/,s=u.split(l),i=r.startField-1;if(i>=s.length)return"";if(r.endField===void 0){let o=s[i]||"";return r.startChar!==void 0&&(o=o.slice(r.startChar-1)),r.ignoreLeading&&(o=o.trimStart()),o}let n=Math.min(r.endField-1,s.length-1),d="";for(let o=i;o<=n&&o<s.length;o++){let c=s[o]||"";if(o===i&&r.startChar!==void 0&&(c=c.slice(r.startChar-1)),o===n&&r.endChar!==void 0){let t=o===i&&r.startChar!==void 0?r.endChar-r.startChar+1:r.endChar;c=c.slice(0,t)}o>i&&(d+=e||" "),d+=c}return r.ignoreLeading&&(d=d.trimStart()),d}function I(u,r,e){let l=u,s=r;if(e.dictionaryOrder&&(l=x(l),s=x(s)),e.ignoreCase&&(l=l.toLowerCase(),s=s.toLowerCase()),e.monthSort){let i=L(l),n=L(s);return i-n}if(e.humanNumeric){let i=w(l),n=w(s);return i-n}if(e.versionSort)return D(l,s);if(e.numeric){let i=parseFloat(l)||0,n=parseFloat(s)||0;return i-n}return l.localeCompare(s)}function M(u){let{keys:r,fieldDelimiter:e,numeric:l,ignoreCase:s,reverse:i,humanNumeric:n,versionSort:d,dictionaryOrder:o,monthSort:c,ignoreLeadingBlanks:t,stable:a}=u;return(f,S)=>{let g=f,b=S;if(t&&(g=g.trimStart(),b=b.trimStart()),r.length===0){let h=I(g,b,{numeric:l,ignoreCase:s,humanNumeric:n,versionSort:d,dictionaryOrder:o,monthSort:c});if(h!==0)return i?-h:h;if(!a){let p=f.localeCompare(S);return i?-p:p}return 0}for(let m of r){let h=v(g,m,e),p=v(b,m,e);m.ignoreLeading&&(h=h.trimStart(),p=p.trimStart());let B={numeric:m.numeric??l,ignoreCase:m.ignoreCase??s,humanNumeric:m.humanNumeric??n,versionSort:m.versionSort??d,dictionaryOrder:m.dictionaryOrder??o,monthSort:m.monthSort??c},A=m.reverse??i,y=I(h,p,B);if(y!==0)return A?-y:y}if(!a){let m=f.localeCompare(S);return i?-m:m}return 0}}function E(u,r){if(r.keys.length===0){if(r.ignoreCase){let s=new Set;return u.filter(i=>{let n=i.toLowerCase();return s.has(n)?!1:(s.add(n),!0)})}return[...new Set(u)]}let e=r.keys[0],l=new Set;return u.filter(s=>{let i=v(s,e,r.fieldDelimiter);return(e.ignoreCase??r.ignoreCase)&&(i=i.toLowerCase()),l.has(i)?!1:(l.add(i),!0)})}function C(u){let r={startField:1},e="",l=u,s=l.match(/([bdfhMnrV]+)$/);s&&(e=s[1],l=l.slice(0,-e.length)),e.includes("n")&&(r.numeric=!0),e.includes("r")&&(r.reverse=!0),e.includes("f")&&(r.ignoreCase=!0),e.includes("b")&&(r.ignoreLeading=!0),e.includes("h")&&(r.humanNumeric=!0),e.includes("V")&&(r.versionSort=!0),e.includes("d")&&(r.dictionaryOrder=!0),e.includes("M")&&(r.monthSort=!0);let i=l.split(",");if(i.length===0||i[0]==="")return null;let n=i[0].split("."),d=parseInt(n[0],10);if(Number.isNaN(d)||d<1)return null;if(r.startField=d,n.length>1&&n[1]){let o=parseInt(n[1],10);!Number.isNaN(o)&&o>=1&&(r.startChar=o)}if(i.length>1&&i[1]){let o=i[1],c=o.match(/([bdfhMnrV]+)$/);if(c){let a=c[1];a.includes("n")&&(r.numeric=!0),a.includes("r")&&(r.reverse=!0),a.includes("f")&&(r.ignoreCase=!0),a.includes("b")&&(r.ignoreLeading=!0),a.includes("h")&&(r.humanNumeric=!0),a.includes("V")&&(r.versionSort=!0),a.includes("d")&&(r.dictionaryOrder=!0),a.includes("M")&&(r.monthSort=!0),o=o.slice(0,-a.length)}let t=o.split(".");if(t[0]){let a=parseInt(t[0],10);if(!Number.isNaN(a)&&a>=1&&(r.endField=a),t.length>1&&t[1]){let f=parseInt(t[1],10);!Number.isNaN(f)&&f>=1&&(r.endChar=f)}}}return r}var q={name:"sort",summary:"sort lines of text files",usage:"sort [OPTION]... [FILE]...",options:["-b, --ignore-leading-blanks ignore leading blanks","-d, --dictionary-order consider only blanks and alphanumeric characters","-f, --ignore-case fold lower case to upper case characters","-h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)","-M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC'","-n, --numeric-sort compare according to string numerical value","-r, --reverse reverse the result of comparisons","-V, --version-sort natural sort of (version) numbers within text","-c, --check check for sorted input; do not sort","-o, --output=FILE write result to FILE instead of stdout","-s, --stable stabilize sort by disabling last-resort comparison","-u, --unique output only unique lines","-k, --key=KEYDEF sort via a key; KEYDEF gives location and type","-t, --field-separator=SEP use SEP as field separator"," --help display this help and exit"],description:`KEYDEF is F[.C][OPTS][,F[.C][OPTS]]
2
- F is a field number (1-indexed)
3
- C is a character position within the field (1-indexed)
4
- OPTS can be: b d f h M n r V (per-key modifiers)
5
-
6
- Examples:
7
- -k1 sort by first field
8
- -k2,2 sort by second field only
9
- -k1.3 sort by first field starting at 3rd character
10
- -k1,2n sort by fields 1-2 numerically
11
- -k2 -k1 sort by field 2, then by field 1`},j={name:"sort",async execute(u,r){if(N(u))return F(q);let e={reverse:!1,numeric:!1,unique:!1,ignoreCase:!1,humanNumeric:!1,versionSort:!1,dictionaryOrder:!1,monthSort:!1,ignoreLeadingBlanks:!1,stable:!1,checkOnly:!1,outputFile:null,keys:[],fieldDelimiter:null},l=[];for(let c=0;c<u.length;c++){let t=u[c];if(t==="-r"||t==="--reverse")e.reverse=!0;else if(t==="-n"||t==="--numeric-sort")e.numeric=!0;else if(t==="-u"||t==="--unique")e.unique=!0;else if(t==="-f"||t==="--ignore-case")e.ignoreCase=!0;else if(t==="-h"||t==="--human-numeric-sort")e.humanNumeric=!0;else if(t==="-V"||t==="--version-sort")e.versionSort=!0;else if(t==="-d"||t==="--dictionary-order")e.dictionaryOrder=!0;else if(t==="-M"||t==="--month-sort")e.monthSort=!0;else if(t==="-b"||t==="--ignore-leading-blanks")e.ignoreLeadingBlanks=!0;else if(t==="-s"||t==="--stable")e.stable=!0;else if(t==="-c"||t==="--check")e.checkOnly=!0;else if(t==="-o"||t==="--output")e.outputFile=u[++c]||null;else if(t.startsWith("-o"))e.outputFile=t.slice(2)||null;else if(t.startsWith("--output="))e.outputFile=t.slice(9)||null;else if(t==="-t"||t==="--field-separator")e.fieldDelimiter=u[++c]||null;else if(t.startsWith("-t"))e.fieldDelimiter=t.slice(2)||null;else if(t.startsWith("--field-separator="))e.fieldDelimiter=t.slice(18)||null;else if(t==="-k"||t==="--key"){let a=u[++c];if(a){let f=C(a);f&&e.keys.push(f)}}else if(t.startsWith("-k")){let a=C(t.slice(2));a&&e.keys.push(a)}else if(t.startsWith("--key=")){let a=C(t.slice(6));a&&e.keys.push(a)}else{if(t.startsWith("--"))return k("sort",t);if(t.startsWith("-")&&!t.startsWith("--")){let a=!1;for(let f of t.slice(1))if(f==="r")e.reverse=!0;else if(f==="n")e.numeric=!0;else if(f==="u")e.unique=!0;else if(f==="f")e.ignoreCase=!0;else if(f==="h")e.humanNumeric=!0;else if(f==="V")e.versionSort=!0;else if(f==="d")e.dictionaryOrder=!0;else if(f==="M")e.monthSort=!0;else if(f==="b")e.ignoreLeadingBlanks=!0;else if(f==="s")e.stable=!0;else if(f==="c")e.checkOnly=!0;else{a=!0;break}if(a)return k("sort",t)}else l.push(t)}}let s=await O(r,l,{cmdName:"sort"});if(!s.ok)return s.error;let n=s.content.split(`
12
- `);n.length>0&&n[n.length-1]===""&&n.pop();let d=M(e);if(e.checkOnly){let c=l.length>0?l[0]:"-";for(let t=1;t<n.length;t++)if(d(n[t-1],n[t])>0)return{stdout:"",stderr:`sort: ${c}:${t+1}: disorder: ${n[t]}
13
- `,exitCode:1};return{stdout:"",stderr:"",exitCode:0}}n.sort(d),e.unique&&(n=E(n,e));let o=n.length>0?`${n.join(`
14
- `)}
15
- `:"";if(e.outputFile){let c=r.fs.resolvePath(r.cwd,e.outputFile);return await r.fs.writeFile(c,o),{stdout:"",stderr:"",exitCode:0}}return{stdout:o,stderr:"",exitCode:0}}};export{j as sortCommand};