@inkeep/open-knowledge 0.28.0-beta.0 → 0.28.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD_PARTY_NOTICES.md +24 -9
- package/dist/assets/skills/discovery/SKILL.md +1 -1
- package/dist/assets/skills/project/SKILL.md +1 -1
- package/dist/awk2-BBAGSFUB-Clvg_OoV.mjs +1 -0
- package/dist/chunk-2TRDZQLB-C2G-sahM.mjs +18 -0
- package/dist/{chunk-UNYNJIFU-HSzsM3a6.mjs → chunk-3BS5SKQH-HZ1-1bfb.mjs} +36 -36
- package/dist/{chunk-YS3AZT3J-DwQ3GyQR.mjs → chunk-3H6UQG3A-DdNaIxPm.mjs} +9 -9
- package/dist/{chunk-XORM457F-CJbQLVgU.mjs → chunk-6Z5SFZXK-C3WlMqq-.mjs} +53 -53
- package/dist/{chunk-YNYSPYQ5-DHter9G3.mjs → chunk-B74TABJS-DlbqoTuk.mjs} +13 -13
- package/dist/{chunk-FEIOJCZD-D6YUa1Xl.mjs → chunk-BGSUD5R5-DQ0_iOyO.mjs} +2 -2
- package/dist/{chunk-F55TLFGB-AEzanSfe.mjs → chunk-DBKNVD4L-BVx-WyDG.mjs} +2 -2
- package/dist/{chunk-BRGMQKJV-DtyxDw61.mjs → chunk-HKLCLINH-DwmCAW4U.mjs} +16 -16
- package/dist/chunk-HL6NGDO2-978327U5.mjs +24 -0
- package/dist/{chunk-LPQPILI2-GOcK96AE.mjs → chunk-K6LIBGJA-DpjaSGfc.mjs} +2 -2
- package/dist/{chunk-BBXLRYSX-OVlWa2B-.mjs → chunk-KRBPSX3W-nYEMVABW.mjs} +2 -2
- package/dist/chunk-KX3P26DQ-Cli1PSKS.mjs +2 -0
- package/dist/{chunk-SYMJJMQ4-DUF5hY-A.mjs → chunk-PXTK5WE2-B17f9YTq.mjs} +1 -1
- package/dist/{chunk-J642UCRS-C1PS8Hwf.mjs → chunk-SNN4IESC-C-P75V1I.mjs} +2 -2
- package/dist/chunk-TP4BZANS-eJW0TOjs.mjs +21 -0
- package/dist/{chunk-YFG2CMIF-DBRGs_rZ.mjs → chunk-V5MWI2OL-CDEVEp7K.mjs} +2 -2
- package/dist/chunk-XKWWSDBF-XuPgN5BP.mjs +37 -0
- package/dist/{chunk-NYQYO467-KfHLMnUW.mjs → chunk-YMMW5UAP-uYgeXT56.mjs} +5 -5
- package/dist/chunk-YULBWSET-BYBVdNmi.mjs +14 -0
- package/dist/{chunk-OL3S66CO-CBdL6pp1.mjs → chunk-ZZO3UDB3-CdVtmXn4.mjs} +2 -2
- package/dist/cli.mjs +7 -7
- package/dist/constants-DQ9gCjtp.mjs +2 -0
- package/dist/{dist-CgMyk9vp.mjs → dist-Cj2f9yMz.mjs} +1 -1
- package/dist/{dist-C_yx5tj0.mjs → dist-Dzsbf2ES.mjs} +159 -161
- package/dist/expansion-VBDYWVZR-k3W3Rc7R.mjs +1 -0
- package/dist/expr-YYCVMXE3-CHnBeIXW.mjs +1 -0
- package/dist/file-IGDTDPLG-DQaFkvTu.mjs +1 -0
- package/dist/find-DH2ALKQS-6y8KktlA.mjs +1 -0
- package/dist/{flag-coverage-QT4N2Z44-BlPYKPtd.mjs → flag-coverage-6JEX67RU-BqC6mFKB.mjs} +2 -2
- package/dist/{git-handle-Bhgrj9qX-DBwQr-02.mjs → git-handle-B4hCEi7c-CXOP12Ds.mjs} +2 -2
- package/dist/git-handle-DG8d2xCi-C_CAAChL.mjs +1 -0
- package/dist/grep-2HUTXO5U-Dbnjl3Iq.mjs +1 -0
- package/dist/index.d.mts +30 -1
- package/dist/index.mjs +1 -1
- package/dist/{init-ivEBwK7y.mjs → init-CylIL2_d.mjs} +24 -24
- package/dist/init-iEaa5yZe.mjs +1 -0
- package/dist/jq-LYZFFBZB-CSF_TJhe.mjs +1 -0
- package/dist/{js-exec-M6UR76J5-ZESSNIAK.mjs → js-exec-VXN6TZ7U-fCXuAS2-.mjs} +2 -2
- package/dist/{loader-u0w9n8j8.mjs → loader-DL7cugZT.mjs} +2 -2
- package/dist/loader-Dnu5tSEp.mjs +1 -0
- package/dist/preview-B5POtWPo.mjs +1 -0
- package/dist/{preview-DuGdXEFZ.mjs → preview-Bn8zUTY3.mjs} +2 -2
- package/dist/public/assets/SettingsDialogBody-BX4GP2gS.js +7 -0
- package/dist/public/assets/{index-BY2yEG8q.js → index-Br8R5akq.js} +3 -3
- package/dist/public/index.html +1 -1
- package/dist/{python3-AUFTPCU6-B7_jrPM3.mjs → python3-DNGS4G3E-bGzU9nm-.mjs} +2 -2
- package/dist/{repair-launch-json-GbJKeEYH.mjs → repair-launch-json-BkY5nlM0.mjs} +2 -2
- package/dist/repair-mcp-configs-Cz6iXpxD.mjs +2 -0
- package/dist/repair-skills-BwkQh3gJ.mjs +1 -0
- package/dist/repair-skills-DDLj2RIs.mjs +3 -0
- package/dist/rg-XNF3R3II-ivb6d3Sm.mjs +1 -0
- package/dist/sed-JAPPVBEU-BvDbOHs0.mjs +1 -0
- package/dist/{sqlite3-56UMWEY3-DNmhrHQv.mjs → sqlite3-TE5AIOTF-DW7pT7NE.mjs} +1 -1
- package/dist/{src-Cc1qY4l3.mjs → src-DL-hUlrv.mjs} +3 -3
- package/dist/{start-FRD4_VQ8.mjs → start-OiE8Ork3.mjs} +2 -2
- package/dist/start-uZWiX6-B.mjs +1 -0
- package/dist/tar-MZQD7NO4-46pC0DHj.mjs +1 -0
- package/dist/{write-project-skill-GLroKiE7.mjs → write-project-skill-C7UNscN7.mjs} +3 -3
- package/dist/xan-UD7JYIL2-DnWVVFeC.mjs +1 -0
- package/dist/xan-view-OW2TB7Z3-DBl8NjSB.mjs +1 -0
- package/dist/yq-OAKYHSXH-CpYttz-E.mjs +1 -0
- package/package.json +1 -1
- package/dist/awk2-POPGKRAI-6Q9HKhoL.mjs +0 -1
- package/dist/chunk-CR5AFCPT-BD_awIEP.mjs +0 -24
- package/dist/chunk-HWBSOZZR-DaPTwPxK.mjs +0 -37
- package/dist/chunk-OARHFVLG-Csb_cJVS.mjs +0 -21
- package/dist/chunk-VLGZJRPG-CHtdu0KZ.mjs +0 -17
- package/dist/chunk-XHM67O4N-2lBQUjKO.mjs +0 -2
- package/dist/chunk-YCFVLTST-CKzPj8PR.mjs +0 -13
- package/dist/constants-CrfIfZxB.mjs +0 -2
- package/dist/expansion-ENLSRCXJ-C5xjxYTl.mjs +0 -1
- package/dist/expr-5T3UU5KE-DrJUreFq.mjs +0 -1
- package/dist/file-ZIGAJ4YS-D07ChhI1.mjs +0 -1
- package/dist/find-TPUOAIUQ-ZPOxwUwf.mjs +0 -1
- package/dist/git-handle-DjEtQkHv-DQXg1XhZ.mjs +0 -1
- package/dist/grep-3AIAIJVR-Bh6KBg6d.mjs +0 -1
- package/dist/init-D4mCPnC2.mjs +0 -1
- package/dist/jq-ODXZBPLY-D3tmTL1R.mjs +0 -1
- package/dist/loader-ByJ07pxk.mjs +0 -1
- package/dist/preview-BSeDAUIf.mjs +0 -1
- package/dist/public/assets/SettingsDialogBody-BGLGfDpN.js +0 -7
- package/dist/repair-mcp-configs-DLSIsucG.mjs +0 -2
- package/dist/repair-skills-B-VIYM77.mjs +0 -1
- package/dist/repair-skills-DJmyw_aE.mjs +0 -3
- package/dist/rg-FOQSCCX3-ViKChHv5.mjs +0 -1
- package/dist/sed-VFTTATXJ-BfHBQ11q.mjs +0 -1
- package/dist/start-B-djBhNq.mjs +0 -1
- package/dist/tar-ANUBEFJY-Db9qg5B2.mjs +0 -1
- package/dist/xan-BXDXYEIB-I8yansvE.mjs +0 -1
- package/dist/xan-view-ECQUO7AJ-DJhdCPf3.mjs +0 -1
- package/dist/yq-MJMAR36V-BXyMiYfX.mjs +0 -1
|
@@ -877,7 +877,7 @@ https://github.com/DataDog/import-in-the-middle repository:
|
|
|
877
877
|
limitations under the License.
|
|
878
878
|
```
|
|
879
879
|
|
|
880
|
-
### `just-bash@2.14.
|
|
880
|
+
### `just-bash@2.14.5`
|
|
881
881
|
Homepage: https://github.com/vercel-labs/just-bash#readme
|
|
882
882
|
|
|
883
883
|
Copyright 2025 Vercel Inc.
|
|
@@ -1590,6 +1590,11 @@ Homepage: https://paulmillr.com/noble/
|
|
|
1590
1590
|
|
|
1591
1591
|
Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
1592
1592
|
|
|
1593
|
+
### `@nodable/entities@2.2.0`
|
|
1594
|
+
Homepage: https://github.com/nodable/val-parsers
|
|
1595
|
+
|
|
1596
|
+
_(No LICENSE file in package; SPDX identifier in `package.json` is the sole declared grant.)_
|
|
1597
|
+
|
|
1593
1598
|
### `@nodelib/fs.scandir@2.1.5`
|
|
1594
1599
|
Homepage: https://github.com/nodelib/nodelib/tree/master/packages/fs/fs.scandir
|
|
1595
1600
|
|
|
@@ -2689,6 +2694,11 @@ Homepage: https://github.com/chalk/ansi-styles
|
|
|
2689
2694
|
|
|
2690
2695
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
2691
2696
|
|
|
2697
|
+
### `anynum@1.0.1`
|
|
2698
|
+
Homepage: https://github.com/NaturalIntelligence/anynum
|
|
2699
|
+
|
|
2700
|
+
Copyright (c) 2026 Natural Intelligence
|
|
2701
|
+
|
|
2692
2702
|
### `aria-hidden@1.2.6`
|
|
2693
2703
|
Homepage: https://github.com/theKashey/aria-hidden#readme
|
|
2694
2704
|
|
|
@@ -3354,12 +3364,12 @@ Homepage: https://github.com/43081j/fast-wrap-ansi#readme
|
|
|
3354
3364
|
Copyright (c) 2025 James Garbutt
|
|
3355
3365
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
3356
3366
|
|
|
3357
|
-
### `fast-xml-builder@1.
|
|
3367
|
+
### `fast-xml-builder@1.2.0`
|
|
3358
3368
|
Homepage: https://github.com/NaturalIntelligence/fast-xml-builder
|
|
3359
3369
|
|
|
3360
3370
|
Copyright (c) 2026 Natural Intelligence
|
|
3361
3371
|
|
|
3362
|
-
### `fast-xml-parser@5.
|
|
3372
|
+
### `fast-xml-parser@5.9.3`
|
|
3363
3373
|
Homepage: https://github.com/NaturalIntelligence/fast-xml-parser
|
|
3364
3374
|
|
|
3365
3375
|
Copyright (c) 2017 Amit Kumar Gupta
|
|
@@ -3804,6 +3814,11 @@ Homepage: https://github.com/sindresorhus/is-unicode-supported
|
|
|
3804
3814
|
|
|
3805
3815
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
3806
3816
|
|
|
3817
|
+
### `is-unsafe@1.0.1`
|
|
3818
|
+
Homepage: https://github.com/NaturalIntelligence/is-unsafe
|
|
3819
|
+
|
|
3820
|
+
Copyright (c) 2026 Natural Intelligence
|
|
3821
|
+
|
|
3807
3822
|
### `is-wsl@3.1.1`
|
|
3808
3823
|
Homepage: https://github.com/sindresorhus/is-wsl
|
|
3809
3824
|
|
|
@@ -5313,7 +5328,7 @@ Homepage: https://github.com/sindresorhus/strip-json-comments
|
|
|
5313
5328
|
|
|
5314
5329
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
5315
5330
|
|
|
5316
|
-
### `strnum@2.
|
|
5331
|
+
### `strnum@2.4.1`
|
|
5317
5332
|
Homepage: https://github.com/NaturalIntelligence/strnum
|
|
5318
5333
|
|
|
5319
5334
|
Copyright (c) 2021 Natural Intelligence
|
|
@@ -5708,6 +5723,11 @@ Homepage: https://github.com/sindresorhus/wsl-utils
|
|
|
5708
5723
|
|
|
5709
5724
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
5710
5725
|
|
|
5726
|
+
### `xml-naming@0.1.0`
|
|
5727
|
+
Homepage: https://github.com/NaturalIntelligence/xml-naming
|
|
5728
|
+
|
|
5729
|
+
_(No LICENSE file in package; SPDX identifier in `package.json` is the sole declared grant.)_
|
|
5730
|
+
|
|
5711
5731
|
### `y-codemirror.next@0.3.5`
|
|
5712
5732
|
Homepage: https://github.com/yjs/y-codemirror.next#readme
|
|
5713
5733
|
|
|
@@ -6123,11 +6143,6 @@ Homepage: https://eemeli.org/yaml/
|
|
|
6123
6143
|
|
|
6124
6144
|
Copyright Eemeli Aro <eemeli@gmail.com>
|
|
6125
6145
|
|
|
6126
|
-
### `yaml@2.8.3`
|
|
6127
|
-
Homepage: https://eemeli.org/yaml/
|
|
6128
|
-
|
|
6129
|
-
Copyright Eemeli Aro <eemeli@gmail.com>
|
|
6130
|
-
|
|
6131
6146
|
### `yargs-parser@21.1.1`
|
|
6132
6147
|
Homepage: https://github.com/yargs/yargs-parser
|
|
6133
6148
|
|
|
@@ -3,7 +3,7 @@ name: open-knowledge-discovery
|
|
|
3
3
|
description: "Read when the user asks what OpenKnowledge is, wants to install it on a repository, wants to share an OpenKnowledge project with collaborators, or asks how `ok init` / `ok cowork` / OK Desktop set up a project. Do NOT load to perform OpenKnowledge reads/writes — the runtime guidance for editing markdown inside an initialized OK project ships as a separate project-local skill at `.claude/skills/open-knowledge/` whenever `ok init` runs. If the user appears to be editing markdown inside a `.ok/` project and this is the only OK skill loaded, advise them to re-run `ok init` to install the project-local skill."
|
|
4
4
|
compatibility: "Any agent host — no MCP server required. Pure discovery + install guidance."
|
|
5
5
|
metadata:
|
|
6
|
-
version: "0.28.0-beta.
|
|
6
|
+
version: "0.28.0-beta.2"
|
|
7
7
|
author: "Inkeep"
|
|
8
8
|
repository: "https://github.com/inkeep/open-knowledge"
|
|
9
9
|
---
|
|
@@ -3,7 +3,7 @@ name: open-knowledge
|
|
|
3
3
|
description: "Authoritative agent-runtime contract for working inside an OpenKnowledge project — a markdown-CRDT knowledge base exposed over MCP. Use whenever reading, listing, searching, or editing any `.md` or `.mdx` file in the project, and before any `mcp__open-knowledge__*` tool call (`exec`, `search`, `write`, `edit`, and the rest). Installed by `ok init`, so its presence means this is an OpenKnowledge project and it governs every markdown file here. Covers the read/write tool surface, grounding and linking rules, folder/template conventions, the live browser preview, and the rule that OK's MCP tools — never native file tools — handle in-scope markdown."
|
|
4
4
|
compatibility: "Claude Code, Claude Desktop, Claude Cowork, Claude.ai web. Requires OpenKnowledge MCP server + code execution."
|
|
5
5
|
metadata:
|
|
6
|
-
version: "0.28.0-beta.
|
|
6
|
+
version: "0.28.0-beta.2"
|
|
7
7
|
author: "Inkeep"
|
|
8
8
|
repository: "https://github.com/inkeep/open-knowledge"
|
|
9
9
|
---
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-B74TABJS-DlbqoTuk.mjs";import"./chunk-DXB73IDG-Bx-Ikbnu.mjs";import"./chunk-5QMZ5MUS-_0tQyQsf.mjs";import"./chunk-24IMIIXA-BoP5OA93.mjs";import{n as e}from"./chunk-TP4BZANS-eJW0TOjs.mjs";export{e as awkCommand2};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{t as e}from"./chunk-B74TABJS-DlbqoTuk.mjs";function t(e,t){let n=e.ignoreCase?t.toLowerCase():t,r=e.needles;for(let e=0;e<r.length;e++)if(n.indexOf(r[e])!==-1)return!0;return!1}function n(e,t){return e.replace(/\$(&|\d+|<([^>]+)>)/g,(e,n,r)=>n===`&`?t[0]:r===void 0?t[parseInt(n,10)]??``:t.groups?.[r]??``)}function r(e,r,a={}){let{invertMatch:o=!1,showLineNumbers:s=!1,countOnly:c=!1,countMatches:l=!1,filename:u=``,onlyMatching:d=!1,beforeContext:f=0,afterContext:p=0,maxCount:m=0,contextSeparator:h=`--`,showColumn:g=!1,vimgrep:_=!1,showByteOffset:v=!1,replace:y=null,passthru:b=!1,multiline:x=!1,kResetGroup:S,preFilter:C}=a;if(x)return i(e,r,{invertMatch:o,showLineNumbers:s,countOnly:c,countMatches:l,filename:u,onlyMatching:d,beforeContext:f,afterContext:p,maxCount:m,contextSeparator:h,showColumn:g,showByteOffset:v,replace:y,kResetGroup:S});let w=e.split(`
|
|
2
|
+
`),T=w.length,E=T>0&&w[T-1]===``?T-1:T;if(c||l){let e=0,n=(l||d)&&!o;for(let i=0;i<E;i++){let a=w[i];if(!(C&&!o&&!t(C,a)))if(r.lastIndex=0,n)for(let t=r.exec(a);t!==null;t=r.exec(a))e++,t[0].length===0&&r.lastIndex++;else r.test(a)!==o&&e++}return{output:`${u?`${u}:${e}`:String(e)}
|
|
3
|
+
`,matched:e>0,matchCount:e}}if(f===0&&p===0&&!b){let e=[],i=!1,a=0,c=0;for(let l=0;l<E&&!(m>0&&a>=m);l++){let f=w[l],p=null;if(C&&!t(C,f)||(r.lastIndex=0,p=r.exec(f)),p!==null!==o)if(i=!0,a++,d)for(let t=p;t!==null;t=r.exec(f)){let i=S===void 0?t[0]:t[S]??``,a=y===null?i:n(y,t),o=u?`${u}:`:``;v&&(o+=`${c+t.index}:`),s&&(o+=`${l+1}:`),g&&(o+=`${t.index+1}:`),e.push(o+a),t[0].length===0&&r.lastIndex++}else if(_)for(let t=p;t!==null;t=r.exec(f)){let n=u?`${u}:`:``;v&&(n+=`${c+t.index}:`),s&&(n+=`${l+1}:`),g&&(n+=`${t.index+1}:`),e.push(n+f),t[0].length===0&&r.lastIndex++}else{let t=p?p.index+1:1,i=f;y!==null&&(r.lastIndex=0,i=r.replace(f,(...e)=>{if(e[0].length===0)return``;let t=e,r=e[e.length-1];return typeof r==`object`&&r?(t.groups=r,t.input=e[e.length-2],t.index=e[e.length-3]):(t.input=e[e.length-1],t.index=e[e.length-2]),n(y,t)}));let a=u?`${u}:`:``;v&&(a+=`${c+(p?p.index:0)}:`),s&&(a+=`${l+1}:`),g&&(a+=`${t}:`),e.push(a+i)}c+=f.length+1}return{output:e.length>0?`${e.join(`
|
|
4
|
+
`)}
|
|
5
|
+
`:``,matched:i,matchCount:a}}if(b){let e=[],n=!1,i=0;for(let a=0;a<E;a++){let c=w[a],l;C&&!t(C,c)?l=!1:(r.lastIndex=0,l=r.test(c));let d=l!==o;d&&(n=!0,i++);let f=d?`:`:`-`,p=u?`${u}${f}`:``;s&&(p+=`${a+1}${f}`),e.push(p+c)}return{output:e.length>0?`${e.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`:``,matched:n,matchCount:i}}let D=[],O=0,k=new Set,A=-1,j=[];for(let e=0;e<E&&!(m>0&&O>=m);e++){let n=w[e],i;C&&!t(C,n)?i=!1:(r.lastIndex=0,i=r.test(n)),i!==o&&(j.push(e),O++)}for(let e of j){let t=Math.max(0,e-f);A>=0&&t>A+1&&D.push(h);for(let n=t;n<e;n++)if(!k.has(n)){k.add(n),A=n;let e=w[n];s&&(e=`${n+1}-${e}`),u&&(e=`${u}-${e}`),D.push(e)}if(!k.has(e)){k.add(e),A=e;let t=w[e];if(d){r.lastIndex=0;for(let n=r.exec(t);n!==null;n=r.exec(t)){let t=S===void 0?n[0]:n[S]??``,i=y===null?t:y,a=u?`${u}:`:``;s&&(a+=`${e+1}:`),g&&(a+=`${n.index+1}:`),D.push(a+i),n[0].length===0&&r.lastIndex++}}else{let n=t;s&&(n=`${e+1}:${n}`),u&&(n=`${u}:${n}`),D.push(n)}}let n=Math.min(E-1,e+p);for(let t=e+1;t<=n;t++)if(!k.has(t)){k.add(t),A=t;let e=w[t];s&&(e=`${t+1}-${e}`),u&&(e=`${u}-${e}`),D.push(e)}}return{output:D.length>0?`${D.join(`
|
|
8
|
+
`)}
|
|
9
|
+
`:``,matched:O>0,matchCount:O}}function i(e,t,n){let{invertMatch:r,showLineNumbers:i,countOnly:a,countMatches:o,filename:s,onlyMatching:c,beforeContext:l,afterContext:u,maxCount:d,contextSeparator:f,showColumn:p,showByteOffset:m,replace:h,kResetGroup:g}=n,_=e.split(`
|
|
10
|
+
`),v=_.length,y=v>0&&_[v-1]===``?v-1:v,b=[0];for(let t=0;t<e.length;t++)e[t]===`
|
|
11
|
+
`&&b.push(t+1);let x=e=>{let t=0;for(let n=0;n<b.length&&!(b[n]>e);n++)t=n;return t},S=e=>e-b[x(e)]+1,C=[];t.lastIndex=0;for(let n=t.exec(e);n!==null&&!(d>0&&C.length>=d);n=t.exec(e)){let e=x(n.index),r=x(n.index+Math.max(0,n[0].length-1)),i=g===void 0?n[0]:n[g]??``;C.push({startLine:e,endLine:r,byteOffset:n.index,column:S(n.index),matchText:i}),n[0].length===0&&t.lastIndex++}if(a||o){let e;if(o)e=r?0:C.length;else{let t=new Set;for(let e of C)for(let n=e.startLine;n<=e.endLine;n++)t.add(n);e=r?y-t.size:t.size}return{output:`${s?`${s}:${e}`:String(e)}
|
|
12
|
+
`,matched:e>0,matchCount:e}}if(r){let e=new Set;for(let t of C)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);let t=[];for(let n=0;n<y;n++)if(!e.has(n)){let e=_[n];i&&(e=`${n+1}:${e}`),s&&(e=`${s}:${e}`),t.push(e)}return{output:t.length>0?`${t.join(`
|
|
13
|
+
`)}
|
|
14
|
+
`:``,matched:t.length>0,matchCount:t.length}}if(C.length===0)return{output:``,matched:!1,matchCount:0};let w=new Set,T=-1,E=[];for(let e of C){let n=Math.max(0,e.startLine-l),r=Math.min(y-1,e.endLine+u);T>=0&&n>T+1&&E.push(f);for(let t=n;t<e.startLine;t++)if(!w.has(t)){w.add(t),T=t;let e=_[t];i&&(e=`${t+1}-${e}`),s&&(e=`${s}-${e}`),E.push(e)}if(c){let t=h===null?e.matchText:h,n=s?`${s}:`:``;m&&(n+=`${e.byteOffset}:`),i&&(n+=`${e.startLine+1}:`),p&&(n+=`${e.column}:`),E.push(n+t);for(let t=e.startLine;t<=e.endLine;t++)w.add(t),T=t}else for(let n=e.startLine;n<=e.endLine&&n<y;n++)if(!w.has(n)){w.add(n),T=n;let r=_[n];h!==null&&n===e.startLine&&(t.lastIndex=0,r=t.replace(r,h));let a=s?`${s}:`:``;m&&n===e.startLine&&(a+=`${e.byteOffset}:`),i&&(a+=`${n+1}:`),p&&n===e.startLine&&(a+=`${e.column}:`),E.push(a+r)}for(let t=e.endLine+1;t<=r;t++)if(!w.has(t)){w.add(t),T=t;let e=_[t];i&&(e=`${t+1}-${e}`),s&&(e=`${s}-${e}`),E.push(e)}}return{output:E.length>0?`${E.join(`
|
|
15
|
+
`)}
|
|
16
|
+
`:``,matched:!0,matchCount:C.length}}var a=new Map([[`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 o(e){let t=``,n=0;for(;n<e.length;){if(e.slice(n,n+7)===`[[:<:]]`){t+=`\\b`,n+=7;continue}if(e.slice(n,n+7)===`[[:>:]]`){t+=`\\b`,n+=7;continue}if(e[n]===`[`){let r=`[`;for(n++,n<e.length&&(e[n]===`^`||e[n]===`!`)&&(r+=`^`,n++),n<e.length&&e[n]===`]`&&(r+=`\\]`,n++);n<e.length&&e[n]!==`]`;){if(e[n]===`[`&&n+1<e.length&&e[n+1]===`:`){let t=e.indexOf(`:]`,n+2);if(t!==-1){let i=e.slice(n+2,t),o=a.get(i);if(o){r+=o,n=t+2;continue}}}if(e[n]===`\\`&&n+1<e.length){r+=e[n]+e[n+1],n+=2;continue}r+=e[n],n++}n<e.length&&e[n]===`]`&&(r+=`]`,n++),t+=r;continue}if(e[n]===`\\`&&n+1<e.length){t+=e[n]+e[n+1],n+=2;continue}t+=e[n],n++}return t}function s(t,n){let r,i;switch(n.mode){case`fixed`:r=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);break;case`extended`:case`perl`:if(r=o(t),r=r.replace(/\(\?P<([^>]+)>/g,`(?<$1>`),n.mode===`perl`){r=d(r),r=f(r),r=p(r);let e=_(r);r=e.pattern,i=e.kResetGroup}break;default:r=o(t),r=x(r);break}n.wholeWord&&(r=`\\b(?:${r})\\b`),n.lineRegexp&&(r=`^${r}$`);let a=/\\u\{[0-9A-Fa-f]+\}/.test(r),s=`g`+(n.ignoreCase?`i`:``)+(n.multiline?`m`:``)+(n.multilineDotall?`s`:``)+(a?`u`:``),l=c(r,n.ignoreCase??!1);return{regex:e(r,s),kResetGroup:i,preFilter:l??void 0}}function c(e,t){let n=e;if(n.startsWith(`\\b(?:`)&&n.endsWith(`)\\b`)?n=n.slice(5,n.length-3):n.startsWith(`\\b`)&&n.endsWith(`\\b`)&&n.length>=4&&(n=n.slice(2,n.length-2)),n.length===0)return null;let r=l(n);if(r===null)return null;let i=[];for(let e of r){let t=u(e);if(t===null||t.length===0)return null;i.push(t)}return i.length===0?null:{needles:t?i.map(e=>e.toLowerCase()):i,ignoreCase:t}}function l(e){let t=[],n=0,r=!1,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(o===`\\`){a++;continue}if(r){o===`]`&&(r=!1);continue}if(o===`[`)r=!0;else if(o===`(`)n++;else if(o===`)`){if(n--,n<0)return null}else o===`|`&&n===0&&(t.push(e.slice(i,a)),i=a+1)}return n!==0||r?null:(t.push(e.slice(i)),t)}function u(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(r===`\\`){let r=e[n+1];if(r===void 0||/[dDwWsSbBAZzGQE0-9ckpPNXRxuU]/.test(r))return null;r===`n`?t+=`
|
|
17
|
+
`:r===`t`?t+=` `:r===`r`?t+=`\r`:r===`f`?t+=`\f`:r===`v`?t+=`\v`:t+=r,n++;continue}if(/[.*+?^${}()|[\]]/.test(r))return null;t+=r}return t}function d(e){let t=``,n=0;for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length&&e[n+1]===`Q`){n+=2;let r=``;for(;n<e.length;){if(e[n]===`\\`&&n+1<e.length&&e[n+1]===`E`){n+=2;break}r+=e[n],n++}t+=r.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}else t+=e[n],n++;return t}function f(e){return e.replace(/\\x\{([0-9A-Fa-f]+)\}/g,`\\u{$1}`)}function p(e){let t=``,n=0;for(;n<e.length;){if(e[n]===`(`&&n+1<e.length&&e[n+1]===`?`){let r=e.slice(n).match(/^\(\?([imsx]*)(-[imsx]*)?(:|$|\))/);if(r){let i=r[1]||``,a=r[2]||``,o=r[3];if(o===`:`){let o=n+r[0].length-1,s=m(e,n);if(s!==-1){let r=h(e.slice(o+1,s),i,a);t+=`(?:${r})`,n=s+1;continue}}else if(o===`)`||o===``){n+=r[0].length;continue}}}t+=e[n],n++}return t}function m(e,t){let n=0,r=t;for(;r<e.length;){if(e[r]===`\\`){r+=2;continue}if(e[r]===`[`){for(r++;r<e.length&&e[r]!==`]`;)e[r]===`\\`&&r++,r++;r++;continue}if(e[r]===`(`)n++;else if(e[r]===`)`&&(n--,n===0))return r;r++}return-1}function h(e,t,n){let r=e;return t.includes(`i`)&&(r=g(r)),r}function g(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===`\\`){n+1<e.length?(t+=r+e[n+1],n+=2):(t+=r,n++);continue}if(r===`[`){t+=r,n++,n<e.length&&e[n]===`^`&&(t+=e[n],n++);let i=[];for(;n<e.length&&e[n]!==`]`;)if(e[n]===`\\`)i.push(e[n]),n++,n<e.length&&(i.push(e[n]),n++);else if(e[n]===`-`&&i.length>0&&n+1<e.length&&e[n+1]!==`]`){let t=i[i.length-1],r=e[n+1];i.push(`-`),i.push(r),/[a-z]/.test(t)&&/[a-z]/.test(r)?(i.push(t.toUpperCase()),i.push(`-`),i.push(r.toUpperCase())):/[A-Z]/.test(t)&&/[A-Z]/.test(r)&&(i.push(t.toLowerCase()),i.push(`-`),i.push(r.toLowerCase())),n+=2}else{let t=e[n];if(i.push(t),/[a-zA-Z]/.test(t)){let e=t===t.toLowerCase()?t.toUpperCase():t.toLowerCase();i.includes(e)||i.push(e)}n++}t+=i.join(``),n<e.length&&(t+=e[n],n++);continue}if(/[a-zA-Z]/.test(r)){let e=r.toLowerCase(),n=r.toUpperCase();t+=`[${n}${e}]`}else t+=r;n++}return t}function _(e){let t=v(e);if(t===-1)return{pattern:e};let n=e.slice(0,t),r=e.slice(t+2),i=y(n);return{pattern:`(?:${n})(${r})`,kResetGroup:i+1}}function v(e){let t=0;for(;t<e.length-1;)if(e[t]===`\\`){if(e[t+1]===`K`){let n=0,r=t-1;for(;r>=0&&e[r]===`\\`;)n++,r--;if(n%2==0)return t}t+=2}else t++;return-1}function y(e){let t=0,n=0;for(;n<e.length;){if(e[n]===`\\`){n+=2;continue}if(e[n]===`[`){for(n++;n<e.length&&e[n]!==`]`;)e[n]===`\\`&&n++,n++;n++;continue}if(e[n]===`(`)if(n+1<e.length&&e[n+1]===`?`){if(n+2<e.length){let r=e[n+2];if(r===`:`||r===`=`||r===`!`){n++;continue}if(r===`<`&&n+3<e.length){let r=e[n+3];if(r===`=`||r===`!`){n++;continue}t++,n++;continue}}}else t++;n++}return t}function b(e){let t=e.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 x(e){let t=``,n=0,r=!0,i=0;for(;n<e.length;){let a=e[n];if(a===`[`){for(t+=a,n++,n<e.length&&(e[n]===`^`||e[n]===`!`)&&(t+=e[n],n++),n<e.length&&e[n]===`]`&&(t+=e[n],n++);n<e.length&&e[n]!==`]`;)e[n]===`\\`&&n+1<e.length?(t+=e[n]+e[n+1],n+=2):(t+=e[n],n++);n<e.length&&e[n]===`]`&&(t+=e[n],n++),r=!1;continue}if(a===`\\`&&n+1<e.length){let o=e[n+1];if(o===`|`){t+=`|`,n+=2,r=!0;continue}if(o===`(`){t+=`(`,n+=2,i++,r=!0;continue}if(o===`)`){t+=`)`,n+=2,i=Math.max(0,i-1),r=!1;continue}if(o===`{`){let i=e.slice(n).match(/^\\{(\d+)(,(\d*)?)?\\}/);if(i){let e=i[1],a=i[2]!==void 0,o=i[3]||``;a?t+=`{${e},${o}}`:t+=`{${e}}`,n+=i[0].length,r=!1;continue}t+=`\\{`,n+=2,r=!1;continue}if(o===`}`){t+=`\\}`,n+=2,r=!1;continue}t+=a+o,n+=2,r=!1;continue}if(a===`*`&&r){t+=`\\*`,n++;continue}if(a===`^`){if(r){t+=`^`,n++;continue}t+=`\\^`,n++;continue}if(a===`$`){let i=n===e.length-1,a=n+2<e.length&&e[n+1]===`\\`&&e[n+2]===`)`;i||a?t+=`$`:t+=`\\$`,n++,r=!1;continue}a===`+`||a===`?`||a===`|`||a===`(`||a===`)`||a===`{`||a===`}`?t+=`\\${a}`:t+=a,n++,r=!1}return t}export{r as n,b as r,s as t};
|
|
18
|
+
//# sourceMappingURL=chunk-2TRDZQLB-C2G-sahM.mjs.map
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import{t as e}from"./chunk-
|
|
1
|
+
import{t as e}from"./chunk-B74TABJS-DlbqoTuk.mjs";import{a as t,i as n,n as r,o as i}from"./chunk-DXB73IDG-Bx-Ikbnu.mjs";import{r as a,t as o}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{n as s}from"./chunk-7L36YK2X-B3QRwLbB.mjs";import{t as c}from"./chunk-PXTK5WE2-B17f9YTq.mjs";import{n as l,s as u}from"./chunk-7TSDKFEO-CMVuiOdP.mjs";import{n as d}from"./chunk-KRBPSX3W-nYEMVABW.mjs";import{a as f,c as p,i as m,n as h,o as g,r as _,s as v,t as y}from"./chunk-DBKNVD4L-BVx-WyDG.mjs";var b,x=r(()=>{b=class{input;pos=0;tokens=[];constructor(e){this.input=e}tokenize(){for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let e=this.nextToken();e&&this.tokens.push(e)}return this.tokens.push({type:`eof`,value:``,pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos<this.input.length;){let e=this.input[this.pos];if(e===` `||e===` `||e===`
|
|
2
2
|
`||e===`\r`)this.pos++;else if(e===`#`)for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
3
3
|
`;)this.pos++;else break}}nextToken(){let e=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 e=this.input[this.pos+1];if(e===`"`||e===`'`||e==="`")return this.pos++,this.readString(e)}if(t===`/`){let t=this.tokens[this.tokens.length-1];return t&&(t.type===`int`||t.type===`float`||t.type===`string`||t.type===`ident`||t.type===`)`||t.type===`]`)?this.input[this.pos+1]===`/`?(this.pos+=2,{type:`//`,value:`//`,pos:e}):(this.pos++,{type:`/`,value:`/`,pos:e}):this.readRegex()}if(this.match(`not in`))return{type:`not in`,value:`not in`,pos:e};if(this.match(`=>`))return{type:`=>`,value:`=>`,pos:e};if(this.match(`**`))return{type:`**`,value:`**`,pos:e};if(this.match(`++`))return{type:`++`,value:`++`,pos:e};if(this.match(`//`))return{type:`//`,value:`//`,pos:e};if(this.match(`==`))return{type:`==`,value:`==`,pos:e};if(this.match(`!=`))return{type:`!=`,value:`!=`,pos:e};if(this.match(`<=`))return{type:`<=`,value:`<=`,pos:e};if(this.match(`>=`))return{type:`>=`,value:`>=`,pos:e};if(this.match(`&&`))return{type:`&&`,value:`&&`,pos:e};if(this.match(`||`))return{type:`||`,value:`||`,pos:e};let n=new Map([[`(`,`(`],[`)`,`)`],[`[`,`[`],[`]`,`]`],[`{`,`{`],[`}`,`}`],[`,`,`,`],[`:`,`:`],[`;`,`;`],[`+`,`+`],[`-`,`-`],[`*`,`*`],[`%`,`%`],[`<`,`<`],[`>`,`>`],[`!`,`!`],[`.`,`.`],[`|`,`|`],[`=`,`=`]]).get(t);if(n!==void 0)return this.pos++,{type:n,value:t,pos:e};if(this.isIdentStart(t))return this.readIdentifier();throw Error(`Unexpected character '${t}' at position ${this.pos}`)}match(e){if(this.input.slice(this.pos,this.pos+e.length)===e){if(/^[a-zA-Z]/.test(e)){let t=this.input[this.pos+e.length];if(t&&this.isIdentChar(t))return!1}return this.pos+=e.length,!0}return!1}isIdentStart(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e===`_`}isIdentChar(e){return this.isIdentStart(e)||e>=`0`&&e<=`9`}readNumber(){let e=this.pos,t=!1,n=!1;for(;this.pos<this.input.length;){let e=this.input[this.pos];if(e>=`0`&&e<=`9`)this.pos++;else if(e===`_`)this.pos++;else if(e===`.`&&!t&&!n)t=!0,this.pos++;else if((e===`e`||e===`E`)&&!n)n=!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(e,this.pos).replace(/_/g,``);return{type:t?`float`:`int`,value:r,pos:e}}readString(e){let t=this.pos;this.pos++;let n=``;for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r===e)return this.pos++,{type:`string`,value:n,pos:t};if(r===`\\`){if(this.pos++,this.pos<this.input.length){let e=this.input[this.pos];switch(e){case`n`:n+=`
|
|
4
|
-
`;break;case`r`:n+=`\r`;break;case`t`:n+=` `;break;case`\\`:n+=`\\`;break;case`"`:n+=`"`;break;case`'`:n+=`'`;break;case"`":n+="`";break;case`0`:n+=`\0`;break;default:n+=e}this.pos++}}else n+=r,this.pos++}throw Error(`Unterminated string starting at position ${t}`)}readRegex(){let e=this.pos;this.pos++;let t=``,n=``;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`;)n+=this.input[this.pos],this.pos++;return{type:`regex`,value:t+(n?`/${n}`:``),pos:e}}r===`\\`?(t+=r,this.pos++,this.pos<this.input.length&&(t+=this.input[this.pos],this.pos++)):(t+=r,this.pos++)}throw Error(`Unterminated regex starting at position ${e}`)}readIdentifier(){let e=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 n=this.input.slice(e,t?this.pos-1:this.pos);t&&(n+=`?`);let r=new Map([[`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`],[`_`,`_`]]),i=n.replace(/\?$/,``),a=r.get(i);return a!==void 0&&!t?{type:a,value:i,pos:e}:{type:`ident`,value:n,pos:e}}}}),S={};n(S,{parseMoonblade:()=>w,parseNamedExpressions:()=>C});function C(e){let t=[],n=new b(e).tokenize(),r=0,i=()=>n[r]||{type:`eof`,value:``,pos:0},a=()=>n[r++];for(;i().type!==`eof`;){if(i().type===`,`&&t.length>0){a();continue}let o=[],s=0,c=r;for(;i().type!==`eof`;){let e=i();if((e.type===`,`||e.type===`as`)&&s===0)break;(e.type===`(`||e.type===`[`||e.type===`{`)&&s++,(e.type===`)`||e.type===`]`||e.type===`}`)&&s--,o.push(a())}o.push({type:`eof`,value:``,pos:0});let l=new E(o).parse(),u;if(i().type===`as`)if(a(),i().type===`(`){a();let e=[];for(;i().type!==`)`&&i().type!==`eof`;)(i().type===`ident`||i().type===`string`)&&(e.push(i().value),a()),i().type===`,`&&a();i().type===`)`&&a(),u=e}else if(i().type===`ident`||i().type===`string`)u=i().value,a();else throw Error(`Expected name after 'as', got ${i().type}`);else u=e.slice(n[c].pos,n[r-1]?.pos||e.length).trim(),l.type===`identifier`&&(u=l.name);t.push({expr:l,name:u})}return t}function w(e){let t=new b(e).tokenize();return new E(t).parse()}var T,E,D=r(()=>{x(),T={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},E=class{pos=0;tokens;constructor(e){this.tokens=e}parse(){let e=this.parseExpr(0);if(this.peek().type!==`eof`)throw Error(`Unexpected token: ${this.peek().value}`);return e}parseExpr(e){let t=this.parsePrefix();for(;;){let n=this.peek(),r=this.getInfixPrec(n.type);if(r<e)break;t=this.parseInfix(t,r)}return t}parsePrefix(){let e=this.peek();switch(e.type){case`int`:return this.advance(),{type:`int`,value:Number.parseInt(e.value,10)};case`float`:return this.advance(),{type:`float`,value:Number.parseFloat(e.value)};case`string`:return this.advance(),{type:`string`,value:e.value};case`regex`:{this.advance();let t=e.value.split(`/`),n=t.length>1?t[t.length-1]:``;return{type:`regex`,pattern:t.slice(0,-1).join(`/`)||e.value,caseInsensitive:n.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=e.value,n=t.endsWith(`?`),r=n?t.slice(0,-1):t;if(this.advance(),this.peek().type===`(`)return this.parseFunctionCall(r);if(this.peek().type===`=>`){this.advance();let e=this.parseExpr(0);return this.bindLambdaArgs({type:`lambda`,params:[r],body:e},[r])}return{type:`identifier`,name:r,unsure:n}}case`(`:{this.advance();let e=[];if(this.peek().type===`)`){if(this.advance(),this.peek().type===`=>`)return this.advance(),{type:`lambda`,params:[],body:this.parseExpr(0)};throw Error(`Empty parentheses not allowed`)}if(this.peek().type===`ident`){let t=this.peek().value;if(this.advance(),this.peek().type===`,`||this.peek().type===`)`){for(e.push(t);this.peek().type===`,`&&(this.advance(),this.peek().type===`ident`);)e.push(this.peek().value),this.advance();if(this.peek().type===`)`&&(this.advance(),this.peek().type===`=>`)){this.advance();let t=this.parseExpr(0);return this.bindLambdaArgs({type:`lambda`,params:e,body:t},e)}this.pos-=e.length*2,e.length>1&&(this.pos=this.pos)}this.pos--}let t=this.parseExpr(0);return this.expect(`)`),this.peek().type,t}case`[`:return this.parseList();case`{`:return this.parseMap();case`-`:{this.advance();let e=this.parseExpr(T.UNARY);return e.type===`int`?{type:`int`,value:-e.value}:e.type===`float`?{type:`float`,value:-e.value}:{type:`func`,name:`neg`,args:[{expr:e}]}}case`!`:return this.advance(),{type:`func`,name:`not`,args:[{expr:this.parseExpr(T.UNARY)}]};default:throw Error(`Unexpected token: ${e.type} (${e.value})`)}}parseFunctionCall(e){this.expect(`(`);let t=[];if(this.peek().type!==`)`)do{t.length>0&&this.peek().type===`,`&&this.advance();let e;if(this.peek().type===`ident`){let t=this.peek().value,n=this.pos+1;n<this.tokens.length&&this.tokens[n].type===`=`&&(e=t,this.advance(),this.advance())}let n=this.parseExpr(0);t.push({name:e,expr:n})}while(this.peek().type===`,`);return this.expect(`)`),{type:`func`,name:e.toLowerCase(),args:t}}parseList(){this.expect(`[`);let e=[];if(this.peek().type!==`]`)do e.length>0&&this.peek().type===`,`&&this.advance(),e.push(this.parseExpr(0));while(this.peek().type===`,`);return this.expect(`]`),{type:`list`,elements:e}}parseMap(){this.expect(`{`);let e=[];if(this.peek().type!==`}`)do{e.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 Error(`Expected map key, got ${this.peek().type}`);this.expect(`:`);let n=this.parseExpr(0);e.push({key:t,value:n})}while(this.peek().type===`,`);return this.expect(`}`),{type:`map`,entries:e}}parseInfix(e,t){let n=this.peek(),r=new Map([[`+`,`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`]]).get(n.type);if(r!==void 0){this.advance();let i=this.parseExpr(t+(this.isRightAssoc(n.type)?0:1));return{type:`func`,name:r,args:[{expr:e},{expr:i}]}}if(n.type===`|`){this.advance();let n=this.parseExpr(t);return this.handlePipe(e,n)}if(n.type===`.`)return this.advance(),this.handleDot(e);if(n.type===`[`)return this.advance(),this.handleIndexing(e);if(n.type===`in`)return this.advance(),{type:`func`,name:`contains`,args:[{expr:this.parseExpr(t+1)},{expr:e}]};if(n.type===`not in`)return this.advance(),{type:`func`,name:`not`,args:[{expr:{type:`func`,name:`contains`,args:[{expr:this.parseExpr(t+1)},{expr:e}]}}]};throw Error(`Unexpected infix token: ${n.type}`)}handlePipe(e,t){if(t.type===`identifier`)return{type:`func`,name:t.name,args:[{expr:e}]};if(t.type===`func`){let n=this.countUnderscores(t);return n===0?t:n===1?this.fillUnderscore(t,e):{type:`pipeline`,exprs:[e,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,e):t}handleDot(e){let t=this.peek();if(t.type===`ident`){let n=t.value;if(this.advance(),this.peek().type===`(`){let t=this.parseFunctionCall(n);return t.type===`func`&&t.args.unshift({expr:e}),t}return{type:`func`,name:`get`,args:[{expr:e},{expr:{type:`string`,value:n}}]}}if(t.type===`int`){let n=Number.parseInt(t.value,10);return this.advance(),{type:`func`,name:`get`,args:[{expr:e},{expr:{type:`int`,value:n}}]}}if(t.type===`string`){let n=t.value;return this.advance(),{type:`func`,name:`get`,args:[{expr:e},{expr:{type:`string`,value:n}}]}}throw Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(e){if(this.peek().type===`:`){if(this.advance(),this.peek().type===`]`)return this.advance(),{type:`func`,name:`slice`,args:[{expr:e}]};let t=this.parseExpr(0);return this.expect(`]`),{type:`func`,name:`slice`,args:[{expr:e},{expr:{type:`int`,value:0}},{expr:t}]}}let t=this.parseExpr(0);if(this.peek().type===`:`){if(this.advance(),this.peek().type===`]`)return this.advance(),{type:`func`,name:`slice`,args:[{expr:e},{expr:t}]};let n=this.parseExpr(0);return this.expect(`]`),{type:`func`,name:`slice`,args:[{expr:e},{expr:t},{expr:n}]}}return this.expect(`]`),{type:`func`,name:`get`,args:[{expr:e},{expr:t}]}}countUnderscores(e){return e.type===`underscore`?1:e.type===`func`?e.args.reduce((e,t)=>e+this.countUnderscores(t.expr),0):e.type===`list`?e.elements.reduce((e,t)=>e+this.countUnderscores(t),0):e.type===`map`?e.entries.reduce((e,t)=>e+this.countUnderscores(t.value),0):0}fillUnderscore(e,t){return e.type===`underscore`?t:e.type===`func`?{...e,args:e.args.map(e=>({...e,expr:this.fillUnderscore(e.expr,t)}))}:e.type===`list`?{...e,elements:e.elements.map(e=>this.fillUnderscore(e,t))}:e.type===`map`?{...e,entries:e.entries.map(e=>({...e,value:this.fillUnderscore(e.value,t)}))}:e}bindLambdaArgs(e,t){return{...e,body:this.bindLambdaArgsInExpr(e.body,t)}}bindLambdaArgsInExpr(e,t){return e.type===`identifier`&&t.includes(e.name)?{type:`lambdaBinding`,name:e.name}:e.type===`func`?{...e,args:e.args.map(e=>({...e,expr:this.bindLambdaArgsInExpr(e.expr,t)}))}:e.type===`list`?{...e,elements:e.elements.map(e=>this.bindLambdaArgsInExpr(e,t))}:e.type===`map`?{...e,entries:e.entries.map(e=>({...e,value:this.bindLambdaArgsInExpr(e.value,t)}))}:e}getInfixPrec(e){switch(e){case`|`:return T.PIPE;case`||`:case`or`:return T.OR;case`&&`:case`and`:return T.AND;case`==`:case`!=`:case`eq`:case`ne`:return T.EQUALITY;case`<`:case`<=`:case`>`:case`>=`:case`lt`:case`le`:case`gt`:case`ge`:case`in`:case`not in`:return T.COMPARISON;case`+`:case`-`:case`++`:return T.ADDITIVE;case`*`:case`/`:case`//`:case`%`:return T.MULTIPLICATIVE;case`**`:return T.POWER;case`.`:case`[`:return T.POSTFIX;default:return-1}}isRightAssoc(e){return e===`**`}peek(){return this.tokens[this.pos]||{type:`eof`,value:``,pos:0}}advance(){return this.tokens[this.pos++]}expect(e){let t=this.peek();if(t.type!==e)throw Error(`Expected ${e}, got ${t.type}`);return this.advance()}}});D();function O(e,t){return t.length===0?j(e,[]):t.length===1?{type:`Pipe`,left:t[0],right:j(e,[])}:{type:`Pipe`,left:t[0],right:j(e,t.slice(1))}}var k={add:e=>A(`+`,e[0],e[1]),sub:e=>A(`-`,e[0],e[1]),mul:e=>A(`*`,e[0],e[1]),div:e=>A(`/`,e[0],e[1]),mod:e=>A(`%`,e[0],e[1]),idiv:e=>j(`floor`,[A(`/`,e[0],e[1])]),pow:e=>O(`pow`,e),neg:e=>({type:`UnaryOp`,op:`-`,operand:e[0]}),"==":e=>A(`==`,e[0],e[1]),"!=":e=>A(`!=`,e[0],e[1]),"<":e=>A(`<`,e[0],e[1]),"<=":e=>A(`<=`,e[0],e[1]),">":e=>A(`>`,e[0],e[1]),">=":e=>A(`>=`,e[0],e[1]),eq:e=>A(`==`,P(e[0]),P(e[1])),ne:e=>A(`!=`,P(e[0]),P(e[1])),lt:e=>A(`<`,P(e[0]),P(e[1])),le:e=>A(`<=`,P(e[0]),P(e[1])),gt:e=>A(`>`,P(e[0]),P(e[1])),ge:e=>A(`>=`,P(e[0]),P(e[1])),and:e=>A(`and`,e[0],e[1]),or:e=>A(`or`,e[0],e[1]),not:e=>({type:`UnaryOp`,op:`not`,operand:e[0]}),len:e=>O(`length`,e),length:e=>O(`length`,e),upper:e=>O(`ascii_upcase`,e),lower:e=>O(`ascii_downcase`,e),trim:e=>O(`trim`,e),ltrim:e=>e.length===0?j(`ltrimstr`,[{type:`Literal`,value:` `}]):{type:`Pipe`,left:e[0],right:j(`ltrimstr`,[{type:`Literal`,value:` `}])},rtrim:e=>e.length===0?j(`rtrimstr`,[{type:`Literal`,value:` `}]):{type:`Pipe`,left:e[0],right:j(`rtrimstr`,[{type:`Literal`,value:` `}])},split:e=>O(`split`,e),join:e=>e.length===1?j(`join`,[{type:`Literal`,value:``}]):O(`join`,e),concat:e=>A(`+`,e[0],e[1]),startswith:e=>O(`startswith`,e),endswith:e=>O(`endswith`,e),contains:e=>O(`contains`,e),replace:e=>O(`gsub`,e),substr:e=>e.length===2?{type:`Slice`,base:e[0],start:e[1]}:{type:`Slice`,base:e[0],start:e[1],end:A(`+`,e[1],e[2])},abs:e=>O(`fabs`,e),floor:e=>O(`floor`,e),ceil:e=>O(`ceil`,e),round:e=>O(`round`,e),sqrt:e=>O(`sqrt`,e),log:e=>O(`log`,e),log10:e=>O(`log10`,e),log2:e=>O(`log2`,e),exp:e=>O(`exp`,e),sin:e=>O(`sin`,e),cos:e=>O(`cos`,e),tan:e=>O(`tan`,e),asin:e=>O(`asin`,e),acos:e=>O(`acos`,e),atan:e=>O(`atan`,e),min:e=>O(`min`,e),max:e=>O(`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=>j(`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=>j(`select`,e),empty:()=>j(`empty`,[]),count:()=>j(`length`,[]),sum:e=>e.length===0?j(`add`,[]):{type:`Pipe`,left:{type:`Array`,elements:e[0]},right:j(`add`,[])},mean:e=>e.length===0?{type:`Pipe`,left:{type:`Identity`},right:A(`/`,j(`add`,[]),j(`length`,[]))}:{type:`Pipe`,left:{type:`Array`,elements:e[0]},right:A(`/`,j(`add`,[]),j(`length`,[]))},avg:e=>e.length===0?{type:`Pipe`,left:{type:`Identity`},right:A(`/`,j(`add`,[]),j(`length`,[]))}:{type:`Pipe`,left:{type:`Array`,elements:e[0]},right:A(`/`,j(`add`,[]),j(`length`,[]))},type:`type`,isnull:e=>e.length===0?A(`==`,{type:`Identity`},{type:`Literal`,value:null}):A(`==`,e[0],{type:`Literal`,value:null}),isempty:e=>e.length===0?A(`==`,{type:`Identity`},{type:`Literal`,value:``}):A(`==`,e[0],{type:`Literal`,value:``}),tonumber:e=>e.length===0?j(`tonumber`,[]):j(`tonumber`,e),tostring:e=>e.length===0?j(`tostring`,[]):j(`tostring`,e),if:e=>N(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[t,...n]=e;return N(A(`and`,A(`!=`,t,{type:`Literal`,value:null}),A(`!=`,t,{type:`Literal`,value:``})),t,n.length===1?n[0]:k.coalesce(n))},index:()=>({type:`Field`,name:`_row_index`}),now:()=>j(`now`,[]),fmt:e=>j(`tostring`,e),format:e=>j(`tostring`,e)};Object.setPrototypeOf(k,null);function A(e,t,n){return{type:`BinaryOp`,op:e,left:t,right:n}}function j(e,t){return{type:`Call`,name:e,args:t}}var M=`then`;function N(e,t,n){let r=u({type:`Cond`,cond:e,elifs:[],else:n||{type:`Literal`,value:null}});return r[M]=t,r}function P(e){return{type:`Pipe`,left:e,right:{type:`Call`,name:`tostring`,args:[]}}}function F(e,t=!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 t?{type:`Field`,name:e.name}:{type:`VarRef`,name:e.name};case`lambdaBinding`:return{type:`VarRef`,name:e.name};case`func`:{let n=e.args.map(e=>F(e.expr,t)),r=Object.hasOwn(k,e.name)?k[e.name]:void 0;return typeof r==`function`?r(n):j(typeof r==`string`?r:e.name,n)}case`list`:return e.elements.length===0?{type:`Array`}:{type:`Array`,elements:e.elements.reduce((e,n,r)=>{let i=F(n,t);return r===0?i:{type:`Comma`,left:e,right:i}},null)};case`map`:return{type:`Object`,entries:e.entries.map(e=>({key:e.key,value:F(e.value,t)}))};case`regex`:return{type:`Literal`,value:e.pattern};case`slice`:return{type:`Slice`,start:e.start?F(e.start,t):void 0,end:e.end?F(e.end,t):void 0};case`lambda`:return F(e.body,t);case`pipeline`:return{type:`Identity`};default:throw Error(`Unknown moonblade expression type: ${e.type}`)}}function I(e){let t=[],n=0;for(;n<e.length;){for(;n<e.length&&(e[n]===` `||e[n]===`,`);)n++;if(n>=e.length)break;let r=n;for(;n<e.length&&/\w/.test(e[n]);)n++;let i=e.slice(r,n);for(;n<e.length&&e[n]===` `;)n++;if(e[n]!==`(`)break;n++;let a=1,o=n;for(;n<e.length&&a>0;)e[n]===`(`?a++:e[n]===`)`&&a--,a>0&&n++;let s=e.slice(o,n).trim();for(n++;n<e.length&&e[n]===` `;)n++;let c=``;if(e.slice(n,n+3).toLowerCase()===`as `){for(n+=3;n<e.length&&e[n]===` `;)n++;let t=n;for(;n<e.length&&/\w/.test(e[n]);)n++;c=e.slice(t,n)}c||=s?`${i}(${s})`:`${i}()`,t.push({func:i,expr:s,alias:c})}return t}function L(e){return/^\w+$/.test(e)}function R(e,t,n){let r=d(e,F(w(t)),n);return r.length>0?r[0]:null}function z(e,t,n={}){let{func:r,expr:i}=t;if(r===`count`&&!i)return e.length;let a;switch(a=L(i)?e.map(e=>e[i]).filter(e=>e!=null):e.map(e=>R(e,i,n)).filter(e=>e!=null),r){case`count`:return L(i)?a.length:a.filter(e=>!!e).length;case`sum`:return a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e))).reduce((e,t)=>e+t,0);case`mean`:case`avg`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e)));return e.length>0?e.reduce((e,t)=>e+t,0)/e.length:0}case`min`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e)));return e.length>0?Math.min(...e):null}case`max`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e)));return e.length>0?Math.max(...e):null}case`first`:return a.length>0?a[0]:null;case`last`:return a.length>0?a[a.length-1]:null;case`median`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e))).filter(e=>!Number.isNaN(e)).sort((e,t)=>e-t);if(e.length===0)return null;let t=Math.floor(e.length/2);return e.length%2==0?(e[t-1]+e[t])/2:e[t]}case`mode`:{let e=new Map;for(let t of a){let n=String(t);e.set(n,(e.get(n)||0)+1)}let t=0,n=null;for(let[r,i]of e)i>t&&(t=i,n=r);return n}case`cardinality`:return new Set(a.map(e=>String(e))).size;case`values`:return a.map(e=>String(e)).join(`|`);case`distinct_values`:return[...new Set(a.map(e=>String(e)))].sort().join(`|`);case`all`:if(e.length===0)return!0;for(let t of e)if(!R(t,i,n))return!1;return!0;case`any`:for(let t of e)if(R(t,i,n))return!0;return!1;default:return null}}function ee(e,t,n={}){let r=v();for(let i of t)_(r,i.alias,z(e,i,n));return r}async function te(e,t){let n=``,r=[];for(let t of e)t.startsWith(`-`)||(n?r.push(t):n=t);if(!n)return{stdout:``,stderr:`xan agg: no aggregation expression
|
|
4
|
+
`;break;case`r`:n+=`\r`;break;case`t`:n+=` `;break;case`\\`:n+=`\\`;break;case`"`:n+=`"`;break;case`'`:n+=`'`;break;case"`":n+="`";break;case`0`:n+=`\0`;break;default:n+=e}this.pos++}}else n+=r,this.pos++}throw Error(`Unterminated string starting at position ${t}`)}readRegex(){let e=this.pos;this.pos++;let t=``,n=``;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`;)n+=this.input[this.pos],this.pos++;return{type:`regex`,value:t+(n?`/${n}`:``),pos:e}}r===`\\`?(t+=r,this.pos++,this.pos<this.input.length&&(t+=this.input[this.pos],this.pos++)):(t+=r,this.pos++)}throw Error(`Unterminated regex starting at position ${e}`)}readIdentifier(){let e=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 n=this.input.slice(e,t?this.pos-1:this.pos);t&&(n+=`?`);let r=new Map([[`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`],[`_`,`_`]]),i=n.replace(/\?$/,``),a=r.get(i);return a!==void 0&&!t?{type:a,value:i,pos:e}:{type:`ident`,value:n,pos:e}}}}),S={};n(S,{parseMoonblade:()=>w,parseNamedExpressions:()=>C});function C(e){let t=[],n=new b(e).tokenize(),r=0,i=()=>n[r]||{type:`eof`,value:``,pos:0},a=()=>n[r++];for(;i().type!==`eof`;){if(i().type===`,`&&t.length>0){a();continue}let o=[],s=0,c=r;for(;i().type!==`eof`;){let e=i();if((e.type===`,`||e.type===`as`)&&s===0)break;(e.type===`(`||e.type===`[`||e.type===`{`)&&s++,(e.type===`)`||e.type===`]`||e.type===`}`)&&s--,o.push(a())}o.push({type:`eof`,value:``,pos:0});let l=new E(o).parse(),u;if(i().type===`as`)if(a(),i().type===`(`){a();let e=[];for(;i().type!==`)`&&i().type!==`eof`;)(i().type===`ident`||i().type===`string`)&&(e.push(i().value),a()),i().type===`,`&&a();i().type===`)`&&a(),u=e}else if(i().type===`ident`||i().type===`string`)u=i().value,a();else throw Error(`Expected name after 'as', got ${i().type}`);else u=e.slice(n[c].pos,n[r-1]?.pos||e.length).trim(),l.type===`identifier`&&(u=l.name);t.push({expr:l,name:u})}return t}function w(e){let t=new b(e).tokenize();return new E(t).parse()}var T,E,D=r(()=>{x(),T={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},E=class{pos=0;tokens;constructor(e){this.tokens=e}parse(){let e=this.parseExpr(0);if(this.peek().type!==`eof`)throw Error(`Unexpected token: ${this.peek().value}`);return e}parseExpr(e){let t=this.parsePrefix();for(;;){let n=this.peek(),r=this.getInfixPrec(n.type);if(r<e)break;t=this.parseInfix(t,r)}return t}parsePrefix(){let e=this.peek();switch(e.type){case`int`:return this.advance(),{type:`int`,value:Number.parseInt(e.value,10)};case`float`:return this.advance(),{type:`float`,value:Number.parseFloat(e.value)};case`string`:return this.advance(),{type:`string`,value:e.value};case`regex`:{this.advance();let t=e.value.split(`/`),n=t.length>1?t[t.length-1]:``;return{type:`regex`,pattern:t.slice(0,-1).join(`/`)||e.value,caseInsensitive:n.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=e.value,n=t.endsWith(`?`),r=n?t.slice(0,-1):t;if(this.advance(),this.peek().type===`(`)return this.parseFunctionCall(r);if(this.peek().type===`=>`){this.advance();let e=this.parseExpr(0);return this.bindLambdaArgs({type:`lambda`,params:[r],body:e},[r])}return{type:`identifier`,name:r,unsure:n}}case`(`:{this.advance();let e=this.pos;if(this.peek().type===`)`){if(this.advance(),this.peek().type===`=>`)return this.advance(),{type:`lambda`,params:[],body:this.parseExpr(0)};throw Error(`Empty parentheses not allowed`)}if(this.peek().type===`ident`){let t=[this.peek().value];this.advance();let n=!0;for(;this.peek().type===`,`;)if(this.advance(),this.peek().type===`ident`)t.push(this.peek().value),this.advance();else{n=!1;break}if(n&&this.peek().type===`)`&&this.peekAt(1).type===`=>`){this.advance(),this.advance();let e=this.parseExpr(0);return this.bindLambdaArgs({type:`lambda`,params:t,body:e},t)}this.pos=e}let t=this.parseExpr(0);return this.expect(`)`),t}case`[`:return this.parseList();case`{`:return this.parseMap();case`-`:{this.advance();let e=this.parseExpr(T.UNARY);return e.type===`int`?{type:`int`,value:-e.value}:e.type===`float`?{type:`float`,value:-e.value}:{type:`func`,name:`neg`,args:[{expr:e}]}}case`!`:return this.advance(),{type:`func`,name:`not`,args:[{expr:this.parseExpr(T.UNARY)}]};default:throw Error(`Unexpected token: ${e.type} (${e.value})`)}}parseFunctionCall(e){this.expect(`(`);let t=[];if(this.peek().type!==`)`)do{t.length>0&&this.peek().type===`,`&&this.advance();let e;if(this.peek().type===`ident`){let t=this.peek().value,n=this.pos+1;n<this.tokens.length&&this.tokens[n].type===`=`&&(e=t,this.advance(),this.advance())}let n=this.parseExpr(0);t.push({name:e,expr:n})}while(this.peek().type===`,`);return this.expect(`)`),{type:`func`,name:e.toLowerCase(),args:t}}parseList(){this.expect(`[`);let e=[];if(this.peek().type!==`]`)do e.length>0&&this.peek().type===`,`&&this.advance(),e.push(this.parseExpr(0));while(this.peek().type===`,`);return this.expect(`]`),{type:`list`,elements:e}}parseMap(){this.expect(`{`);let e=[];if(this.peek().type!==`}`)do{e.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 Error(`Expected map key, got ${this.peek().type}`);this.expect(`:`);let n=this.parseExpr(0);e.push({key:t,value:n})}while(this.peek().type===`,`);return this.expect(`}`),{type:`map`,entries:e}}parseInfix(e,t){let n=this.peek(),r=new Map([[`+`,`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`]]).get(n.type);if(r!==void 0){this.advance();let i=this.parseExpr(t+(this.isRightAssoc(n.type)?0:1));return{type:`func`,name:r,args:[{expr:e},{expr:i}]}}if(n.type===`|`){this.advance();let n=this.parseExpr(t);return this.handlePipe(e,n)}if(n.type===`.`)return this.advance(),this.handleDot(e);if(n.type===`[`)return this.advance(),this.handleIndexing(e);if(n.type===`in`)return this.advance(),{type:`func`,name:`contains`,args:[{expr:this.parseExpr(t+1)},{expr:e}]};if(n.type===`not in`)return this.advance(),{type:`func`,name:`not`,args:[{expr:{type:`func`,name:`contains`,args:[{expr:this.parseExpr(t+1)},{expr:e}]}}]};throw Error(`Unexpected infix token: ${n.type}`)}handlePipe(e,t){if(t.type===`identifier`)return{type:`func`,name:t.name,args:[{expr:e}]};if(t.type===`func`){let n=this.countUnderscores(t);return n===0?t:n===1?this.fillUnderscore(t,e):{type:`pipeline`,exprs:[e,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,e):t}handleDot(e){let t=this.peek();if(t.type===`ident`){let n=t.value;if(this.advance(),this.peek().type===`(`){let t=this.parseFunctionCall(n);return t.type===`func`&&t.args.unshift({expr:e}),t}return{type:`func`,name:`get`,args:[{expr:e},{expr:{type:`string`,value:n}}]}}if(t.type===`int`){let n=Number.parseInt(t.value,10);return this.advance(),{type:`func`,name:`get`,args:[{expr:e},{expr:{type:`int`,value:n}}]}}if(t.type===`string`){let n=t.value;return this.advance(),{type:`func`,name:`get`,args:[{expr:e},{expr:{type:`string`,value:n}}]}}throw Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(e){if(this.peek().type===`:`){if(this.advance(),this.peek().type===`]`)return this.advance(),{type:`func`,name:`slice`,args:[{expr:e}]};let t=this.parseExpr(0);return this.expect(`]`),{type:`func`,name:`slice`,args:[{expr:e},{expr:{type:`int`,value:0}},{expr:t}]}}let t=this.parseExpr(0);if(this.peek().type===`:`){if(this.advance(),this.peek().type===`]`)return this.advance(),{type:`func`,name:`slice`,args:[{expr:e},{expr:t}]};let n=this.parseExpr(0);return this.expect(`]`),{type:`func`,name:`slice`,args:[{expr:e},{expr:t},{expr:n}]}}return this.expect(`]`),{type:`func`,name:`get`,args:[{expr:e},{expr:t}]}}countUnderscores(e){return e.type===`underscore`?1:e.type===`func`?e.args.reduce((e,t)=>e+this.countUnderscores(t.expr),0):e.type===`list`?e.elements.reduce((e,t)=>e+this.countUnderscores(t),0):e.type===`map`?e.entries.reduce((e,t)=>e+this.countUnderscores(t.value),0):0}fillUnderscore(e,t){return e.type===`underscore`?t:e.type===`func`?{...e,args:e.args.map(e=>({...e,expr:this.fillUnderscore(e.expr,t)}))}:e.type===`list`?{...e,elements:e.elements.map(e=>this.fillUnderscore(e,t))}:e.type===`map`?{...e,entries:e.entries.map(e=>({...e,value:this.fillUnderscore(e.value,t)}))}:e}bindLambdaArgs(e,t){return{...e,body:this.bindLambdaArgsInExpr(e.body,t)}}bindLambdaArgsInExpr(e,t){return e.type===`identifier`&&t.includes(e.name)?{type:`lambdaBinding`,name:e.name}:e.type===`func`?{...e,args:e.args.map(e=>({...e,expr:this.bindLambdaArgsInExpr(e.expr,t)}))}:e.type===`list`?{...e,elements:e.elements.map(e=>this.bindLambdaArgsInExpr(e,t))}:e.type===`map`?{...e,entries:e.entries.map(e=>({...e,value:this.bindLambdaArgsInExpr(e.value,t)}))}:e}getInfixPrec(e){switch(e){case`|`:return T.PIPE;case`||`:case`or`:return T.OR;case`&&`:case`and`:return T.AND;case`==`:case`!=`:case`eq`:case`ne`:return T.EQUALITY;case`<`:case`<=`:case`>`:case`>=`:case`lt`:case`le`:case`gt`:case`ge`:case`in`:case`not in`:return T.COMPARISON;case`+`:case`-`:case`++`:return T.ADDITIVE;case`*`:case`/`:case`//`:case`%`:return T.MULTIPLICATIVE;case`**`:return T.POWER;case`.`:case`[`:return T.POSTFIX;default:return-1}}isRightAssoc(e){return e===`**`}peek(){return this.tokens[this.pos]||{type:`eof`,value:``,pos:0}}peekAt(e){return this.tokens[this.pos+e]||{type:`eof`,value:``,pos:0}}advance(){return this.tokens[this.pos++]}expect(e){let t=this.peek();if(t.type!==e)throw Error(`Expected ${e}, got ${t.type}`);return this.advance()}}});D();function O(e,t){return t.length===0?j(e,[]):t.length===1?{type:`Pipe`,left:t[0],right:j(e,[])}:{type:`Pipe`,left:t[0],right:j(e,t.slice(1))}}var k={add:e=>A(`+`,e[0],e[1]),sub:e=>A(`-`,e[0],e[1]),mul:e=>A(`*`,e[0],e[1]),div:e=>A(`/`,e[0],e[1]),mod:e=>A(`%`,e[0],e[1]),idiv:e=>j(`floor`,[A(`/`,e[0],e[1])]),pow:e=>O(`pow`,e),neg:e=>({type:`UnaryOp`,op:`-`,operand:e[0]}),"==":e=>A(`==`,e[0],e[1]),"!=":e=>A(`!=`,e[0],e[1]),"<":e=>A(`<`,e[0],e[1]),"<=":e=>A(`<=`,e[0],e[1]),">":e=>A(`>`,e[0],e[1]),">=":e=>A(`>=`,e[0],e[1]),eq:e=>A(`==`,P(e[0]),P(e[1])),ne:e=>A(`!=`,P(e[0]),P(e[1])),lt:e=>A(`<`,P(e[0]),P(e[1])),le:e=>A(`<=`,P(e[0]),P(e[1])),gt:e=>A(`>`,P(e[0]),P(e[1])),ge:e=>A(`>=`,P(e[0]),P(e[1])),and:e=>A(`and`,e[0],e[1]),or:e=>A(`or`,e[0],e[1]),not:e=>({type:`UnaryOp`,op:`not`,operand:e[0]}),len:e=>O(`length`,e),length:e=>O(`length`,e),upper:e=>O(`ascii_upcase`,e),lower:e=>O(`ascii_downcase`,e),trim:e=>O(`trim`,e),ltrim:e=>e.length===0?j(`ltrimstr`,[{type:`Literal`,value:` `}]):{type:`Pipe`,left:e[0],right:j(`ltrimstr`,[{type:`Literal`,value:` `}])},rtrim:e=>e.length===0?j(`rtrimstr`,[{type:`Literal`,value:` `}]):{type:`Pipe`,left:e[0],right:j(`rtrimstr`,[{type:`Literal`,value:` `}])},split:e=>O(`split`,e),join:e=>e.length===1?j(`join`,[{type:`Literal`,value:``}]):O(`join`,e),concat:e=>A(`+`,e[0],e[1]),startswith:e=>O(`startswith`,e),endswith:e=>O(`endswith`,e),contains:e=>O(`contains`,e),replace:e=>O(`gsub`,e),substr:e=>e.length===2?{type:`Slice`,base:e[0],start:e[1]}:{type:`Slice`,base:e[0],start:e[1],end:A(`+`,e[1],e[2])},abs:e=>O(`fabs`,e),floor:e=>O(`floor`,e),ceil:e=>O(`ceil`,e),round:e=>O(`round`,e),sqrt:e=>O(`sqrt`,e),log:e=>O(`log`,e),log10:e=>O(`log10`,e),log2:e=>O(`log2`,e),exp:e=>O(`exp`,e),sin:e=>O(`sin`,e),cos:e=>O(`cos`,e),tan:e=>O(`tan`,e),asin:e=>O(`asin`,e),acos:e=>O(`acos`,e),atan:e=>O(`atan`,e),min:e=>O(`min`,e),max:e=>O(`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=>j(`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=>j(`select`,e),empty:()=>j(`empty`,[]),count:()=>j(`length`,[]),sum:e=>e.length===0?j(`add`,[]):{type:`Pipe`,left:{type:`Array`,elements:e[0]},right:j(`add`,[])},mean:e=>e.length===0?{type:`Pipe`,left:{type:`Identity`},right:A(`/`,j(`add`,[]),j(`length`,[]))}:{type:`Pipe`,left:{type:`Array`,elements:e[0]},right:A(`/`,j(`add`,[]),j(`length`,[]))},avg:e=>e.length===0?{type:`Pipe`,left:{type:`Identity`},right:A(`/`,j(`add`,[]),j(`length`,[]))}:{type:`Pipe`,left:{type:`Array`,elements:e[0]},right:A(`/`,j(`add`,[]),j(`length`,[]))},type:`type`,isnull:e=>e.length===0?A(`==`,{type:`Identity`},{type:`Literal`,value:null}):A(`==`,e[0],{type:`Literal`,value:null}),isempty:e=>e.length===0?A(`==`,{type:`Identity`},{type:`Literal`,value:``}):A(`==`,e[0],{type:`Literal`,value:``}),tonumber:e=>e.length===0?j(`tonumber`,[]):j(`tonumber`,e),tostring:e=>e.length===0?j(`tostring`,[]):j(`tostring`,e),if:e=>N(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[t,...n]=e;return N(A(`and`,A(`!=`,t,{type:`Literal`,value:null}),A(`!=`,t,{type:`Literal`,value:``})),t,n.length===1?n[0]:k.coalesce(n))},index:()=>({type:`Field`,name:`_row_index`}),now:()=>j(`now`,[]),fmt:e=>j(`tostring`,e),format:e=>j(`tostring`,e)};Object.setPrototypeOf(k,null);function A(e,t,n){return{type:`BinaryOp`,op:e,left:t,right:n}}function j(e,t){return{type:`Call`,name:e,args:t}}var M=`then`;function N(e,t,n){let r=u({type:`Cond`,cond:e,elifs:[],else:n||{type:`Literal`,value:null}});return r[M]=t,r}function P(e){return{type:`Pipe`,left:e,right:{type:`Call`,name:`tostring`,args:[]}}}function F(e,t=!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 t?{type:`Field`,name:e.name}:{type:`VarRef`,name:e.name};case`lambdaBinding`:return{type:`VarRef`,name:e.name};case`func`:{let n=e.args.map(e=>F(e.expr,t)),r=Object.hasOwn(k,e.name)?k[e.name]:void 0;return typeof r==`function`?r(n):j(typeof r==`string`?r:e.name,n)}case`list`:return e.elements.length===0?{type:`Array`}:{type:`Array`,elements:e.elements.reduce((e,n,r)=>{let i=F(n,t);return r===0?i:{type:`Comma`,left:e,right:i}},null)};case`map`:return{type:`Object`,entries:e.entries.map(e=>({key:e.key,value:F(e.value,t)}))};case`regex`:return{type:`Literal`,value:e.pattern};case`slice`:return{type:`Slice`,start:e.start?F(e.start,t):void 0,end:e.end?F(e.end,t):void 0};case`lambda`:return F(e.body,t);case`pipeline`:return{type:`Identity`};default:throw Error(`Unknown moonblade expression type: ${e.type}`)}}function I(e){let t=[],n=0;for(;n<e.length;){for(;n<e.length&&(e[n]===` `||e[n]===`,`);)n++;if(n>=e.length)break;let r=n;for(;n<e.length&&/\w/.test(e[n]);)n++;let i=e.slice(r,n);for(;n<e.length&&e[n]===` `;)n++;if(e[n]!==`(`)break;n++;let a=1,o=n;for(;n<e.length&&a>0;)e[n]===`(`?a++:e[n]===`)`&&a--,a>0&&n++;let s=e.slice(o,n).trim();for(n++;n<e.length&&e[n]===` `;)n++;let c=``;if(e.slice(n,n+3).toLowerCase()===`as `){for(n+=3;n<e.length&&e[n]===` `;)n++;let t=n;for(;n<e.length&&/\w/.test(e[n]);)n++;c=e.slice(t,n)}c||=s?`${i}(${s})`:`${i}()`,t.push({func:i,expr:s,alias:c})}return t}function L(e){return/^\w+$/.test(e)}function R(e,t,n){let r=d(e,F(w(t)),n);return r.length>0?r[0]:null}function z(e,t,n={}){let{func:r,expr:i}=t;if(r===`count`&&!i)return e.length;let a;switch(a=L(i)?e.map(e=>e[i]).filter(e=>e!=null):e.map(e=>R(e,i,n)).filter(e=>e!=null),r){case`count`:return L(i)?a.length:a.filter(e=>!!e).length;case`sum`:return a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e))).reduce((e,t)=>e+t,0);case`mean`:case`avg`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e)));return e.length>0?e.reduce((e,t)=>e+t,0)/e.length:0}case`min`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e)));return e.length>0?Math.min(...e):null}case`max`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e)));return e.length>0?Math.max(...e):null}case`first`:return a.length>0?a[0]:null;case`last`:return a.length>0?a[a.length-1]:null;case`median`:{let e=a.map(e=>typeof e==`number`?e:Number.parseFloat(String(e))).filter(e=>!Number.isNaN(e)).sort((e,t)=>e-t);if(e.length===0)return null;let t=Math.floor(e.length/2);return e.length%2==0?(e[t-1]+e[t])/2:e[t]}case`mode`:{let e=new Map;for(let t of a){let n=String(t);e.set(n,(e.get(n)||0)+1)}let t=0,n=null;for(let[r,i]of e)i>t&&(t=i,n=r);return n}case`cardinality`:return new Set(a.map(e=>String(e))).size;case`values`:return a.map(e=>String(e)).join(`|`);case`distinct_values`:return[...new Set(a.map(e=>String(e)))].sort().join(`|`);case`all`:if(e.length===0)return!0;for(let t of e)if(!R(t,i,n))return!1;return!0;case`any`:for(let t of e)if(R(t,i,n))return!0;return!1;default:return null}}function ee(e,t,n={}){let r=v();for(let i of t)_(r,i.alias,z(e,i,n));return r}async function te(e,t){let n=``,r=[];for(let t of e)t.startsWith(`-`)||(n?r.push(t):n=t);if(!n)return{stdout:``,stderr:`xan agg: no aggregation expression
|
|
5
5
|
`,exitCode:1};let{data:i,error:a}=await g(r,t);if(a)return a;let o={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},s=I(n);return{stdout:h(s.map(e=>e.alias),[ee(i,s,o)]),stderr:``,exitCode:0}}async function ne(e,t){let n=``,r=``,i=[];for(let t=0;t<e.length;t++){let a=e[t];a===`--sorted`||a.startsWith(`-`)||(n?r?i.push(a):r=a:n=a)}if(!n||!r)return{stdout:``,stderr:`xan groupby: usage: xan groupby COLS EXPR [FILE]
|
|
6
|
-
`,exitCode:1};let{data:a,error:o}=await g(i,t);if(o)return o;let s={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},c=n.split(`,`),l=I(r),u=[],d=new Map;for(let e of a){let t=c.map(t=>String(e[t])).join(`\0`);d.has(t)||(d.set(t,[]),u.push(t)),d.get(t)?.push(e)}let f=[...c,...l.map(e=>e.alias)],p=[];for(let e of u){let t=d.get(e);if(!t)continue;let n=v();for(let e of c)_(n,e,t[0][e]);for(let e of l)_(n,e.alias,z(t,e,s));p.push(n)}return{stdout:h(f,p),stderr:``,exitCode:0}}async function re(e,t){let n=[],r=``,i=10,a=!1,o=[];for(let t=0;t<e.length;t++){let s=e[t];(s===`-s`||s===`--select`)&&t+1<e.length?n=e[++t].split(`,`):(s===`-g`||s===`--groupby`)&&t+1<e.length?r=e[++t]:(s===`-l`||s===`--limit`)&&t+1<e.length?i=Number.parseInt(e[++t],10):s===`--no-extra`?a=!0:s===`-A`||s===`--all`?i=0:s.startsWith(`-`)||o.push(s)}let{headers:s,data:c,error:l}=await g(o,t);if(l)return l;let u=n.length>0?n:s.filter(e=>e!==r);r&&n.length===0&&(u=s.filter(e=>e!==r));let d=[],f=r?[`field`,r,`value`,`count`]:[`field`,`value`,`count`];if(r){let e=new Map;for(let t of c){let n=String(t[r]??``);e.has(n)||e.set(n,[]),e.get(n)?.push(t)}for(let t of u)for(let[n,o]of e){let e=new Map;for(let n of o){let r=n[t],i=r===``||r==null?``:String(r);e.set(i,(e.get(i)||0)+1)}let s=[...e.entries()].sort((e,t)=>t[1]===e[1]?e[0].localeCompare(t[0]):t[1]-e[1]);a&&(s=s.filter(([e])=>e!==``)),i>0&&(s=s.slice(0,i));for(let[e,i]of s)d.push({field:t,[r]:n,value:e===``?`<empty>`:e,count:i})}}else for(let e of u){let t=new Map;for(let n of c){let r=n[e],i=r===``||r==null?``:String(r);t.set(i,(t.get(i)||0)+1)}let n=[...t.entries()].sort((e,t)=>t[1]===e[1]?e[0].localeCompare(t[0]):t[1]-e[1]);a&&(n=n.filter(([e])=>e!==``)),i>0&&(n=n.slice(0,i));for(let[t,r]of n)d.push({field:e,value:t===``?`<empty>`:t,count:r})}return{stdout:h(f,d),stderr:``,exitCode:0}}async function ie(e,t){let n=[],r=[];for(let t=0;t<e.length;t++){let i=e[t];i===`-s`&&t+1<e.length?n=e[++t].split(`,`):i.startsWith(`-`)||r.push(i)}let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=n.length>0?n:i,c=[`field`,`type`,`count`,`min`,`max`,`mean`],l=[];for(let e of s){let t=a.map(t=>t[e]).filter(e=>e!=null),n=t.map(e=>typeof e==`number`?e:Number.parseFloat(String(e))).filter(e=>!Number.isNaN(e)),r=n.length===t.length&&n.length>0;l.push({field:e,type:r?`Number`:`String`,count:t.length,min:r?Math.min(...n):``,max:r?Math.max(...n):``,mean:r?Math.round(n.reduce((e,t)=>e+t,0)/n.length*1e10)/1e10:``})}return{stdout:h(c,l),stderr:``,exitCode:0}}D();function
|
|
7
|
-
`,exitCode:1};let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=
|
|
8
|
-
`,exitCode:1};let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=new Set(
|
|
9
|
-
`,exitCode:1};let{headers:a,data:o,error:s}=await g(i,t);if(s)return s;let c;if(r){let e=r.split(`,`),t=n.split(`,`),i=new Map;for(let n=0;n<e.length&&n<t.length;n++)i.set(e[n],t[n]);c=a.map(e=>i.get(e)||e)}else{let e=n.split(`,`);c=a.map((t,n)=>n<e.length?e[n]:t)}let l=o.map(e=>{let t=v();for(let n=0;n<a.length;n++)_(t,c[n],e[a[n]]);return t});return{stdout:h(c,l),stderr:``,exitCode:0}}async function
|
|
6
|
+
`,exitCode:1};let{data:a,error:o}=await g(i,t);if(o)return o;let s={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},c=n.split(`,`),l=I(r),u=[],d=new Map;for(let e of a){let t=c.map(t=>String(e[t])).join(`\0`);d.has(t)||(d.set(t,[]),u.push(t)),d.get(t)?.push(e)}let f=[...c,...l.map(e=>e.alias)],p=[];for(let e of u){let t=d.get(e);if(!t)continue;let n=v();for(let e of c)_(n,e,t[0][e]);for(let e of l)_(n,e.alias,z(t,e,s));p.push(n)}return{stdout:h(f,p),stderr:``,exitCode:0}}async function re(e,t){let n=[],r=``,i=10,a=!1,o=[];for(let t=0;t<e.length;t++){let s=e[t];(s===`-s`||s===`--select`)&&t+1<e.length?n=e[++t].split(`,`):(s===`-g`||s===`--groupby`)&&t+1<e.length?r=e[++t]:(s===`-l`||s===`--limit`)&&t+1<e.length?i=Number.parseInt(e[++t],10):s===`--no-extra`?a=!0:s===`-A`||s===`--all`?i=0:s.startsWith(`-`)||o.push(s)}let{headers:s,data:c,error:l}=await g(o,t);if(l)return l;let u=n.length>0?n:s.filter(e=>e!==r);r&&n.length===0&&(u=s.filter(e=>e!==r));let d=[],f=r?[`field`,r,`value`,`count`]:[`field`,`value`,`count`];if(r){let e=new Map;for(let t of c){let n=String(t[r]??``);e.has(n)||e.set(n,[]),e.get(n)?.push(t)}for(let t of u)for(let[n,o]of e){let e=new Map;for(let n of o){let r=n[t],i=r===``||r==null?``:String(r);e.set(i,(e.get(i)||0)+1)}let s=[...e.entries()].sort((e,t)=>t[1]===e[1]?e[0].localeCompare(t[0]):t[1]-e[1]);a&&(s=s.filter(([e])=>e!==``)),i>0&&(s=s.slice(0,i));for(let[e,i]of s)d.push({field:t,[r]:n,value:e===``?`<empty>`:e,count:i})}}else for(let e of u){let t=new Map;for(let n of c){let r=n[e],i=r===``||r==null?``:String(r);t.set(i,(t.get(i)||0)+1)}let n=[...t.entries()].sort((e,t)=>t[1]===e[1]?e[0].localeCompare(t[0]):t[1]-e[1]);a&&(n=n.filter(([e])=>e!==``)),i>0&&(n=n.slice(0,i));for(let[t,r]of n)d.push({field:e,value:t===``?`<empty>`:t,count:r})}return{stdout:h(f,d),stderr:``,exitCode:0}}async function ie(e,t){let n=[],r=[];for(let t=0;t<e.length;t++){let i=e[t];i===`-s`&&t+1<e.length?n=e[++t].split(`,`):i.startsWith(`-`)||r.push(i)}let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=n.length>0?n:i,c=[`field`,`type`,`count`,`min`,`max`,`mean`],l=[];for(let e of s){let t=a.map(t=>t[e]).filter(e=>e!=null),n=t.map(e=>typeof e==`number`?e:Number.parseFloat(String(e))).filter(e=>!Number.isNaN(e)),r=n.length===t.length&&n.length>0;l.push({field:e,type:r?`Number`:`String`,count:t.length,min:r?Math.min(...n):``,max:r?Math.max(...n):``,mean:r?Math.round(n.reduce((e,t)=>e+t,0)/n.length*1e10)/1e10:``})}return{stdout:h(c,l),stderr:``,exitCode:0}}D();function ae(e){return F(w(e))}function B(t){return e(`^${t.replace(/[.+?^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)}$`)}function V(e,t){let n=[],r=new Set;for(let i of e.split(`,`)){let e=i.trim();if(e.startsWith(`!`)){let n=V(e.slice(1),t);for(let e of n)r.add(e);continue}if(e===`*`){for(let e of t)n.includes(e)||n.push(e);continue}if(e.includes(`*`)){let r=B(e);for(let e of t)r.test(e)&&!n.includes(e)&&n.push(e);continue}let a=e.match(/^([^:]*):([^:]*)$/);if(a&&(a[1]||a[2])){let e=a[1],r=a[2],i=e?t.indexOf(e):0,o=r?t.indexOf(r):t.length-1;if(i!==-1&&o!==-1){let e=i<=o?1:-1;for(let r=i;e>0?r<=o:r>=o;r+=e)n.includes(t[r])||n.push(t[r])}continue}let o=e.match(/^(\d+)-(\d+)$/);if(o){let e=Number.parseInt(o[1],10),r=Number.parseInt(o[2],10);for(let i=e;i<=r&&i<t.length;i++)n.push(t[i]);continue}let s=Number.parseInt(e,10);if(!Number.isNaN(s)&&s>=0&&s<t.length){n.push(t[s]);continue}t.includes(e)&&n.push(e)}return r.size>0?n.filter(e=>!r.has(e)):n}async function H(e,t){let n=``,r=[];for(let t of e)t.startsWith(`-`)||(n?r.push(t):n=t);if(!n)return{stdout:``,stderr:`xan select: no columns specified
|
|
7
|
+
`,exitCode:1};let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=V(n,i);return{stdout:h(s,a.map(e=>{let t=v();for(let n of s)_(t,n,e[n]);return t})),stderr:``,exitCode:0}}async function U(e,t){let n=``,r=[];for(let t of e)t.startsWith(`-`)||(n?r.push(t):n=t);if(!n)return{stdout:``,stderr:`xan drop: no columns specified
|
|
8
|
+
`,exitCode:1};let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=new Set(V(n,i)),c=i.filter(e=>!s.has(e));return{stdout:h(c,a.map(e=>{let t=v();for(let n of c)_(t,n,e[n]);return t})),stderr:``,exitCode:0}}async function W(e,t){let n=``,r=``,i=[];for(let t=0;t<e.length;t++){let a=e[t];a===`-s`&&t+1<e.length?r=e[++t]:a.startsWith(`-`)||(n?i.push(a):n=a)}if(!n)return{stdout:``,stderr:`xan rename: no new name(s) specified
|
|
9
|
+
`,exitCode:1};let{headers:a,data:o,error:s}=await g(i,t);if(s)return s;let c;if(r){let e=r.split(`,`),t=n.split(`,`),i=new Map;for(let n=0;n<e.length&&n<t.length;n++)i.set(e[n],t[n]);c=a.map(e=>i.get(e)||e)}else{let e=n.split(`,`);c=a.map((t,n)=>n<e.length?e[n]:t)}let l=o.map(e=>{let t=v();for(let n=0;n<a.length;n++)_(t,c[n],e[a[n]]);return t});return{stdout:h(c,l),stderr:``,exitCode:0}}async function G(e,t){let n=`index`,r=[];for(let t=0;t<e.length;t++)e[t]===`-c`&&t+1<e.length?n=e[++t]:r.push(e[t]);let{headers:i,data:a,error:o}=await g(r,t);return o||{stdout:h([n,...i],a.map((e,t)=>{let r=v();_(r,n,t);for(let t of i)_(r,t,e[t]);return r})),stderr:``,exitCode:0}}async function K(e,t){let n=e.includes(`-j`)||e.includes(`--just-names`),{headers:r,error:i}=await g(e.filter(e=>e!==`-j`&&e!==`--just-names`),t);return i||{stdout:n?`${r.map(e=>e).join(`
|
|
10
10
|
`)}
|
|
11
11
|
`:`${r.map((e,t)=>`${t} ${e}`).join(`
|
|
12
12
|
`)}
|
|
13
|
-
`,stderr:``,exitCode:0}}async function
|
|
14
|
-
`,stderr:``,exitCode:0}}async function
|
|
15
|
-
`,exitCode:1}}let s=
|
|
13
|
+
`,stderr:``,exitCode:0}}async function q(e,t){let{data:n,error:r}=await g(e,t);return r||{stdout:`${n.length}
|
|
14
|
+
`,stderr:``,exitCode:0}}async function J(e,t){let n=10,r=[];for(let t=0;t<e.length;t++)(e[t]===`-l`||e[t]===`-n`)&&t+1<e.length?n=Number.parseInt(e[++t],10):r.push(e[t]);let{headers:i,data:a,error:o}=await g(r,t);return o||{stdout:h(i,a.slice(0,n)),stderr:``,exitCode:0}}async function oe(e,t){let n=10,r=[];for(let t=0;t<e.length;t++)(e[t]===`-l`||e[t]===`-n`)&&t+1<e.length?n=Number.parseInt(e[++t],10):r.push(e[t]);let{headers:i,data:a,error:o}=await g(r,t);return o||{stdout:h(i,a.slice(-n)),stderr:``,exitCode:0}}async function se(e,t){let n,r,i,a=[];for(let t=0;t<e.length;t++){let o=e[t];(o===`-s`||o===`--start`)&&t+1<e.length?n=Number.parseInt(e[++t],10):(o===`-e`||o===`--end`)&&t+1<e.length?r=Number.parseInt(e[++t],10):(o===`-l`||o===`--len`)&&t+1<e.length?i=Number.parseInt(e[++t],10):o.startsWith(`-`)||a.push(o)}let{headers:o,data:s,error:c}=await g(a,t);if(c)return c;let l=n??0,u;return u=i===void 0?r===void 0?s.length:r:l+i,{stdout:h(o,s.slice(l,u)),stderr:``,exitCode:0}}async function ce(e,t){let{headers:n,data:r,error:i}=await g(e,t);return i||{stdout:h(n,[...r].reverse()),stderr:``,exitCode:0}}var Y=t(c(),1);async function le(e,t){let{headers:n,data:r,error:i}=await g(e.filter(e=>!e.startsWith(`-`)),t);if(i)return i;if(r.length===0)return{stdout:h([`column`],n.map(e=>({column:e}))),stderr:``,exitCode:0};let a=n[0],o=[a,...r.map((e,t)=>String(e[a]??`row_${t}`))],s=[];for(let e=1;e<n.length;e++){let t=n[e],i=v();_(i,a,t);for(let e=0;e<r.length;e++)_(i,o[e+1],r[e][t]);s.push(i)}return{stdout:h(o,s),stderr:``,exitCode:0}}async function ue(e,t){let n=null,r=[];for(let t=0;t<e.length;t++){let i=e[t];i===`--seed`&&t+1<e.length?n=Number.parseInt(e[++t],10):i.startsWith(`-`)||r.push(i)}let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=n===null?Date.now():n,c=()=>(s=s*1103515245+12345&2147483647,s/2147483647),l=[...a];for(let e=l.length-1;e>0;e--){let t=Math.floor(c()*(e+1));[l[e],l[t]]=[l[t],l[e]]}return{stdout:h(i,l),stderr:``,exitCode:0}}async function de(e,t){let n=null,r=``,i=[];for(let t=0;t<e.length;t++){let a=e[t];(a===`-l`||a===`--length`)&&t+1<e.length?n=Number.parseInt(e[++t],10):(a===`-d`||a===`--default`)&&t+1<e.length?r=e[++t]:a.startsWith(`-`)||i.push(a)}let a=i[0],o;if(!a||a===`-`)o=t.stdin;else try{let e=t.fs.resolvePath(t.cwd,a);o=await t.fs.readFile(e)}catch{return{stdout:``,stderr:`xan fixlengths: ${a}: No such file or directory
|
|
15
|
+
`,exitCode:1}}let s=Y.default.parse(o.trim(),{header:!1,skipEmptyLines:!0}).data;if(s.length===0)return{stdout:``,stderr:``,exitCode:0};let c=Math.max(...s.map(e=>e.length)),l=n??c,u=s.map(e=>e.length===l?e:e.length<l?[...e,...Array(l-e.length).fill(r)]:e.slice(0,l));return{stdout:`${Y.default.unparse(u).replace(/\r\n/g,`
|
|
16
16
|
`)}
|
|
17
|
-
`,stderr:``,exitCode:0}}async function
|
|
17
|
+
`,stderr:``,exitCode:0}}async function fe(e,t){let n=null,r=null,i=`.`,a=[];for(let t=0;t<e.length;t++){let o=e[t];(o===`-c`||o===`--chunks`)&&t+1<e.length?n=Number.parseInt(e[++t],10):(o===`-S`||o===`--size`)&&t+1<e.length?r=Number.parseInt(e[++t],10):(o===`-o`||o===`--output`)&&t+1<e.length?i=e[++t]:o.startsWith(`-`)||a.push(o)}if(!n&&!r)return{stdout:``,stderr:`xan split: must specify -c or -S
|
|
18
18
|
`,exitCode:1};let{headers:o,data:s,error:c}=await g(a,t);if(c)return c;let l=[];if(n){let e=Math.ceil(s.length/n);for(let t=0;t<n;t++)l.push(s.slice(t*e,(t+1)*e))}else if(r)for(let e=0;e<s.length;e+=r)l.push(s.slice(e,e+r));let u=l.filter(e=>e.length>0),d=a[0]?.replace(/\.csv$/,``)||`part`;try{let e=t.fs.resolvePath(t.cwd,i);for(let n=0;n<u.length;n++){let r=`${d}_${String(n+1).padStart(3,`0`)}.csv`,i=t.fs.resolvePath(e,r);await t.fs.writeFile(i,h(o,u[n]))}return{stdout:`Split into ${u.length} parts
|
|
19
19
|
`,stderr:``,exitCode:0}}catch{return{stdout:`${u.map((e,t)=>`Part ${t+1}: ${e.length} rows`).join(`
|
|
20
20
|
`)}
|
|
21
|
-
`,stderr:``,exitCode:0}}}async function
|
|
21
|
+
`,stderr:``,exitCode:0}}}function X(e){return e.replace(/[^a-zA-Z0-9_-]/g,`_`)||`empty`}function pe(e){let t=2166136261;for(let n=0;n<e.length;n++)t=(t^e.charCodeAt(n))*16777619>>>0;return t.toString(36).padStart(6,`0`).slice(0,6)}async function me(e,t){let n=``,r=`.`,i=[];for(let t=0;t<e.length;t++){let a=e[t];(a===`-o`||a===`--output`)&&t+1<e.length?r=e[++t]:a.startsWith(`-`)||(n?i.push(a):n=a)}if(!n)return{stdout:``,stderr:`xan partition: usage: xan partition COLUMN [FILE]
|
|
22
22
|
`,exitCode:1};let{headers:a,data:o,error:s}=await g(i,t);if(s)return s;if(!a.includes(n))return{stdout:``,stderr:`xan partition: column '${n}' not found
|
|
23
|
-
`,exitCode:1};let c=new Map;for(let e of o){let t=String(e[n]??``);c.has(t)||c.set(t,[]),c.get(t)?.push(e)}try{let e=t.fs.resolvePath(t.cwd,r);for(let[n,r]of c){let i
|
|
23
|
+
`,exitCode:1};let c=new Map;for(let e of o){let t=String(e[n]??``);c.has(t)||c.set(t,[]),c.get(t)?.push(e)}let l=new Map;for(let e of c.keys()){let t=X(e);l.set(t,(l.get(t)??0)+1)}let u=new Set,d=new Map;for(let e of c.keys()){let t=X(e),n=(l.get(t)??0)>1?`${t}_${pe(e)}`:t,r=`${n}.csv`,i=1;for(;u.has(r);)r=`${n}_${i}.csv`,i++;u.add(r),d.set(e,r)}try{let e=t.fs.resolvePath(t.cwd,r);for(let[n,r]of c){let i=d.get(n);if(!i)continue;let o=t.fs.resolvePath(e,i);await t.fs.writeFile(o,h(a,r))}return{stdout:`Partitioned into ${c.size} files by '${n}'
|
|
24
24
|
`,stderr:``,exitCode:0}}catch{return{stdout:`${Array.from(c.entries()).map(([e,t])=>`${e}: ${t.length} rows`).join(`
|
|
25
25
|
`)}
|
|
26
|
-
`,stderr:``,exitCode:0}}}async function
|
|
27
|
-
`,exitCode:1};let n=e[0],r=e.slice(1);return n===`json`?
|
|
28
|
-
`,exitCode:1}}async function
|
|
29
|
-
`,stderr:``,exitCode:0}}async function
|
|
26
|
+
`,stderr:``,exitCode:0}}}async function he(e,t){if(e.length===0)return{stdout:``,stderr:`xan to: usage: xan to <format> [FILE]
|
|
27
|
+
`,exitCode:1};let n=e[0],r=e.slice(1);return n===`json`?ge(r,t):{stdout:``,stderr:`xan to: unsupported format '${n}'
|
|
28
|
+
`,exitCode:1}}async function ge(e,t){let{data:n,error:r}=await g(e.filter(e=>!e.startsWith(`-`)),t);return r||{stdout:`${JSON.stringify(n,null,2)}
|
|
29
|
+
`,stderr:``,exitCode:0}}async function _e(e,t){let n=``,r=[];for(let t=0;t<e.length;t++){let i=e[t];(i===`-f`||i===`--format`)&&t+1<e.length?n=e[++t]:i.startsWith(`-`)||r.push(i)}return n?n===`json`?ve(r,t):{stdout:``,stderr:`xan from: unsupported format '${n}'
|
|
30
30
|
`,exitCode:1}:{stdout:``,stderr:`xan from: usage: xan from -f <format> [FILE]
|
|
31
|
-
`,exitCode:1}}async function
|
|
31
|
+
`,exitCode:1}}async function ve(e,t){let n=e[0],r;if(!n||n===`-`)r=t.stdin;else try{let e=t.fs.resolvePath(t.cwd,n);r=await t.fs.readFile(e)}catch{return{stdout:``,stderr:`xan from: ${n}: No such file or directory
|
|
32
32
|
`,exitCode:1}}try{let e=JSON.parse(r.trim());if(!Array.isArray(e))return{stdout:``,stderr:`xan from: JSON input must be an array
|
|
33
33
|
`,exitCode:1};if(e.length===0)return{stdout:`
|
|
34
34
|
`,stderr:``,exitCode:0};if(Array.isArray(e[0])){let[t,...n]=e;return{stdout:h(t,n.map(e=>{let n=v();for(let r=0;r<t.length;r++)_(n,t[r],e[r]);return n})),stderr:``,exitCode:0}}return{stdout:h(Object.keys(e[0]).sort(),e),stderr:``,exitCode:0}}catch{return{stdout:``,stderr:`xan from: invalid JSON input
|
|
35
|
-
`,exitCode:1}}}async function
|
|
36
|
-
`,exitCode:1};let{headers:s,data:c,error:l}=await g(o,t);if(l)return l;let u={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},f=
|
|
37
|
-
`,exitCode:1};let{headers:o,data:s,error:c}=await g(a,t);if(c)return c;let u=C(n).map(({expr:e,name:t})=>({alias:typeof t==`string`?t:t[0],ast:F(e)})),f={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},p;if(r){p=[...o];for(let e of u)o.includes(e.alias)||p.push(e.alias)}else p=[...o,...u.map(e=>e.alias)];let m=[];for(let e=0;e<s.length;e++){let t=s[e],n=y(t),r=!1,a=Object.assign(l(t),{_row_index:e});for(let e of u){let t=d(a,e.ast,f),o=t.length>0?t[0]:null;if(i&&o==null){r=!0;break}_(n,e.alias,o)}r||m.push(n)}return{stdout:h(p,m),stderr:``,exitCode:0}}async function
|
|
35
|
+
`,exitCode:1}}}async function ye(e,t){let n=!1,r=0,i=``,o=[];for(let t=0;t<e.length;t++){let s=e[t];if(s===`-v`||s===`--invert`)n=!0;else if((s===`-l`||s===`--limit`)&&t+1<e.length)r=Number.parseInt(e[++t],10);else{if(s===`--help`)return a({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`]});s.startsWith(`-`)||(i?o.push(s):i=s)}}if(!i)return{stdout:``,stderr:`xan filter: no expression specified
|
|
36
|
+
`,exitCode:1};let{headers:s,data:c,error:l}=await g(o,t);if(l)return l;let u={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},f=ae(i),p=[];for(let e of c){if(r>0&&p.length>=r)break;let t=d(e,f,u),i=t.length>0&&t.some(e=>!!e);(n?!i:i)&&p.push(e)}return{stdout:h(s,p),stderr:``,exitCode:0}}async function be(e,t){let n=``,r=!1,i=!1,a=[];for(let t=0;t<e.length;t++){let o=e[t];o===`-N`||o===`--numeric`?r=!0:o===`-R`||o===`-r`||o===`--reverse`?i=!0:o===`-s`&&t+1<e.length?n=e[++t]:o.startsWith(`-`)||a.push(o)}let{headers:o,data:s,error:c}=await g(a,t);return c||(!n&&o.length>0&&(n=o[0]),{stdout:h(o,[...s].sort((e,t)=>{let a=e[n],o=t[n],s;return s=r?(typeof a==`number`?a:Number.parseFloat(String(a)))-(typeof o==`number`?o:Number.parseFloat(String(o))):String(a).localeCompare(String(o)),i?-s:s})),stderr:``,exitCode:0})}async function xe(e,t){let n=``,r=[];for(let t=0;t<e.length;t++){let i=e[t];i===`-s`&&t+1<e.length?n=e[++t]:i.startsWith(`-`)||r.push(i)}let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=new Set;return{stdout:h(i,a.filter(e=>{let t=n?String(e[n]):JSON.stringify(e);return s.has(t)?!1:(s.add(t),!0)})),stderr:``,exitCode:0}}async function Se(e,t){let n=10,r=``,i=!1,a=[];for(let t=0;t<e.length;t++){let o=e[t];(o===`-l`||o===`-n`)&&t+1<e.length?n=Number.parseInt(e[++t],10):o===`-R`||o===`-r`||o===`--reverse`?i=!0:o.startsWith(`-`)||(r?a.push(o):r=o)}let{headers:o,data:s,error:c}=await g(a,t);return c||(!r&&o.length>0&&(r=o[0]),{stdout:h(o,[...s].sort((e,t)=>{let n=e[r],a=t[r],o=typeof n==`number`?n:Number.parseFloat(String(n)),s=typeof a==`number`?a:Number.parseFloat(String(a));return i?o-s:s-o}).slice(0,n)),stderr:``,exitCode:0})}D();async function Ce(e,t){let n=``,r=!1,i=!1,a=[];for(let t=0;t<e.length;t++){let o=e[t];o===`-O`||o===`--overwrite`?r=!0:o===`--filter`?i=!0:o.startsWith(`-`)||(n?a.push(o):n=o)}if(!n)return{stdout:``,stderr:`xan map: no expression specified
|
|
37
|
+
`,exitCode:1};let{headers:o,data:s,error:c}=await g(a,t);if(c)return c;let u=C(n).map(({expr:e,name:t})=>({alias:typeof t==`string`?t:t[0],ast:F(e)})),f={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},p;if(r){p=[...o];for(let e of u)o.includes(e.alias)||p.push(e.alias)}else p=[...o,...u.map(e=>e.alias)];let m=[];for(let e=0;e<s.length;e++){let t=s[e],n=y(t),r=!1,a=Object.assign(l(t),{_row_index:e});for(let e of u){let t=d(a,e.ast,f),o=t.length>0?t[0]:null;if(i&&o==null){r=!0;break}_(n,e.alias,o)}r||m.push(n)}return{stdout:h(p,m),stderr:``,exitCode:0}}async function we(e,t){let n=``,r=``,a=``,o=[];for(let t=0;t<e.length;t++){let i=e[t];(i===`-r`||i===`--rename`)&&t+1<e.length?a=e[++t]:i.startsWith(`-`)||(n?r?o.push(i):r=i:n=i)}if(!n||!r)return{stdout:``,stderr:`xan transform: usage: xan transform COLUMN EXPR [FILE]
|
|
38
38
|
`,exitCode:1};let{headers:s,data:c,error:u}=await g(o,t);if(u)return u;let f=n.split(`,`).map(e=>e.trim()),p=a?a.split(`,`).map(e=>e.trim()):[];for(let e of f)if(!s.includes(e))return{stdout:``,stderr:`xan transform: column '${e}' not found
|
|
39
|
-
`,exitCode:1};let m=F(C(r)[0]?.expr||(D(),i(S)).parseMoonblade(r)),v={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},b=s.map(e=>{let t=f.indexOf(e);return t!==-1&&p[t]?p[t]:e}),x=[];for(let e of c){let t=y(e);for(let n=0;n<f.length;n++){let r=f[n],i=d(Object.assign(l(e),{_:e[r]}),m,v),a=i.length>0?i[0]:null,o=p[n]||r;o!==r&&delete t[r],_(t,o,a)}x.push(t)}return{stdout:h(b,x),stderr:``,exitCode:0}}async function
|
|
39
|
+
`,exitCode:1};let m=F(C(r)[0]?.expr||(D(),i(S)).parseMoonblade(r)),v={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},b=s.map(e=>{let t=f.indexOf(e);return t!==-1&&p[t]?p[t]:e}),x=[];for(let e of c){let t=y(e);for(let n=0;n<f.length;n++){let r=f[n],i=d(Object.assign(l(e),{_:e[r]}),m,v),a=i.length>0?i[0]:null,o=p[n]||r;o!==r&&delete t[r],_(t,o,a)}x.push(t)}return{stdout:h(b,x),stderr:``,exitCode:0}}async function Te(e,t){let n=``,r=`|`,i=!1,a=``,o=[];for(let t=0;t<e.length;t++){let s=e[t];(s===`-s`||s===`--separator`)&&t+1<e.length?r=e[++t]:s===`--drop-empty`?i=!0:(s===`-r`||s===`--rename`)&&t+1<e.length?a=e[++t]:s.startsWith(`-`)||(n?o.push(s):n=s)}if(!n)return{stdout:``,stderr:`xan explode: usage: xan explode COLUMN [FILE]
|
|
40
40
|
`,exitCode:1};let{headers:s,data:c,error:l}=await g(o,t);if(l)return l;if(!s.includes(n))return{stdout:``,stderr:`xan explode: column '${n}' not found
|
|
41
|
-
`,exitCode:1};let u=a?s.map(e=>e===n?a:e):s,d=a||n,f=[];for(let e of c){let t=e[n],o=t==null?``:String(t);if(o===``){if(!i){let t=y(e);a&&(delete t[n],_(t,d,``)),f.push(t)}}else{let t=o.split(r);for(let r of t){let t=y(e);a&&delete t[n],_(t,d,r),f.push(t)}}}return{stdout:h(u,f),stderr:``,exitCode:0}}async function
|
|
41
|
+
`,exitCode:1};let u=a?s.map(e=>e===n?a:e):s,d=a||n,f=[];for(let e of c){let t=e[n],o=t==null?``:String(t);if(o===``){if(!i){let t=y(e);a&&(delete t[n],_(t,d,``)),f.push(t)}}else{let t=o.split(r);for(let r of t){let t=y(e);a&&delete t[n],_(t,d,r),f.push(t)}}}return{stdout:h(u,f),stderr:``,exitCode:0}}async function Ee(e,t){let n=``,r=`|`,i=``,a=[];for(let t=0;t<e.length;t++){let o=e[t];(o===`-s`||o===`--sep`)&&t+1<e.length?r=e[++t]:(o===`-r`||o===`--rename`)&&t+1<e.length?i=e[++t]:o.startsWith(`-`)||(n?a.push(o):n=o)}if(!n)return{stdout:``,stderr:`xan implode: usage: xan implode COLUMN [FILE]
|
|
42
42
|
`,exitCode:1};let{headers:o,data:s,error:c}=await g(a,t);if(c)return c;if(!o.includes(n))return{stdout:``,stderr:`xan implode: column '${n}' not found
|
|
43
|
-
`,exitCode:1};let l=o.filter(e=>e!==n),u=i?o.map(e=>e===n?i:e):o,d=i||n,f=[],p=null,m=[],v=null;for(let e of s){let t=l.map(t=>String(e[t]??``)).join(`\0`),a=e[n],o=a==null?``:String(a);if(t!==p){if(v!==null){let e=y(v);i&&delete e[n],_(e,d,m.join(r)),f.push(e)}p=t,m=[o],v=e}else m.push(o)}if(v!==null){let e=y(v);i&&delete e[n],_(e,d,m.join(r)),f.push(e)}return{stdout:h(u,f),stderr:``,exitCode:0}}async function
|
|
43
|
+
`,exitCode:1};let l=o.filter(e=>e!==n),u=i?o.map(e=>e===n?i:e):o,d=i||n,f=[],p=null,m=[],v=null;for(let e of s){let t=l.map(t=>String(e[t]??``)).join(`\0`),a=e[n],o=a==null?``:String(a);if(t!==p){if(v!==null){let e=y(v);i&&delete e[n],_(e,d,m.join(r)),f.push(e)}p=t,m=[o],v=e}else m.push(o)}if(v!==null){let e=y(v);i&&delete e[n],_(e,d,m.join(r)),f.push(e)}return{stdout:h(u,f),stderr:``,exitCode:0}}async function De(e,t){let n=``,r=``,i=``,a=``,o=`inner`,s=``,c=0;for(let t=0;t<e.length;t++){let l=e[t];l===`--left`?o=`left`:l===`--right`?o=`right`:l===`--full`?o=`full`:(l===`-D`||l===`--default`)&&t+1<e.length?s=e[++t]:l.startsWith(`-`)||(c++,c===1?n=l:c===2?r=l:c===3?i=l:c===4&&(a=l))}if(!n||!r||!i||!a)return{stdout:``,stderr:`xan join: usage: xan join KEY1 FILE1 KEY2 FILE2 [OPTIONS]
|
|
44
44
|
`,exitCode:1};let l=await g([r],t);if(l.error)return l.error;let u=await g([a],t);if(u.error)return u.error;let{headers:d,data:f}=l,{headers:p,data:m}=u;if(!d.includes(n))return{stdout:``,stderr:`xan join: column '${n}' not found in first file
|
|
45
45
|
`,exitCode:1};if(!p.includes(i))return{stdout:``,stderr:`xan join: column '${i}' not found in second file
|
|
46
|
-
`,exitCode:1};let y=new Map;for(let e of m){let t=String(e[i]??``);y.has(t)||y.set(t,[]),y.get(t)?.push(e)}let b=new Set(d),x=p.filter(e=>!b.has(e)),S=[...d,...x],C=[],w=new Set;for(let e of f){let t=String(e[n]??``),r=y.get(t);if(r&&r.length>0){w.add(t);for(let t of r){let n=v();for(let t of d)_(n,t,e[t]);for(let e of x)_(n,e,t[e]);C.push(n)}}else if(o===`left`||o===`full`){let t=v();for(let n of d)_(t,n,e[n]);for(let e of x)_(t,e,s);C.push(t)}}if(o===`right`||o===`full`)for(let e of m){let t=String(e[i]??``);if(!w.has(t)){let t=v();for(let n of d)_(t,n,p.includes(n)?e[n]:s);for(let n of x)_(t,n,e[n]);C.push(t)}}return{stdout:h(S,C),stderr:``,exitCode:0}}async function
|
|
46
|
+
`,exitCode:1};let y=new Map;for(let e of m){let t=String(e[i]??``);y.has(t)||y.set(t,[]),y.get(t)?.push(e)}let b=new Set(d),x=p.filter(e=>!b.has(e)),S=[...d,...x],C=[],w=new Set;for(let e of f){let t=String(e[n]??``),r=y.get(t);if(r&&r.length>0){w.add(t);for(let t of r){let n=v();for(let t of d)_(n,t,e[t]);for(let e of x)_(n,e,t[e]);C.push(n)}}else if(o===`left`||o===`full`){let t=v();for(let n of d)_(t,n,e[n]);for(let e of x)_(t,e,s);C.push(t)}}if(o===`right`||o===`full`)for(let e of m){let t=String(e[i]??``);if(!w.has(t)){let t=v();for(let n of d)_(t,n,p.includes(n)?e[n]:s);for(let n of x)_(t,n,e[n]);C.push(t)}}return{stdout:h(S,C),stderr:``,exitCode:0}}async function Oe(e,t){let n=``,r=``,i=[],a=[];for(let t=0;t<e.length;t++){let o=e[t];(o===`-g`||o===`--groupby`)&&t+1<e.length?i=e[++t].split(`,`).map(e=>e.trim()):o.startsWith(`-`)||(n?r?a.push(o):r=o:n=o)}if(!n||!r)return{stdout:``,stderr:`xan pivot: usage: xan pivot COLUMN AGG_EXPR [OPTIONS] [FILE]
|
|
47
47
|
`,exitCode:1};let{headers:o,data:s,error:c}=await g(a,t);if(c)return c;if(!o.includes(n))return{stdout:``,stderr:`xan pivot: column '${n}' not found
|
|
48
48
|
`,exitCode:1};let l=r.match(/^(\w+)\((\w+)\)$/);if(!l)return{stdout:``,stderr:`xan pivot: invalid aggregation expression '${r}'
|
|
49
|
-
`,exitCode:1};let[,u,d]=l;i.length===0&&(i=o.filter(e=>e!==n&&e!==d));let f=[];for(let e of s){let t=String(e[n]??``);f.includes(t)||f.push(t)}let p=new Map,m=[];for(let e of s){let t=i.map(t=>String(e[t]??``)).join(`\0`),r=String(e[n]??``),a=e[d];p.has(t)||(p.set(t,new Map),m.push(t));let o=p.get(t);o&&(o.has(r)||o.set(r,[]),o.get(r)?.push(a))}let y=[...i,...f],b=[];for(let e of m){let t=e.split(`\0`),n=p.get(e);if(!n)continue;let r=v();for(let e=0;e<i.length;e++)_(r,i[e],t[e]);for(let e of f)_(r,e,
|
|
49
|
+
`,exitCode:1};let[,u,d]=l;i.length===0&&(i=o.filter(e=>e!==n&&e!==d));let f=[];for(let e of s){let t=String(e[n]??``);f.includes(t)||f.push(t)}let p=new Map,m=[];for(let e of s){let t=i.map(t=>String(e[t]??``)).join(`\0`),r=String(e[n]??``),a=e[d];p.has(t)||(p.set(t,new Map),m.push(t));let o=p.get(t);o&&(o.has(r)||o.set(r,[]),o.get(r)?.push(a))}let y=[...i,...f],b=[];for(let e of m){let t=e.split(`\0`),n=p.get(e);if(!n)continue;let r=v();for(let e=0;e<i.length;e++)_(r,i[e],t[e]);for(let e of f)_(r,e,ke(u,n.get(e)||[]));b.push(r)}return{stdout:h(y,b),stderr:``,exitCode:0}}function ke(e,t){let n=t.filter(e=>e!=null).map(e=>typeof e==`number`?e:Number.parseFloat(String(e))).filter(e=>!Number.isNaN(e));switch(e){case`count`:return t.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`mean`:case`avg`:return n.length>0?n.reduce((e,t)=>e+t,0)/n.length:null;case`min`:return n.length>0?Math.min(...n):null;case`max`:return n.length>0?Math.max(...n):null;case`first`:return t.length>0?String(t[0]??``):null;case`last`:return t.length>0?String(t[t.length-1]??``):null;default:return null}}async function Z(e,t){let n=``,r=[];for(let t=0;t<e.length;t++){let i=e[t];(i===`-s`||i===`--sort`)&&t+1<e.length?n=e[++t]:i.startsWith(`-`)||r.push(i)}if(r.length<2)return{stdout:``,stderr:`xan merge: usage: xan merge [OPTIONS] FILE1 FILE2 ...
|
|
50
50
|
`,exitCode:1};let i=[],a=null;for(let e of r){let n=await g([e],t);if(n.error)return n.error;if(a===null)a=n.headers;else if(JSON.stringify(a)!==JSON.stringify(n.headers))return{stdout:``,stderr:`xan merge: all files must have the same headers
|
|
51
51
|
`,exitCode:1};i.push({headers:n.headers,data:n.data})}if(!a)return{stdout:``,stderr:``,exitCode:0};let o=[];for(let{data:e}of i)o=o.concat(e);if(n){if(!a.includes(n))return{stdout:``,stderr:`xan merge: column '${n}' not found
|
|
52
|
-
`,exitCode:1};o.sort((e,t)=>{let r=e[n],i=t[n],a=typeof r==`number`?r:Number.parseFloat(String(r)),o=typeof i==`number`?i:Number.parseFloat(String(i));return!Number.isNaN(a)&&!Number.isNaN(o)?a-o:String(r??``).localeCompare(String(i??``))})}return{stdout:h(a,o),stderr:``,exitCode:0}}D();async function
|
|
52
|
+
`,exitCode:1};o.sort((e,t)=>{let r=e[n],i=t[n],a=typeof r==`number`?r:Number.parseFloat(String(r)),o=typeof i==`number`?i:Number.parseFloat(String(i));return!Number.isNaN(a)&&!Number.isNaN(o)?a-o:String(r??``).localeCompare(String(i??``))})}return{stdout:h(a,o),stderr:``,exitCode:0}}D();async function Ae(e,t){let{headers:n,data:r,error:i}=await g(e.filter(e=>!e.startsWith(`-`)),t);return i||(r.length===0?{stdout:``,stderr:``,exitCode:0}:{stdout:r.map(e=>n.map(t=>e[t])).map(e=>e.map(e=>je(e)).join(`,`)).join(`
|
|
53
53
|
`)+`
|
|
54
|
-
`,stderr:``,exitCode:0})}function
|
|
55
|
-
`)?`"${t.replace(/"/g,`""`)}"`:t}async function
|
|
56
|
-
`,exitCode:1};let{headers:a,data:o,error:s}=await g(i,t);if(s)return s;if(o.length<=n)return{stdout:h(a,o),stderr:``,exitCode:0};let c=r===null?Date.now():r,l=()=>(c=c*1103515245+12345&2147483647,c/2147483647),u=o.map((e,t)=>t);for(let e=u.length-1;e>0;e--){let t=Math.floor(l()*(e+1));[u[e],u[t]]=[u[t],u[e]]}return{stdout:h(a,u.slice(0,n).sort((e,t)=>e-t).map(e=>o[e])),stderr:``,exitCode:0}}async function
|
|
54
|
+
`,stderr:``,exitCode:0})}function je(e){if(e==null)return``;let t=String(e);return t.includes(`,`)||t.includes(`"`)||t.includes(`
|
|
55
|
+
`)?`"${t.replace(/"/g,`""`)}"`:t}async function Me(e,t){let n=null,r=null,i=[];for(let t=0;t<e.length;t++){let a=e[t];if(a===`--seed`&&t+1<e.length)r=Number.parseInt(e[++t],10);else if(!a.startsWith(`-`)){let e=Number.parseInt(a,10);n===null&&!Number.isNaN(e)&&e>0?n=e:i.push(a)}}if(n===null)return{stdout:``,stderr:`xan sample: usage: xan sample <sample-size> [FILE]
|
|
56
|
+
`,exitCode:1};let{headers:a,data:o,error:s}=await g(i,t);if(s)return s;if(o.length<=n)return{stdout:h(a,o),stderr:``,exitCode:0};let c=r===null?Date.now():r,l=()=>(c=c*1103515245+12345&2147483647,c/2147483647),u=o.map((e,t)=>t);for(let e=u.length-1;e>0;e--){let t=Math.floor(l()*(e+1));[u[e],u[t]]=[u[t],u[e]]}return{stdout:h(a,u.slice(0,n).sort((e,t)=>e-t).map(e=>o[e])),stderr:``,exitCode:0}}async function Ne(e,t){let n=!1,r=[];for(let t=0;t<e.length;t++){let i=e[t];i===`-p`||i===`--pad`?n=!0:i.startsWith(`-`)||r.push(i)}if(r.length===0)return{stdout:``,stderr:`xan cat: no files specified
|
|
57
57
|
`,exitCode:1};let i=await s(t,r,{cmdName:`xan cat`,stopOnError:!0});if(i.exitCode!==0)return{stdout:``,stderr:i.stderr,exitCode:i.exitCode};let a=[],o=[];for(let{content:e}of i.files){let{headers:t,data:n}=f(e);a.push({headers:t,data:n});for(let e of t)o.includes(e)||o.push(e)}if(!n){let e=JSON.stringify(a[0].headers);for(let t=1;t<a.length;t++)if(JSON.stringify(a[t].headers)!==e)return{stdout:``,stderr:`xan cat: headers do not match (use -p to pad)
|
|
58
|
-
`,exitCode:1};o=a[0].headers}let c=[];for(let{headers:e,data:t}of a)for(let n of t){let t=v();for(let r of o)_(t,r,e.includes(r)?n[r]:``);c.push(t)}return{stdout:h(o,c),stderr:``,exitCode:0}}async function
|
|
58
|
+
`,exitCode:1};o=a[0].headers}let c=[];for(let{headers:e,data:t}of a)for(let n of t){let t=v();for(let r of o)_(t,r,e.includes(r)?n[r]:``);c.push(t)}return{stdout:h(o,c),stderr:``,exitCode:0}}async function Pe(t,n){let r=``,i=[],a=!1,o=!1,s=[];for(let e=0;e<t.length;e++){let n=t[e];(n===`-s`||n===`--select`)&&e+1<t.length?i=t[++e].split(`,`):n===`-v`||n===`--invert`?a=!0:n===`-i`||n===`--ignore-case`?o=!0:n===`-r`||n===`--regex`||n.startsWith(`-`)||(r?s.push(n):r=n)}if(!r)return{stdout:``,stderr:`xan search: no pattern specified
|
|
59
59
|
`,exitCode:1};let{headers:c,data:l,error:u}=await g(s,n);if(u)return u;let d=i.length>0?i:c,f;try{f=e(r,o?`i`:``)}catch{return{stdout:``,stderr:`xan search: invalid regex pattern '${r}'
|
|
60
|
-
`,exitCode:1}}return{stdout:h(c,l.filter(e=>{let t=d.some(t=>{let n=e[t];return n!=null&&f.test(String(n))});return a?!t:t})),stderr:``,exitCode:0}}async function
|
|
61
|
-
`,exitCode:1};let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=C(n).map(({expr:e,name:t})=>({alias:typeof t==`string`?t:t[0],ast:F(e)})),c={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},l=[...i,...s.map(e=>e.alias)],u=[];for(let e of a){let t=[],n=1;for(let r of s){let i=d(e,r.ast,c),a=i.length>0&&Array.isArray(i[0])?i[0]:i;t.push(a),n=Math.max(n,a.length)}for(let r=0;r<n;r++){let n=y(e);for(let e=0;e<s.length;e++){let i=t[e][r]??null;_(n,s[e].alias,i)}u.push(n)}}return{stdout:h(l,u),stderr:``,exitCode:0}}async function
|
|
60
|
+
`,exitCode:1}}return{stdout:h(c,l.filter(e=>{let t=d.some(t=>{let n=e[t];return n!=null&&f.test(String(n))});return a?!t:t})),stderr:``,exitCode:0}}async function Fe(e,t){let n=``,r=[];for(let t of e)t.startsWith(`-`)||(n?r.push(t):n=t);if(!n)return{stdout:``,stderr:`xan flatmap: no expression specified
|
|
61
|
+
`,exitCode:1};let{headers:i,data:a,error:o}=await g(r,t);if(o)return o;let s=C(n).map(({expr:e,name:t})=>({alias:typeof t==`string`?t:t[0],ast:F(e)})),c={limits:t.limits?{maxIterations:t.limits.maxJqIterations}:void 0},l=[...i,...s.map(e=>e.alias)],u=[];for(let e of a){let t=[],n=1;for(let r of s){let i=d(e,r.ast,c),a=i.length>0&&Array.isArray(i[0])?i[0]:i;t.push(a),n=Math.max(n,a.length)}for(let r=0;r<n;r++){let n=y(e);for(let e=0;e<s.length;e++){let i=t[e][r]??null;_(n,s[e].alias,i)}u.push(n)}}return{stdout:h(l,u),stderr:``,exitCode:0}}async function Ie(e,t){let{cmdView:n}=await import(`./xan-view-OW2TB7Z3-DBl8NjSB.mjs`);return n(e,t)}var Q=new Set([`fuzzy-join`,`glob`,`hist`,`input`,`parallel`,`plot`,`progress`,`range`,`scrape`,`tokenize`,`union-find`]),Le=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`,...Q]),$={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.
|
|
62
62
|
It provides a simple, ergonomic interface for common data operations.
|
|
63
63
|
|
|
64
64
|
COMMANDS:
|
|
@@ -132,9 +132,9 @@ EXAMPLES:
|
|
|
132
132
|
xan groupby region 'count() as n' data.csv
|
|
133
133
|
xan explode tags data.csv
|
|
134
134
|
xan join id file1.csv id file2.csv
|
|
135
|
-
xan pivot year 'sum(sales)' data.csv`,options:[` --help display this help and exit`]},
|
|
136
|
-
`,exitCode:1};switch(n){case`headers`:return
|
|
135
|
+
xan pivot year 'sum(sales)' data.csv`,options:[` --help display this help and exit`]},Re={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`]}},ze={name:`xan`,async execute(e,t){if(e.length===0||o(e))return a($);let n=e[0],r=e.slice(1);if(o(r)){let e=Re[n];return a(e||$)}if(Q.has(n))return{stdout:``,stderr:`xan ${n}: not yet implemented
|
|
136
|
+
`,exitCode:1};switch(n){case`headers`:return K(r,t);case`count`:return q(r,t);case`head`:return J(r,t);case`tail`:return oe(r,t);case`slice`:return se(r,t);case`reverse`:return ce(r,t);case`behead`:return Ae(r,t);case`sample`:return Me(r,t);case`select`:return H(r,t);case`drop`:return U(r,t);case`rename`:return W(r,t);case`enum`:return G(r,t);case`filter`:return ye(r,t);case`search`:return Pe(r,t);case`sort`:return be(r,t);case`dedup`:return xe(r,t);case`top`:return Se(r,t);case`map`:return Ce(r,t);case`transform`:return we(r,t);case`explode`:return Te(r,t);case`implode`:return Ee(r,t);case`flatmap`:return Fe(r,t);case`pivot`:return Oe(r,t);case`agg`:return te(r,t);case`groupby`:return ne(r,t);case`frequency`:case`freq`:return re(r,t);case`stats`:return ie(r,t);case`cat`:return Ne(r,t);case`join`:return De(r,t);case`merge`:return Z(r,t);case`split`:return fe(r,t);case`partition`:return me(r,t);case`to`:return he(r,t);case`from`:return _e(r,t);case`transpose`:return le(r,t);case`shuffle`:return ue(r,t);case`fixlengths`:return de(r,t);case`view`:return p(r,t);case`flatten`:case`f`:return m(r,t);case`fmt`:return Ie(r,t);default:return Le.has(n)?{stdout:``,stderr:`xan ${n}: not yet implemented
|
|
137
137
|
`,exitCode:1}:{stdout:``,stderr:`xan: unknown command '${n}'
|
|
138
138
|
Run 'xan --help' for usage.
|
|
139
|
-
`,exitCode:1}}}},
|
|
140
|
-
//# sourceMappingURL=chunk-
|
|
139
|
+
`,exitCode:1}}}},Be={name:`xan`,flags:[],stdinType:`text`,needsArgs:!0};export{Be as n,ze as t};
|
|
140
|
+
//# sourceMappingURL=chunk-3BS5SKQH-HZ1-1bfb.mjs.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as r}from"./chunk-
|
|
2
|
-
`,exitCode:2};let P=S?`fixed`:b?`extended`:x?`perl`:`basic`,F,I;try{let e=
|
|
3
|
-
`,exitCode:2}}if(N.length===0&&c.stdin!==void 0){let e=
|
|
4
|
-
`,exitCode:2};let
|
|
5
|
-
`}:{file:t,result:
|
|
6
|
-
`}}}));for(let e of n){if(e===null)continue;if(`error`in e&&e.error){
|
|
7
|
-
`:g||(
|
|
8
|
-
`:m&&!h&&(
|
|
9
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{n as e,r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as r}from"./chunk-SNN4IESC-C-P75V1I.mjs";import{n as i,t as a}from"./chunk-2TRDZQLB-C2G-sahM.mjs";var o={name:`grep`,summary:`print lines that match patterns`,usage:`grep [OPTION]... PATTERN [FILE]...`,options:[`-E, --extended-regexp PATTERN is an extended regular expression`,`-P, --perl-regexp PATTERN is a Perl regular expression`,`-F, --fixed-strings PATTERN is a set of newline-separated strings`,`-i, --ignore-case ignore case distinctions`,`-v, --invert-match select non-matching lines`,`-w, --word-regexp match only whole words`,`-x, --line-regexp match only whole lines`,`-c, --count print only a count of matching lines`,`-l, --files-with-matches print only names of files with matches`,`-L, --files-without-match print names of files with no matches`,`-m NUM, --max-count=NUM stop after NUM matches`,`-n, --line-number print line number with output lines`,`-h, --no-filename suppress the file name prefix on output`,`-o, --only-matching show only nonempty parts of lines that match`,`-q, --quiet, --silent suppress all normal output`,`-r, -R, --recursive search directories recursively`,`-A NUM print NUM lines of trailing context`,`-B NUM print NUM lines of leading context`,`-C NUM print NUM lines of context`,`-e PATTERN use PATTERN for matching`,` --include=GLOB search only files matching GLOB`,` --exclude=GLOB skip files matching GLOB`,` --exclude-dir=DIR skip directories matching DIR`,` --help display this help and exit`]},s={name:`grep`,async execute(s,c){if(n(s))return t(o);let l=!1,f=!1,p=!1,m=!1,h=!1,g=!1,_=!1,v=!1,y=!1,b=!1,x=!1,S=!1,C=!1,w=!1,T=!1,E=0,D=0,O=0,k=[],A=[],j=[],M=null,N=[];for(let t=0;t<s.length;t++){let n=s[t];if(n.startsWith(`-`)&&n!==`-`){if(n===`-e`&&t+1<s.length){M=s[++t];continue}if(n.startsWith(`--include=`)){k.push(n.slice(10));continue}if(n.startsWith(`--exclude=`)){A.push(n.slice(10));continue}if(n.startsWith(`--exclude-dir=`)){j.push(n.slice(14));continue}if(n.startsWith(`--max-count=`)){E=parseInt(n.slice(12),10);continue}let r=n.match(/^-m(\d+)$/);if(r){E=parseInt(r[1],10);continue}if(n===`-m`&&t+1<s.length){E=parseInt(s[++t],10);continue}let i=n.match(/^-([ABC])(\d+)$/);if(i){let e=parseInt(i[2],10);i[1]===`A`?O=e:i[1]===`B`?D=e:i[1]===`C`&&(D=e,O=e);continue}if((n===`-A`||n===`-B`||n===`-C`)&&t+1<s.length){let e=parseInt(s[++t],10);n===`-A`?O=e:n===`-B`?D=e:(D=e,O=e);continue}let a=n.startsWith(`--`)?[n]:n.slice(1).split(``);for(let t of a)if(t===`i`||t===`--ignore-case`)l=!0;else if(t===`n`||t===`--line-number`)f=!0;else if(t===`v`||t===`--invert-match`)p=!0;else if(t===`c`||t===`--count`)m=!0;else if(t===`l`||t===`--files-with-matches`)h=!0;else if(t===`L`||t===`--files-without-match`)g=!0;else if(t===`r`||t===`R`||t===`--recursive`)_=!0;else if(t===`w`||t===`--word-regexp`)v=!0;else if(t===`x`||t===`--line-regexp`)y=!0;else if(t===`E`||t===`--extended-regexp`)b=!0;else if(t===`P`||t===`--perl-regexp`)x=!0;else if(t===`F`||t===`--fixed-strings`)S=!0;else if(t===`o`||t===`--only-matching`)C=!0;else if(t===`h`||t===`--no-filename`)w=!0;else if(t===`q`||t===`--quiet`||t===`--silent`)T=!0;else{if(t.startsWith(`--`))return e(`grep`,t);if(t.length===1)return e(`grep`,`-${t}`)}}else M===null?M=n:N.push(n)}if(M===null)return{stdout:``,stderr:`grep: missing pattern
|
|
2
|
+
`,exitCode:2};let P=S?`fixed`:b?`extended`:x?`perl`:`basic`,F,I,L;try{let e=a(M,{mode:P,ignoreCase:l,wholeWord:v,lineRegexp:y});F=e.regex,I=e.kResetGroup,L=e.preFilter}catch{return{stdout:``,stderr:`grep: invalid regular expression: ${M}
|
|
3
|
+
`,exitCode:2}}if(N.length===0&&c.stdin!==void 0){let e=i(c.stdin,F,{invertMatch:p,showLineNumbers:f,countOnly:m,filename:``,onlyMatching:C,beforeContext:D,afterContext:O,maxCount:E,kResetGroup:I,preFilter:L});return T?{stdout:``,stderr:``,exitCode:e.matched?0:1}:{stdout:e.output,stderr:``,exitCode:e.matched?0:1}}if(N.length===0)return{stdout:``,stderr:`grep: no input files
|
|
4
|
+
`,exitCode:2};let R=``,z=``,B=!1,V=!1,H=[];for(let e of N)if(e.includes(`*`)||e.includes(`?`)||e.includes(`[`)){let t=await u(e,c);if(_)for(let e of t){let t=await d(e.path,c,k,A,j,e.isFile);H.push(...t)}else H.push(...t)}else if(_){let t=await d(e,c,k,A,j);H.push(...t)}else H.push({path:e});let U=(H.length>1||_)&&!w;for(let e=0;e<H.length;e+=50){let t=H.slice(e,e+50),n=await Promise.all(t.map(async e=>{let t=e.path,n=t.split(`/`).pop()||t;if(A.length>0&&!_&&A.some(e=>r(n,e,{stripQuotes:!0}))||k.length>0&&!_&&!k.some(e=>r(n,e,{stripQuotes:!0})))return null;try{let n=c.fs.resolvePath(c.cwd,t),r=!1;return r=e.isFile===void 0?(await c.fs.stat(n)).isDirectory:!e.isFile,r?_?null:{error:`grep: ${t}: Is a directory
|
|
5
|
+
`}:{file:t,result:i(await c.fs.readFile(n),F,{invertMatch:p,showLineNumbers:f,countOnly:m,filename:U?t:``,onlyMatching:C,beforeContext:D,afterContext:O,maxCount:E,kResetGroup:I,preFilter:L})}}catch{return{error:`grep: ${t}: No such file or directory
|
|
6
|
+
`}}}));for(let e of n){if(e===null)continue;if(`error`in e&&e.error){z+=e.error,e.error.includes(`Is a directory`)||(V=!0);continue}if(!(`file`in e)||!e.result)continue;let{file:t,result:n}=e;if(n.matched){if(B=!0,T)return{stdout:``,stderr:``,exitCode:0};h?R+=`${t}
|
|
7
|
+
`:g||(R+=n.output)}else g?R+=`${t}
|
|
8
|
+
`:m&&!h&&(R+=n.output)}}let W;return W=V?2:g?R.length>0?0:1:B?0:1,T?{stdout:``,stderr:``,exitCode:W}:{stdout:R,stderr:z,exitCode:W}}},c=256;async function l(e,t,n,i,a=0){if(a>=c)return;let o=n.fs.resolvePath(n.cwd,e);try{if(!(await n.fs.stat(o)).isDirectory){let n=e.split(`/`).pop()||``;t&&r(n,t.replace(/^\//,``),{stripQuotes:!0})&&i.push(e);return}let s=await n.fs.readdir(o);for(let o of s){let s=e===`.`?o:`${e}/${o}`,c=n.fs.resolvePath(n.cwd,s);(await n.fs.stat(c)).isDirectory?await l(s,t,n,i,a+1):t&&r(o,t.replace(/^\//,``),{stripQuotes:!0})&&i.push(s)}}catch{}}async function u(e,t){let n=[],i=e.lastIndexOf(`/`),a,o;if(i===-1?(a=t.cwd,o=e):(a=e.slice(0,i)||`/`,o=e.slice(i+1)),e.includes(`**`)){let n=[],r=e.split(`**`);return await l(r[0].replace(/\/$/,``)||`.`,r[1]||``,t,n),n.map(e=>({path:e}))}let s=t.fs.resolvePath(t.cwd,a);try{if(t.fs.readdirWithFileTypes){let e=await t.fs.readdirWithFileTypes(s);for(let t of e)if(r(t.name,o,{stripQuotes:!0})){let e=i===-1?t.name:`${a}/${t.name}`;n.push({path:e,isFile:t.isFile})}}else{let e=await t.fs.readdir(s);for(let t of e)if(r(t,o,{stripQuotes:!0})){let e=i===-1?t:`${a}/${t}`;n.push({path:e})}}}catch{}return n.sort((e,t)=>e.path.localeCompare(t.path))}async function d(e,t,n=[],i=[],a=[],o,s=0){if(s>=c)return[];let l=t.fs.resolvePath(t.cwd,e),u=[];try{let c,f;if(o!==void 0)c=o,f=!o;else{let e=await t.fs.stat(l);c=e.isFile,f=e.isDirectory}if(c){let t=e.split(`/`).pop()||e;return i.length>0&&i.some(e=>r(t,e,{stripQuotes:!0}))||n.length>0&&!n.some(e=>r(t,e,{stripQuotes:!0}))?[]:[{path:e,isFile:!0}]}if(!f)return[];let p=e.split(`/`).pop()||e;if(a.length>0&&a.some(e=>r(p,e,{stripQuotes:!0})))return[];if(t.fs.readdirWithFileTypes){let r=await t.fs.readdirWithFileTypes(l);for(let o of r){if(o.name.startsWith(`.`))continue;let r=await d(e===`.`?o.name:`${e}/${o.name}`,t,n,i,a,o.isFile,s+1);u.push(...r)}}else{let r=await t.fs.readdir(l);for(let o of r){if(o.startsWith(`.`))continue;let r=await d(e===`.`?o:`${e}/${o}`,t,n,i,a,void 0,s+1);u.push(...r)}}}catch{}return u}var f={name:`fgrep`,async execute(e,t){return s.execute([`-F`,...e],t)}},p={name:`egrep`,async execute(e,t){return s.execute([`-E`,...e],t)}},m={name:`grep`,flags:[{flag:`-E`,type:`boolean`},{flag:`-F`,type:`boolean`},{flag:`-P`,type:`boolean`},{flag:`-i`,type:`boolean`},{flag:`-v`,type:`boolean`},{flag:`-w`,type:`boolean`},{flag:`-x`,type:`boolean`},{flag:`-c`,type:`boolean`},{flag:`-l`,type:`boolean`},{flag:`-L`,type:`boolean`},{flag:`-n`,type:`boolean`},{flag:`-h`,type:`boolean`},{flag:`-o`,type:`boolean`},{flag:`-q`,type:`boolean`},{flag:`-r`,type:`boolean`},{flag:`-m`,type:`value`,valueHint:`number`},{flag:`-A`,type:`value`,valueHint:`number`},{flag:`-B`,type:`value`,valueHint:`number`},{flag:`-C`,type:`value`,valueHint:`number`},{flag:`-e`,type:`value`,valueHint:`pattern`}],stdinType:`text`,needsArgs:!0},h={name:`fgrep`,flags:[],stdinType:`text`,needsArgs:!0},g={name:`egrep`,flags:[],stdinType:`text`,needsArgs:!0};export{h as a,g as i,m as n,p as o,f as r,s as t};
|
|
9
|
+
//# sourceMappingURL=chunk-3H6UQG3A-DdNaIxPm.mjs.map
|