@poe-platform/safe-bash 0.1.803 → 0.1.804
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -31
- package/dist/image-ast/ast.d.ts +1 -0
- package/dist/image-ast/browser/ast.d.ts +1 -0
- package/dist/image-ast/browser/codecs/jpeg.d.ts +2 -2
- package/dist/image-ast/codecs/jpeg.d.ts +2 -2
- package/dist/image-ast/index.browser.js +692 -8364
- package/dist/image-ast/index.js +692 -8364
- package/dist/mp4-ast/codecs.d.ts +7 -2
- package/dist/safe-bash/chunks/{chunk-CHYGPFVM.js → chunk-22SX3F2R.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-FBUCWVTE.js → chunk-2IVBJTBD.js} +1 -1
- package/dist/safe-bash/chunks/chunk-2POETUMB.js +190 -0
- package/dist/safe-bash/chunks/{chunk-XVOSKJE2.js → chunk-47D7WBJK.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-VKNVHEX3.js → chunk-4ESI236Y.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-74GHTNJA.js → chunk-4KTMKD5W.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-55YJASTN.js → chunk-4T53AERN.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-DQP3VHSB.js → chunk-5XIFJVOO.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-5OHX7C2V.js → chunk-62BOHHJT.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-HZAMGT5I.js → chunk-67WIFM3N.js} +17 -6
- package/dist/safe-bash/chunks/{chunk-4D4N7IU2.js → chunk-6LNFRPW5.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-6O77NL2S.js → chunk-6SMICPI3.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-4BSJLKNM.js → chunk-7O76UFQD.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-PNBBUWSM.js → chunk-AW5KIT6V.js} +3488 -39
- package/dist/safe-bash/chunks/{chunk-JMMEIDPF.js → chunk-B2Z73HTZ.js} +52 -28
- package/dist/safe-bash/chunks/chunk-B3ZMOJVM.js +319 -0
- package/dist/safe-bash/chunks/{chunk-7ZBU7KYV.js → chunk-CFAWS3O4.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-I5HZ4FGE.js → chunk-CL2FCTTO.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-2LSAMQER.js → chunk-CTXNARJH.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-TFIBK2GI.js → chunk-D5Q7NFWI.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-OQRVVGR6.js → chunk-DSOOVZ6Q.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-VTH3MLDU.js → chunk-DUTAG6ZD.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-XAQMU6OY.js → chunk-EE5YGFIZ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-FZE4HW6G.js → chunk-EJOYT2ME.js} +1 -1
- package/dist/safe-bash/chunks/chunk-FAAIR6EJ.js +887 -0
- package/dist/safe-bash/chunks/{chunk-OV6IHKO6.js → chunk-FOB2FZR4.js} +2 -2
- package/dist/safe-bash/chunks/chunk-G6V4RRSQ.js +14 -0
- package/dist/safe-bash/chunks/{chunk-UTBUUFDM.js → chunk-GGQAGQXQ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-K6VCD7IY.js → chunk-HIIYIJ5G.js} +2 -4
- package/dist/safe-bash/chunks/{chunk-VBTDHOWC.js → chunk-IOHH2GTI.js} +4 -3
- package/dist/safe-bash/chunks/{chunk-CTVWDACF.js → chunk-IQW34XQT.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-HZ7BWKQ3.js → chunk-IS572AAT.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-AUSNDQTJ.js → chunk-JPSUHHOA.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-ZVD5IS4V.js → chunk-KBZ4UB2O.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-AM5ESLPH.js → chunk-KU5CVWKA.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-RYFQ3LZG.js → chunk-LPOVNKNB.js} +173 -153
- package/dist/safe-bash/chunks/{chunk-46Z5E5EV.js → chunk-MBOC3LZ4.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-6PAVEFT3.js → chunk-N4BQFD3P.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-CS4MNM6I.js → chunk-NGKCVNWS.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-7R5BDCG7.js → chunk-OHML2BEU.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-C5OWC2TL.js → chunk-OQ3AGYCZ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-B7TAL7S5.js → chunk-PTAEWLSE.js} +0 -2
- package/dist/safe-bash/chunks/{chunk-LVOBFF4D.js → chunk-Q4FNLOTI.js} +1 -1
- package/dist/safe-bash/chunks/chunk-Q5XO3NAS.js +1036 -0
- package/dist/safe-bash/chunks/{chunk-GEG3BWGE.js → chunk-RHFRJIWQ.js} +1 -1
- package/dist/safe-bash/chunks/chunk-RUR6J33T.js +11 -0
- package/dist/safe-bash/chunks/{chunk-EEEWOYEG.js → chunk-S4RFUUXO.js} +839 -24
- package/dist/safe-bash/chunks/{chunk-RRR7AQ24.js → chunk-SD2ISU5L.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-3NDIFSNM.js → chunk-SUJ3NTMH.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-R3NAKOED.js → chunk-SZRUU5HS.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-PH63PLPZ.js → chunk-TC3F4UFF.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-3R3AANOR.js → chunk-TCKYOLUE.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-D3ANYGMC.js → chunk-UV4X32QU.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-E7OYNDGL.js → chunk-V7QT2RWC.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-B7PIL77G.js → chunk-W2IYOVHK.js} +804 -1195
- package/dist/safe-bash/chunks/{chunk-3HQU4OJO.js → chunk-XNGVOSGI.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-J42RIHHJ.js → chunk-XQWCQSRN.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-A7XEHALN.js → chunk-Y7FW6GLT.js} +6 -6
- package/dist/safe-bash/chunks/{chunk-QGUV42T5.js → chunk-YL3GBUG4.js} +1 -1
- package/dist/safe-bash/chunks/chunk-YOXUCJER.js +389 -0
- package/dist/safe-bash/chunks/{chunk-HBCN24ZA.js → chunk-Z2AAYYJN.js} +2 -2
- package/dist/safe-bash/chunks/chunk-ZKYKJCZZ.js +30 -0
- package/dist/safe-bash/chunks/core-IE3AFIDX.js +85806 -0
- package/dist/safe-bash/chunks/{ffmpeg-WTC3TEFI.js → ffmpeg-YANDK6HU.js} +2 -2
- package/dist/safe-bash/chunks/{gh-6WU6PXL4.js → gh-4MBJ2S5V.js} +2 -2
- package/dist/safe-bash/chunks/{git-EFZIGJW4.js → git-2QONJNRQ.js} +2 -2
- package/dist/safe-bash/chunks/{imagemagick-EIEYGWPF.js → imagemagick-JLEHGYSN.js} +2 -2
- package/dist/safe-bash/chunks/{mmdc-ROQJT5HQ.js → mmdc-6LD7A6ND.js} +2 -2
- package/dist/safe-bash/chunks/{pdfimages-DW7LWXFI.js → pdfimages-RSHL7LOP.js} +2 -2
- package/dist/safe-bash/chunks/{pdfinfo-TIP6XLUQ.js → pdfinfo-L3SGWPNG.js} +2 -2
- package/dist/safe-bash/chunks/{pdftk-DMG22ITZ.js → pdftk-LFBJNU5A.js} +2 -2
- package/dist/safe-bash/chunks/{pdftoppm-WNDYR72T.js → pdftoppm-NXXFUIHG.js} +2 -2
- package/dist/safe-bash/chunks/{pdftotext-5IPZ4NI7.js → pdftotext-4IHNWT6F.js} +2 -2
- package/dist/safe-bash/chunks/{qpdf-TTX2DIUA.js → qpdf-ZEIREV63.js} +2 -2
- package/dist/safe-bash/chunks/read-builtin-A4QKAT45.js +9 -0
- package/dist/safe-bash/chunks/{sips-XYS46JPJ.js → sips-D5YBG2V3.js} +2 -2
- package/dist/safe-bash/chunks/{soffice-TU73E5KL.js → soffice-RAJU3JUT.js} +2 -2
- package/dist/safe-bash/chunks/source-files-3XWRRHFA.js +7 -0
- package/dist/safe-bash/chunks/{wkhtmltopdf-FSZ2CHGE.js → wkhtmltopdf-7UE4FORZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-7KWZXKY6.js → chunk-26RTBV2I.js} +1 -0
- package/dist/safe-bash/command-chunks/{chunk-AQJ2ROJO.js → chunk-2WYNMZR2.js} +10 -8
- package/dist/safe-bash/command-chunks/{chunk-BDSMROQZ.js → chunk-36GFRF2N.js} +2 -1
- package/dist/safe-bash/command-chunks/{chunk-GC5TJZOF.js → chunk-3VIA2IA7.js} +114 -31
- package/dist/safe-bash/command-chunks/{chunk-NKFYQSES.js → chunk-4CTI3ZTX.js} +1 -0
- package/dist/safe-bash/command-chunks/{chunk-WH627NJL.js → chunk-4MYP2FX4.js} +2 -1
- package/dist/safe-bash/command-chunks/{chunk-ZDN7MJE6.js → chunk-4R5ADJM5.js} +11 -1
- package/dist/safe-bash/command-chunks/{chunk-P2N33UMN.js → chunk-5MIKM54M.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-DB453IE6.js → chunk-6FZQUOSJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-PICVQ6B5.js → chunk-6GKYHPJG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7K6JYKPJ.js → chunk-6M2ELGEN.js} +17 -15
- package/dist/safe-bash/command-chunks/{chunk-PXEIT2O4.js → chunk-6UR7V3ET.js} +8 -1
- package/dist/safe-bash/command-chunks/{chunk-6KJ3LPI2.js → chunk-6XBS5B46.js} +26 -3
- package/dist/safe-bash/command-chunks/{chunk-5PWJG2UK.js → chunk-6YXLZX7L.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-EK6YNAXT.js → chunk-753YOR54.js} +31 -5
- package/dist/safe-bash/command-chunks/{chunk-RMWQAAO5.js → chunk-7IR4NRNE.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-FZTK4MFI.js → chunk-7NM73SVK.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-NXEQ3ESQ.js → chunk-7QD5YY4F.js} +6 -11
- package/dist/safe-bash/command-chunks/{chunk-EMPU65ZK.js → chunk-A5LBSJGH.js} +1 -0
- package/dist/safe-bash/command-chunks/{chunk-4FEVBOL5.js → chunk-ARZMP2L2.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-NKIELG7Y.js → chunk-BAKFZ477.js} +40 -19
- package/dist/safe-bash/command-chunks/{chunk-QRRYN2KO.js → chunk-BC7BK6R6.js} +0 -2424
- package/dist/safe-bash/command-chunks/{chunk-CQHP3I66.js → chunk-BOEOJS2Q.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XS72HTMA.js → chunk-BWGGLYEB.js} +5 -22
- package/dist/safe-bash/command-chunks/{chunk-PMBFZXTK.js → chunk-C5ZZKP7V.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-LHIOAFWW.js → chunk-C7SEB6WU.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XPT2UGBF.js → chunk-CHJKFRT7.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-TIOCQVUQ.js → chunk-CON26Q2O.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-E55UKBIE.js → chunk-DBAT3IK2.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Z45N42QC.js → chunk-DPAYAVMS.js} +15 -1
- package/dist/safe-bash/command-chunks/chunk-DS3NXVUM.js +368 -0
- package/dist/safe-bash/command-chunks/{chunk-5ZMZ573Q.js → chunk-DSJ3VRL3.js} +16 -4
- package/dist/safe-bash/command-chunks/{chunk-K2GDEMEU.js → chunk-EFRCFWVR.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-DZCY63VJ.js → chunk-EV6HIJ5H.js} +6 -5
- package/dist/safe-bash/command-chunks/{chunk-JDYXY44P.js → chunk-FJURV46Y.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-TZZ4WUKH.js → chunk-FZAWGKSE.js} +6 -4
- package/dist/safe-bash/command-chunks/{chunk-YHFXOX6U.js → chunk-GOCFQ6XV.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-QVOS4YXL.js → chunk-HH5O7DJI.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3HHCU5YU.js → chunk-HK7F5SDC.js} +13 -0
- package/dist/safe-bash/command-chunks/{chunk-JNZ3CVAE.js → chunk-HQBXIZC7.js} +8 -3
- package/dist/safe-bash/command-chunks/{chunk-V4K2JDYU.js → chunk-I63DBZXZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-WNE7FPVR.js → chunk-I64TLTIW.js} +24 -16
- package/dist/safe-bash/command-chunks/{chunk-GFC2NTDG.js → chunk-ICANWOXH.js} +5 -29
- package/dist/safe-bash/command-chunks/{chunk-SQRQW3CT.js → chunk-IJ6LGLXM.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-TGSNCQSR.js → chunk-JT4RYCA6.js} +1771 -1663
- package/dist/safe-bash/command-chunks/{chunk-II77KPZN.js → chunk-JWW6FYBN.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ZYXH3B66.js → chunk-LCJWKTCJ.js} +250 -203
- package/dist/safe-bash/command-chunks/chunk-LU4HBPP2.js +97 -0
- package/dist/safe-bash/command-chunks/{chunk-XJXU3VVH.js → chunk-LWOE65OE.js} +20 -5
- package/dist/safe-bash/command-chunks/{chunk-GMIHJYDG.js → chunk-M32HFSX7.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-YG4EPFWC.js → chunk-M3NINRDU.js} +2880 -172
- package/dist/safe-bash/command-chunks/chunk-MQREDAL6.js +164 -0
- package/dist/safe-bash/command-chunks/{chunk-LWS62ISU.js → chunk-N6DIASO2.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-NGL7YK7O.js +188 -0
- package/dist/safe-bash/command-chunks/{chunk-EARHPPPJ.js → chunk-NJYHWKIL.js} +39 -9
- package/dist/safe-bash/command-chunks/{chunk-6JSIFWYT.js → chunk-OJQRSCBP.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-OQU6UT6X.js → chunk-OV3XREFN.js} +11 -0
- package/dist/safe-bash/command-chunks/{chunk-MIXBO6U7.js → chunk-PTZLF456.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ALDC4XP4.js → chunk-QILLRNES.js} +34 -10
- package/dist/safe-bash/command-chunks/{chunk-L22T3H7L.js → chunk-QR25JLKO.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-NASVPT6F.js → chunk-R7C4MGZ5.js} +17 -224
- package/dist/safe-bash/command-chunks/{chunk-LCF3OB7P.js → chunk-RBME3JEH.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-2KG2QLJE.js → chunk-RFWGYT7G.js} +3 -0
- package/dist/safe-bash/command-chunks/{chunk-5TBUOBDE.js → chunk-RZMVRT26.js} +27 -13
- package/dist/safe-bash/command-chunks/chunk-TFR6B3WB.js +44 -0
- package/dist/safe-bash/command-chunks/chunk-TOH3OF3O.js +179 -0
- package/dist/safe-bash/command-chunks/chunk-TT4DAFBT.js +13621 -0
- package/dist/safe-bash/command-chunks/{chunk-LWSBAWLT.js → chunk-TXI64OAG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-GIRNFXP3.js → chunk-TZRI7BJZ.js} +45 -15
- package/dist/safe-bash/command-chunks/{chunk-QOKBZFFD.js → chunk-U3MMODA5.js} +2 -7
- package/dist/safe-bash/command-chunks/{chunk-ZYHTWNAE.js → chunk-UAW423ZL.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-C5YYCQHW.js → chunk-UXEEUGOV.js} +222 -12
- package/dist/safe-bash/command-chunks/{chunk-GY3BWK7K.js → chunk-VOZPMJRX.js} +87 -80
- package/dist/safe-bash/command-chunks/{chunk-ILX2NOLF.js → chunk-WPANOB4A.js} +20 -20
- package/dist/safe-bash/command-chunks/{chunk-Y2WBSJG6.js → chunk-X4QZQI5Q.js} +65 -64
- package/dist/safe-bash/command-chunks/{chunk-HDCNKOIX.js → chunk-XGI57GCN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-5UBXNSFZ.js → chunk-XUCU7QQT.js} +1281 -1278
- package/dist/safe-bash/command-chunks/chunk-Y22VXJBD.js +296 -0
- package/dist/safe-bash/command-chunks/{chunk-WVHONVZ4.js → chunk-YMFUUPDX.js} +5 -3
- package/dist/safe-bash/command-chunks/{chunk-IR2BY7EL.js → chunk-YYGIBXFZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-MSFXC3OC.js → chunk-Z4FO6OHE.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-WWIBP2ET.js → chunk-Z5ZZVDUD.js} +143 -22
- package/dist/safe-bash/command-chunks/{chunk-LOICUCHG.js → chunk-ZHN3QDCI.js} +1 -1
- package/dist/safe-bash/commands/alias/index.d.ts +2 -0
- package/dist/safe-bash/commands/alias/index.js +2 -0
- package/dist/safe-bash/commands/apply-patch/index.browser.js +2 -3
- package/dist/safe-bash/commands/apply-patch/index.d.ts +0 -1
- package/dist/safe-bash/commands/apply-patch/index.js +0 -1
- package/dist/safe-bash/commands/archive/index.browser.js +2 -3
- package/dist/safe-bash/commands/archive/index.d.ts +0 -1
- package/dist/safe-bash/commands/archive/index.js +0 -1
- package/dist/safe-bash/commands/bytes/index.js +2 -1
- package/dist/safe-bash/commands/chmod/index.browser.js +1 -1
- package/dist/safe-bash/commands/column/index.browser.js +2 -3
- package/dist/safe-bash/commands/column/index.d.ts +0 -1
- package/dist/safe-bash/commands/column/index.js +0 -1
- package/dist/safe-bash/commands/copy-source.js +1 -0
- package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
- package/dist/safe-bash/commands/csvkit/index.browser.js +72 -0
- package/dist/safe-bash/commands/csvkit/index.d.ts +0 -5
- package/dist/safe-bash/commands/csvkit/index.js +0 -50
- package/dist/safe-bash/commands/docx/index.browser.js +5 -7
- package/dist/safe-bash/commands/du/index.browser.js +2 -3
- package/dist/safe-bash/commands/du/index.d.ts +0 -1
- package/dist/safe-bash/commands/du/index.js +0 -1
- package/dist/safe-bash/commands/expr/index.browser.js +2 -3
- package/dist/safe-bash/commands/expr/index.d.ts +0 -1
- package/dist/safe-bash/commands/expr/index.js +0 -1
- package/dist/safe-bash/commands/factor/index.browser.js +2 -2
- package/dist/safe-bash/commands/file/index.browser.js +2 -3
- package/dist/safe-bash/commands/file/index.d.ts +0 -1
- package/dist/safe-bash/commands/file/index.js +0 -1
- package/dist/safe-bash/commands/filesystem.js +1 -1
- package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
- package/dist/safe-bash/commands/grep-aliases/index.browser.js +3 -3
- package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
- package/dist/safe-bash/commands/html-to-markdown/index.browser.js +2 -3
- package/dist/safe-bash/commands/html-to-markdown/index.d.ts +0 -1
- package/dist/safe-bash/commands/html-to-markdown/index.js +0 -1
- package/dist/safe-bash/commands/htmlq/index.d.ts +1 -5
- package/dist/safe-bash/commands/htmlq/index.js +1 -143
- package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
- package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
- package/dist/safe-bash/commands/llm/index.browser.js +2 -2
- package/dist/safe-bash/commands/llm/providers/index.browser.js +1 -1
- package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
- package/dist/safe-bash/commands/media/index.browser.js +4 -16314
- package/dist/safe-bash/commands/media/index.d.ts +1 -5
- package/dist/safe-bash/commands/media/index.js +1 -3
- package/dist/safe-bash/commands/media/plugin.d.ts +1 -18
- package/dist/safe-bash/commands/media/plugin.js +1 -90
- package/dist/safe-bash/commands/media/remote.d.ts +1 -63
- package/dist/safe-bash/commands/media/remote.js +1 -405
- package/dist/safe-bash/commands/media/settings.d.ts +1 -4
- package/dist/safe-bash/commands/media/settings.js +1 -26
- package/dist/safe-bash/commands/metadata/index.browser.js +3 -4
- package/dist/safe-bash/commands/metadata/index.d.ts +0 -1
- package/dist/safe-bash/commands/metadata/index.js +2 -2
- package/dist/safe-bash/commands/mktemp/index.browser.js +1 -1
- package/dist/safe-bash/commands/network/curl.js +1 -3
- package/dist/safe-bash/commands/network/index.browser.js +3 -4
- package/dist/safe-bash/commands/network/public.d.ts +0 -1
- package/dist/safe-bash/commands/network/public.js +0 -1
- package/dist/safe-bash/commands/network/transport.js +2 -1
- package/dist/safe-bash/commands/network/wget.js +1 -3
- package/dist/safe-bash/commands/node/browser.d.ts +0 -1
- package/dist/safe-bash/commands/node/browser.js +0 -1
- package/dist/safe-bash/commands/node/default-runtime.d.ts +3 -0
- package/dist/safe-bash/commands/node/default-runtime.js +15 -0
- package/dist/safe-bash/commands/node/index.browser.js +7 -8
- package/dist/safe-bash/commands/node/index.js +3 -3
- package/dist/safe-bash/commands/node/path.js +1 -1
- package/dist/safe-bash/commands/node/preload.d.ts +1 -1
- package/dist/safe-bash/commands/node/preload.js +4 -1
- package/dist/safe-bash/commands/node/quickjs.d.ts +2 -0
- package/dist/safe-bash/commands/node/quickjs.js +2 -0
- package/dist/safe-bash/commands/node/safejs.js +26 -12
- package/dist/safe-bash/commands/op/index.browser.js +2 -3
- package/dist/safe-bash/commands/op/index.d.ts +0 -11
- package/dist/safe-bash/commands/op/index.js +0 -84
- package/dist/safe-bash/commands/pandoc/index.browser.js +44 -0
- package/dist/safe-bash/commands/pandoc/index.d.ts +0 -1
- package/dist/safe-bash/commands/pandoc/index.js +0 -1
- package/dist/safe-bash/commands/pr/index.browser.js +2 -2
- package/dist/safe-bash/commands/python/docker-runner.js +4 -3
- package/dist/safe-bash/commands/python/docker.d.ts +1 -0
- package/dist/safe-bash/commands/python/docker.js +5 -2
- package/dist/safe-bash/commands/python/index.browser.js +17 -13
- package/dist/safe-bash/commands/python/index.d.ts +2 -1
- package/dist/safe-bash/commands/python/index.js +10 -8
- package/dist/safe-bash/commands/python/llm-capability.js +65 -2
- package/dist/safe-bash/commands/python/llm-dependencies.d.ts +27 -0
- package/dist/safe-bash/commands/python/llm-dependencies.js +66 -0
- package/dist/safe-bash/commands/python/llm-module.js +6 -4
- package/dist/safe-bash/commands/python/llm-reference-module.d.ts +3 -0
- package/dist/safe-bash/commands/python/llm-reference-module.js +690 -0
- package/dist/safe-bash/commands/python/worker.browser.js +2 -3
- package/dist/safe-bash/commands/python/worker.d.ts +0 -1
- package/dist/safe-bash/commands/python/worker.js +0 -1
- package/dist/safe-bash/commands/regex-execution/ere/transport/wire-engine.d.ts +1 -1
- package/dist/safe-bash/commands/regex-execution/ere/transport/wire-engine.js +3 -3
- package/dist/safe-bash/commands/regex-execution/public.browser.js +7 -7
- package/dist/safe-bash/commands/safejs/options.js +5 -1
- package/dist/safe-bash/commands/safejs/runtime.d.ts +1 -0
- package/dist/safe-bash/commands/safejs/runtime.js +1 -1
- package/dist/safe-bash/commands/split/index.browser.js +2 -3
- package/dist/safe-bash/commands/split/index.d.ts +0 -1
- package/dist/safe-bash/commands/split/index.js +0 -1
- package/dist/safe-bash/commands/ssconvert/index.browser.js +98 -0
- package/dist/safe-bash/commands/stat/index.browser.js +1 -1
- package/dist/safe-bash/commands/stream-format/index.browser.js +3 -4
- package/dist/safe-bash/commands/stream-format/index.d.ts +0 -1
- package/dist/safe-bash/commands/stream-format/index.js +0 -1
- package/dist/safe-bash/commands/stream-inspection/index.browser.js +3 -4
- package/dist/safe-bash/commands/stream-inspection/index.d.ts +0 -1
- package/dist/safe-bash/commands/stream-inspection/index.js +0 -1
- package/dist/safe-bash/commands/streams.js +2 -1
- package/dist/safe-bash/commands/table-text/index.browser.js +3 -4
- package/dist/safe-bash/commands/table-text/index.d.ts +0 -1
- package/dist/safe-bash/commands/table-text/index.js +0 -1
- package/dist/safe-bash/commands/text.js +28 -24
- package/dist/safe-bash/commands/time-env/index.browser.js +3 -4
- package/dist/safe-bash/commands/time-env/index.d.ts +0 -1
- package/dist/safe-bash/commands/time-env/index.js +0 -1
- package/dist/safe-bash/commands/tree/index.browser.js +2 -3
- package/dist/safe-bash/commands/tree/index.d.ts +0 -1
- package/dist/safe-bash/commands/tree/index.js +0 -1
- package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
- package/dist/safe-bash/commands/unalias/index.d.ts +2 -0
- package/dist/safe-bash/commands/unalias/index.js +2 -0
- package/dist/safe-bash/commands/xml/index.browser.js +2 -2
- package/dist/safe-bash/commands/yq/index.browser.js +2 -2
- package/dist/safe-bash/core.browser.js +2 -2
- package/dist/safe-bash/core.d.ts +7 -1
- package/dist/safe-bash/core.js +7 -1
- package/dist/safe-bash/execution-runtime.js +2 -1
- package/dist/safe-bash/fs/s3/http/index.d.ts +2 -2
- package/dist/safe-bash/fs/s3/http/index.js +1 -1
- package/dist/safe-bash/full-core.browser.js +283 -945
- package/dist/safe-bash/internal/op/types.d.ts +1 -0
- package/dist/safe-bash/jobs.browser.js +5 -5
- package/dist/safe-bash/lazy-optional.d.ts +3 -3
- package/dist/safe-bash/lazy-optional.js +1 -1
- package/dist/safe-bash/opt-in/commands/cmp/index.js +7 -6
- package/dist/safe-bash/opt-in/commands/dd/index.js +1 -1
- package/dist/safe-bash/opt-in/commands/dd/io.js +51 -5
- package/dist/safe-bash/opt-in/commands/truncate/index.js +2 -2
- package/dist/safe-bash/opt-in/commands/yq/native-work.js +2 -0
- package/dist/safe-bash/opt-in/optional/commands/shuf/input.js +2 -1
- package/dist/safe-bash/opt-in/optional/commands/shuf/shuf.js +4 -2
- package/dist/safe-bash/opt-in/optional.d.ts +1 -1
- package/dist/safe-bash/opt-in/optional.js +1 -1
- package/dist/safe-bash/opt-in/shell/extensions/read/index.js +2 -344
- package/dist/safe-bash/optional-host.browser.js +23 -18
- package/dist/safe-bash/optional-host.d.ts +1 -0
- package/dist/safe-bash/optional-host.js +1 -0
- package/dist/safe-bash/playwright/controller.js +41 -3
- package/dist/safe-bash/playwright/native-storage-targets.js +4 -2
- package/dist/safe-bash/plugins/base.d.ts +1 -1
- package/dist/safe-bash/plugins/base.js +3 -3
- package/dist/safe-bash/plugins/composition.d.ts +5 -2
- package/dist/safe-bash/plugins/composition.js +10 -7
- package/dist/safe-bash/plugins/index.browser.js +44 -41
- package/dist/safe-bash/plugins/index.js +3 -2
- package/dist/safe-bash/plugins/portable-commands.d.ts +3 -0
- package/dist/safe-bash/plugins/portable-commands.js +31 -0
- package/dist/safe-bash/registry-entry.browser.js +41 -42
- package/dist/safe-bash/search.browser.js +32 -33
- package/dist/safe-bash/shell/arithmetic.js +19 -6
- package/dist/safe-bash/shell/arrays/state.js +1 -1
- package/dist/safe-bash/shell/arrays/syntax.js +4 -3
- package/dist/safe-bash/shell/index.d.ts +0 -1
- package/dist/safe-bash/shell/index.js +0 -1
- package/dist/safe-bash/shell/parser.d.ts +2 -2
- package/dist/safe-bash/shell/parser.js +268 -64
- package/dist/safe-bash/shell/read-builtin.d.ts +3 -0
- package/dist/safe-bash/shell/read-builtin.js +344 -0
- package/dist/safe-bash/shell/runtime.d.ts +21 -4
- package/dist/safe-bash/shell/runtime.js +373 -412
- package/dist/safe-bash/shell/session-state.js +25 -0
- package/dist/safe-bash/shell/shell.js +76 -154
- package/dist/safe-bash/shell/tilde-expansion.d.ts +1 -1
- package/dist/safe-bash/shell/tilde-expansion.js +2 -2
- package/dist/safe-bash/shell/types.d.ts +5 -0
- package/dist/safe-bash/shell/value-state.js +1 -1
- package/dist/safe-bash/shell-entry.browser.js +32 -33
- package/dist/safe-bash/trap.browser.js +4 -4
- package/dist/safe-bash/yq-browser/index.js +1 -1
- package/dist/safe-bash-calendar-engine/time-env/calendar.d.ts +1 -1
- package/dist/safe-bash-calendar-engine/time-env/calendar.js +1 -1
- package/dist/safe-bash-calendar-engine/time-env/format.js +1 -1
- package/dist/safe-bash-command-alias/index.d.ts +13 -0
- package/dist/safe-bash-command-alias/index.js +88 -0
- package/dist/safe-bash-command-apply-patch/apply.js +3 -3
- package/dist/safe-bash-command-apply-patch/index.js +3 -3
- package/dist/safe-bash-command-apply-patch/matcher.js +1 -1
- package/dist/safe-bash-command-apply-patch/parser.js +1 -1
- package/dist/safe-bash-command-awk/awk-pipes.js +2 -2
- package/dist/safe-bash-command-awk/awk-reader.js +1 -1
- package/dist/safe-bash-command-awk/awk-runtime.js +3 -3
- package/dist/safe-bash-command-awk/awk.js +5 -5
- package/dist/safe-bash-command-awk/index.js +5 -5
- package/dist/safe-bash-command-bc/index.js +206 -60
- package/dist/safe-bash-command-cmp/index.js +7 -6
- package/dist/safe-bash-command-column/column.js +3 -3
- package/dist/safe-bash-command-column/index.js +3 -3
- package/dist/safe-bash-command-column/layout.js +2 -2
- package/dist/safe-bash-command-csvkit/index.d.ts +1 -0
- package/dist/safe-bash-command-csvkit/index.js +1505 -7
- package/dist/safe-bash-command-csvkit/sync-support.js +2 -7
- package/dist/safe-bash-command-curl/curl.js +1 -1
- package/dist/safe-bash-command-curl/index.js +1 -1
- package/dist/safe-bash-command-date/date.js +1 -1
- package/dist/safe-bash-command-date/index.js +1 -1
- package/dist/safe-bash-command-dd/index.js +1 -1
- package/dist/safe-bash-command-dd/io.js +51 -5
- package/dist/safe-bash-command-diff/diff.js +1 -1
- package/dist/safe-bash-command-diff/index.js +1 -1
- package/dist/safe-bash-command-diff3/index.js +10 -13
- package/dist/safe-bash-command-exiftool/index.js +278 -50
- package/dist/safe-bash-command-exiftool/registry.d.ts +4 -2
- package/dist/safe-bash-command-factor/command.js +2 -2
- package/dist/safe-bash-command-factor/index.js +2 -2
- package/dist/safe-bash-command-fd/arguments.d.ts +2 -0
- package/dist/safe-bash-command-fd/index.js +42 -12
- package/dist/safe-bash-command-ffmpeg/index.js +356 -66
- package/dist/safe-bash-command-find/find-format.d.ts +3 -0
- package/dist/safe-bash-command-find/find-format.js +1 -1
- package/dist/safe-bash-command-find/find.js +2 -2
- package/dist/safe-bash-command-find/index.js +2 -2
- package/dist/safe-bash-command-fmt/index.js +1 -4
- package/dist/safe-bash-command-fold/engine.d.ts +1 -1
- package/dist/safe-bash-command-fold/family.js +2 -2
- package/dist/safe-bash-command-fold/index.js +1 -1
- package/dist/safe-bash-command-hexdump/command.js +2 -2
- package/dist/safe-bash-command-hexdump/index.js +2 -2
- package/dist/safe-bash-command-html-to-markdown/entities.js +1 -1
- package/dist/safe-bash-command-html-to-markdown/index.js +4 -4
- package/dist/safe-bash-command-html-to-markdown/input.js +3 -3
- package/dist/safe-bash-command-html-to-markdown/parser.js +2 -2
- package/dist/safe-bash-command-html-to-markdown/render.js +3 -3
- package/dist/safe-bash-command-htmlq/contracts.d.ts +5 -2
- package/dist/safe-bash-command-htmlq/index.d.ts +2 -1
- package/dist/safe-bash-command-htmlq/index.js +175 -49
- package/dist/safe-bash-command-htmlq/sync.d.ts +1 -0
- package/dist/safe-bash-command-imagemagick/index.js +56 -6
- package/dist/safe-bash-command-install/arguments.d.ts +27 -0
- package/dist/safe-bash-command-install/arguments.js +224 -0
- package/dist/safe-bash-command-install/index.d.ts +7 -0
- package/dist/safe-bash-command-install/index.js +942 -0
- package/dist/safe-bash-command-install/mode.d.ts +6 -0
- package/dist/safe-bash-command-install/mode.js +71 -0
- package/dist/safe-bash-command-install/options.d.ts +40 -0
- package/dist/safe-bash-command-install/options.js +27 -0
- package/dist/safe-bash-command-jq/index.js +1 -1
- package/dist/safe-bash-command-jq/jq.js +1 -1
- package/dist/safe-bash-command-less/index.js +37 -61
- package/dist/safe-bash-command-llm/command.js +1 -1
- package/dist/safe-bash-command-llm/elevenlabs.js +2 -2
- package/dist/safe-bash-command-llm/index.js +4 -4
- package/dist/safe-bash-command-llm/openai.js +2 -2
- package/dist/safe-bash-command-llm/providers/elevenlabs.js +2 -2
- package/dist/safe-bash-command-llm/providers/index.js +3 -3
- package/dist/safe-bash-command-llm/providers/openai.js +2 -2
- package/dist/safe-bash-command-llm/providers/shared.js +1 -1
- package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.browser.d.ts +463 -46
- package/dist/safe-bash-command-mcp/index.browser.js +19308 -0
- package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.d.ts +15 -6
- package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.js +2804 -2771
- package/dist/safe-bash-command-media/LICENSE +21 -0
- package/dist/safe-bash-command-media/index.d.ts +6 -0
- package/dist/safe-bash-command-media/index.js +30 -0
- package/dist/safe-bash-command-media/plugin.d.ts +18 -0
- package/dist/safe-bash-command-media/plugin.js +11 -0
- package/dist/safe-bash-command-media/remote.d.ts +63 -0
- package/dist/safe-bash-command-media/remote.js +11 -0
- package/dist/safe-bash-command-media/settings.d.ts +4 -0
- package/dist/safe-bash-command-media/settings.js +41 -0
- package/dist/safe-bash-command-mktemp/command.js +1 -1
- package/dist/safe-bash-command-mktemp/index.js +1 -1
- package/dist/safe-bash-command-mmdc/arguments.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/command.d.ts +2 -0
- package/dist/safe-bash-command-mmdc/contracts.d.ts +8 -1
- package/dist/safe-bash-command-mmdc/index.js +359 -7
- package/dist/safe-bash-command-nl/index.js +1 -1
- package/dist/safe-bash-command-nl/nl.js +1 -1
- package/dist/safe-bash-command-node/LICENSE +21 -0
- package/dist/safe-bash-command-node/index.d.ts +17 -0
- package/dist/safe-bash-command-node/index.js +328 -0
- package/dist/safe-bash-command-numfmt/index.js +1 -0
- package/dist/safe-bash-command-od/index.js +10 -6
- package/dist/safe-bash-command-op/index.js +39 -32
- package/dist/safe-bash-command-op/types.d.ts +1 -0
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.d.ts +1 -0
- package/dist/safe-bash-command-pandoc/index.js +5 -3
- package/dist/safe-bash-command-pandoc/sync.d.ts +1 -0
- package/dist/safe-bash-command-patch/index.js +4 -4
- package/dist/safe-bash-command-patch/patch.js +4 -4
- package/dist/safe-bash-command-pdfimages/index.js +1 -1
- package/dist/safe-bash-command-pdfinfo/index.js +30 -5
- package/dist/safe-bash-command-pdftk/index.js +21 -23
- package/dist/safe-bash-command-pdftoppm/index.js +17 -4
- package/dist/safe-bash-command-pdftotext/index.js +11 -14
- package/dist/safe-bash-command-qpdf/index.d.ts +1 -0
- package/dist/safe-bash-command-qpdf/index.js +9 -6
- package/dist/safe-bash-command-rg/index.js +1 -1
- package/dist/safe-bash-command-rg/rg-command.js +1 -1
- package/dist/safe-bash-command-sed/index.js +1 -1
- package/dist/safe-bash-command-sed/sed.js +1 -1
- package/dist/safe-bash-command-shuf/input.d.ts +2 -2
- package/dist/safe-bash-command-shuf/input.js +2 -1
- package/dist/safe-bash-command-shuf/shuf.js +4 -2
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +97 -12
- package/dist/safe-bash-command-sponge/index.js +4 -1
- package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -0
- package/dist/safe-bash-command-sqlite3/index.js +510 -70
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +2 -2
- package/dist/safe-bash-command-ssconvert/index.js +44 -22
- package/dist/safe-bash-command-stat/command.js +1 -1
- package/dist/safe-bash-command-stat/index.js +1 -1
- package/dist/safe-bash-command-tar/create.d.ts +1 -0
- package/dist/safe-bash-command-tar/create.js +2 -2
- package/dist/safe-bash-command-tar/extract.js +2 -2
- package/dist/safe-bash-command-tar/index.js +4 -4
- package/dist/safe-bash-command-tar/modes.js +4 -4
- package/dist/safe-bash-command-tar/options.js +1 -1
- package/dist/safe-bash-command-truncate/index.js +2 -2
- package/dist/safe-bash-command-tsort/command.js +2 -2
- package/dist/safe-bash-command-tsort/index.js +2 -2
- package/dist/safe-bash-command-unalias/index.d.ts +12 -0
- package/dist/safe-bash-command-unalias/index.js +67 -0
- package/dist/safe-bash-command-unrtf/index.js +26 -4
- package/dist/safe-bash-command-xan/argv.d.ts +1 -1
- package/dist/safe-bash-command-xan/argv.js +2 -2
- package/dist/safe-bash-command-xan/budget.d.ts +0 -1
- package/dist/safe-bash-command-xan/budget.js +1 -1
- package/dist/safe-bash-command-xan/commands.js +6 -6
- package/dist/safe-bash-command-xan/csv.js +2 -2
- package/dist/safe-bash-command-xan/index.js +8 -9
- package/dist/safe-bash-command-xan/io.js +4 -4
- package/dist/safe-bash-command-xan/options.js +1 -1
- package/dist/safe-bash-command-xan/selector.js +2 -2
- package/dist/safe-bash-command-xmllint/index.js +45 -23
- package/dist/safe-bash-command-xxd/index.js +41 -10
- package/dist/safe-bash-command-yq/accounting.js +1 -1
- package/dist/safe-bash-command-yq/index.js +3 -2
- package/dist/safe-bash-command-yq/native-work.js +2 -0
- package/dist/safe-bash-command-yq/parser.js +2 -2
- package/dist/safe-bash-command-yq/query.js +5 -5
- package/dist/safe-bash-command-yq/toml.js +2 -2
- package/dist/safe-bash-command-zip/index.js +3 -3
- package/dist/safe-bash-compression-engine/bounded-codec.js +2 -2
- package/dist/safe-bash-compression-engine/codec-loader.js +1 -1
- package/dist/safe-bash-compression-engine/files.js +5 -5
- package/dist/safe-bash-compression-engine/index.js +4 -4
- package/dist/safe-bash-compression-engine/operand.js +5 -5
- package/dist/safe-bash-compression-engine/stream.js +4 -4
- package/dist/safe-bash-compression-engine/zstd-decode.js +3 -3
- package/dist/safe-bash-contracts/command.js +3 -3
- package/dist/safe-bash-contracts/default-executor.js +2 -2
- package/dist/safe-bash-contracts/diagnostics.js +3 -3
- package/dist/safe-bash-contracts/escaping.js +6 -6
- package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
- package/dist/safe-bash-contracts/filesystem-output.js +5 -5
- package/dist/safe-bash-contracts/http.d.ts +7 -0
- package/dist/safe-bash-contracts/index.js +8 -8
- package/dist/safe-bash-contracts/io.js +2 -2
- package/dist/safe-bash-contracts/output.js +3 -3
- package/dist/safe-bash-contracts/runtime-control.d.ts +2 -2
- package/dist/safe-bash-contracts/runtime-control.js +4 -2
- package/dist/safe-bash-contracts/signals.d.ts +2 -0
- package/dist/safe-bash-contracts/signals.js +3 -1
- package/dist/safe-bash-contracts/yield.js +1 -1
- package/dist/safe-bash-csv-engine/index.d.ts +2 -1
- package/dist/safe-bash-csv-engine/index.js +21 -15
- package/dist/safe-bash-io-engine/commands/search/requirements.js +2 -2
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +6 -6
- package/dist/safe-bash-io-engine/internal.js +1 -1
- package/dist/safe-bash-io-engine/shell/pattern.js +38 -18
- package/dist/safe-bash-line-ending-engine/convert.js +9 -204
- package/dist/safe-bash-line-ending-engine/encoding.js +9 -42
- package/dist/safe-bash-line-ending-engine/index.js +48 -0
- package/dist/safe-bash-line-ending-engine/info.js +9 -90
- package/dist/safe-bash-line-ending-engine/internal.js +15 -160
- package/dist/safe-bash-line-ending-engine/io.js +12 -289
- package/dist/safe-bash-line-ending-engine/stage.js +10 -160
- package/dist/safe-bash-markdown-engine/index.js +3 -3
- package/dist/safe-bash-network-engine/args.d.ts +6 -0
- package/dist/safe-bash-network-engine/args.js +4 -2
- package/dist/safe-bash-network-engine/body.js +1 -1
- package/dist/safe-bash-network-engine/fetch-transport.js +3 -1
- package/dist/safe-bash-network-engine/index.js +3 -1
- package/dist/safe-bash-network-engine/input.js +2 -2
- package/dist/safe-bash-network-engine/platform-portable.js +3 -1
- package/dist/safe-bash-query-engine/dates.d.ts +1 -1
- package/dist/safe-bash-query-engine/dates.js +1 -1
- package/dist/safe-bash-query-engine/index.js +6 -6
- package/dist/safe-bash-query-engine/interpreter.js +4 -4
- package/dist/safe-bash-query-engine/parser.js +1 -1
- package/dist/safe-bash-query-engine/query-core.js +6 -6
- package/dist/safe-bash-regex-engine/execution/bounded-provider.js +10 -0
- package/dist/safe-bash-regex-engine/index.js +1 -1
- package/dist/safe-bash-regex-engine/text/regex.d.ts +1 -1
- package/dist/safe-bash-regex-engine/text/regex.js +1 -1
- package/dist/safe-bash-search-engine/ergonomic-regex.d.ts +1 -0
- package/dist/safe-bash-search-engine/ergonomic-regex.js +1 -1
- package/dist/safe-bash-search-engine/grep.js +16 -9
- package/dist/safe-bash-search-engine/matcher.d.ts +2 -2
- package/dist/safe-bash-search-engine/matcher.js +12 -8
- package/dist/safe-bash-search-engine/shared.js +1 -1
- package/dist/safe-bash-search-engine/walk.js +13 -1
- package/dist/safe-bash-text-stream-engine/stream-format/shared.d.ts +1 -1
- package/dist/safe-bash-text-stream-engine/stream-format/shared.js +2 -1
- package/dist/safe-bash-xml-engine/document.js +3 -3
- package/dist/safe-bash-xml-engine/evaluate.js +2 -2
- package/dist/safe-bash-xml-engine/index.js +4 -4
- package/dist/safe-bash-xml-engine/io.js +7 -2
- package/dist/safe-bash-xml-engine/limits.d.ts +0 -2
- package/dist/safe-bash-xml-engine/limits.js +1 -1
- package/dist/safe-bash-xml-engine/query.js +3 -3
- package/dist/safe-bash-zip-engine/index.js +3 -3
- package/dist/safe-bash-zip-engine/zip/repair.js +3 -3
- package/dist/safe-bash-zip-engine/zip/safety.js +1 -1
- package/dist/safe-bash-zip-engine/zip/sfx.js +3 -3
- package/dist/safe-bash-zip-engine/zip/volumes.js +1 -1
- package/dist/safe-bash-zip-engine/zip-format.js +3 -3
- package/dist/safe-playwright-cloudflare/browser-socket-closure.js +18 -3
- package/dist/safe-playwright-cloudflare/shell-browser-resource.js +1 -1
- package/dist/xlsx-ast/xlsx.js +6 -5
- package/package.json +86 -98
- package/dist/media-cli/bytes.d.ts +0 -8
- package/dist/media-cli/bytes.js +0 -40
- package/dist/media-cli/concat.d.ts +0 -30
- package/dist/media-cli/concat.js +0 -197
- package/dist/media-cli/content.js +0 -66
- package/dist/media-cli/dependency-grammars.d.ts +0 -12
- package/dist/media-cli/dependency-grammars.js +0 -557
- package/dist/media-cli/discover.js +0 -286
- package/dist/media-cli/engine.js +0 -190
- package/dist/media-cli/filename-expression.js +0 -147
- package/dist/media-cli/filesystem.js +0 -35
- package/dist/media-cli/frontend-contract.js +0 -8
- package/dist/media-cli/frontend-issues.d.ts +0 -6
- package/dist/media-cli/frontend-issues.js +0 -9
- package/dist/media-cli/imagemagick-operand.d.ts +0 -42
- package/dist/media-cli/imagemagick-operand.js +0 -229
- package/dist/media-cli/imagemagick-references.d.ts +0 -7
- package/dist/media-cli/imagemagick-references.js +0 -42
- package/dist/media-cli/imagemagick.generated.js +0 -3254
- package/dist/media-cli/imagemagick.js +0 -615
- package/dist/media-cli/index.js +0 -12
- package/dist/media-cli/mvg.d.ts +0 -10
- package/dist/media-cli/mvg.js +0 -102
- package/dist/media-cli/network.js +0 -78
- package/dist/media-cli/options.generated.js +0 -3312
- package/dist/media-cli/preset.d.ts +0 -11
- package/dist/media-cli/preset.js +0 -57
- package/dist/media-cli/resolution-path.d.ts +0 -23
- package/dist/media-cli/resolution-path.js +0 -217
- package/dist/media-cli/resolver.js +0 -494
- package/dist/media-cli/resources.d.ts +0 -16
- package/dist/media-cli/resources.js +0 -187
- package/dist/media-cli/shim.js +0 -52
- package/dist/media-cli/tee.d.ts +0 -6
- package/dist/media-cli/tee.js +0 -38
- package/dist/office-package/zip-sync.js +0 -111
- package/dist/remote-execution/binary.js +0 -178
- package/dist/remote-execution/callback-result.js +0 -26
- package/dist/remote-execution/canonical-capabilities.d.ts +0 -5
- package/dist/remote-execution/canonical-capabilities.js +0 -45
- package/dist/remote-execution/canonical-metadata.d.ts +0 -4
- package/dist/remote-execution/canonical-metadata.js +0 -32
- package/dist/remote-execution/client.js +0 -824
- package/dist/remote-execution/deployment.js +0 -131
- package/dist/remote-execution/descriptors.js +0 -267
- package/dist/remote-execution/effects.js +0 -357
- package/dist/remote-execution/endpoint.js +0 -224
- package/dist/remote-execution/files.js +0 -291
- package/dist/remote-execution/hosting-operation.js +0 -26
- package/dist/remote-execution/hosting-request.d.ts +0 -4
- package/dist/remote-execution/hosting-request.js +0 -12
- package/dist/remote-execution/hosting-stream.d.ts +0 -8
- package/dist/remote-execution/hosting-stream.js +0 -64
- package/dist/remote-execution/index.js +0 -18
- package/dist/remote-execution/invocation-admission.d.ts +0 -3
- package/dist/remote-execution/invocation-admission.js +0 -17
- package/dist/remote-execution/job-binding.js +0 -1269
- package/dist/remote-execution/materializations.js +0 -284
- package/dist/remote-execution/modal-driver.js +0 -90
- package/dist/remote-execution/native-result.d.ts +0 -3
- package/dist/remote-execution/native-result.js +0 -16
- package/dist/remote-execution/output-freshness.d.ts +0 -4
- package/dist/remote-execution/output-freshness.js +0 -19
- package/dist/remote-execution/output-retrieval.js +0 -474
- package/dist/remote-execution/process-http.js +0 -607
- package/dist/remote-execution/process.js +0 -577
- package/dist/remote-execution/protocol.js +0 -208
- package/dist/remote-execution/relay.js +0 -91
- package/dist/remote-execution/rest-driver.js +0 -93
- package/dist/remote-execution/upload-descriptor.js +0 -201
- package/dist/remote-execution/upload-protocol.js +0 -62
- package/dist/remote-execution/uploads.js +0 -324
- package/dist/remote-execution/wire-json.d.ts +0 -4
- package/dist/remote-execution/wire-json.js +0 -44
- package/dist/remote-execution/wire-validation.js +0 -131
- package/dist/remote-execution/wire.generated.js +0 -4224
- package/dist/safe-bash/chunks/chunk-GDYNCWRV.js +0 -161
- package/dist/safe-bash/chunks/chunk-IWDICZVK.js +0 -20
- package/dist/safe-bash/chunks/chunk-MHMMRCYC.js +0 -3464
- package/dist/safe-bash/chunks/chunk-UE5KZDEK.js +0 -77
- package/dist/safe-bash/chunks/csvkit-TACDU7FC.js +0 -1618
- package/dist/safe-bash/chunks/implementation-MLFHUQ5M.js +0 -133
- package/dist/safe-bash/commands/csvkit/sync.js +0 -1639
- package/dist/safe-bash/commands/node/unconfigured.d.ts +0 -3
- package/dist/safe-bash/commands/node/unconfigured.js +0 -10
- package/dist/safe-bash/commands/pandoc/implementation.d.ts +0 -8
- package/dist/safe-bash/commands/pandoc/implementation.js +0 -94
- package/dist/safe-bash-mcp/index.browser.js +0 -9167
- package/dist/safe-bash/command-chunks/{chunk-ZRRBXU3M.js → chunk-GIN5GUDP.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-LAOM65EE.js → chunk-IEO4XVN6.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-BXCXRYVU.js → chunk-JNANXVJV.js} +0 -0
- package/dist/safe-bash/command-chunks/{chunk-364TMWBT.js → chunk-MWREVL44.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-464RVBGB.js → chunk-Q5TDKFHK.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-AJR3AQYA.js → chunk-UKX3LZHR.js} +0 -0
- package/dist/safe-bash/command-chunks/{chunk-XIIBTGC5.js → chunk-XPXEQKRW.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-FDBUV4HJ.js → chunk-Y4HGTG3E.js} +3 -3
- /package/dist/{safe-bash/commands/csvkit → safe-bash-command-csvkit}/sync.d.ts +0 -0
|
@@ -1,1639 +0,0 @@
|
|
|
1
|
-
import { readZipArchiveEntries } from "../../../office-package/zip-sync.js";
|
|
2
|
-
import { defaultHeaders, inferTable, readCsv, sniff, POSSIBLE_DELIMITERS, Decimal, pythonValueText, writeCsvRow, parseColumnIdentifiers, matchColumnIdentifier, } from "../../../safe-bash-command-csvkit/sync-support.js";
|
|
3
|
-
const syncUtf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
4
|
-
function parseSyncCsvkitCommon(opArgs, mode) {
|
|
5
|
-
const res = {
|
|
6
|
-
tabs: false,
|
|
7
|
-
noDoublequote: false,
|
|
8
|
-
skipInitialSpace: false,
|
|
9
|
-
noHeaderRow: false,
|
|
10
|
-
skipLines: 0,
|
|
11
|
-
lineNumbers: false,
|
|
12
|
-
addBom: false,
|
|
13
|
-
noInference: false,
|
|
14
|
-
blanks: false,
|
|
15
|
-
noLeadingZeroes: false,
|
|
16
|
-
sniffLimit: 1024,
|
|
17
|
-
noNumberEllipsis: false,
|
|
18
|
-
indent: null,
|
|
19
|
-
key: null,
|
|
20
|
-
streamOutput: false,
|
|
21
|
-
};
|
|
22
|
-
let positionalDone = false;
|
|
23
|
-
for (let i = 0; i < opArgs.length; i++) {
|
|
24
|
-
const a = opArgs[i];
|
|
25
|
-
if (!positionalDone && a === "--") {
|
|
26
|
-
positionalDone = true;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (!positionalDone && a.startsWith("-") && a !== "-") {
|
|
30
|
-
if (a === "-t" || a === "--tabs") {
|
|
31
|
-
res.tabs = true;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (a === "-b" || a === "--no-doublequote") {
|
|
35
|
-
res.noDoublequote = true;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (a === "-S" || a === "--skipinitialspace") {
|
|
39
|
-
res.skipInitialSpace = true;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (a === "-H" || a === "--no-header-row") {
|
|
43
|
-
res.noHeaderRow = true;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (a === "-l" || a === "--linenumbers") {
|
|
47
|
-
res.lineNumbers = true;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (a === "--add-bom") {
|
|
51
|
-
res.addBom = true;
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (a === "-I" || a === "--no-inference") {
|
|
55
|
-
res.noInference = true;
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (a === "--blanks") {
|
|
59
|
-
res.blanks = true;
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (a === "--no-leading-zeroes") {
|
|
63
|
-
res.noLeadingZeroes = true;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (a === "-d" || a.startsWith("-d") || a === "--delimiter" || a.startsWith("--delimiter=")) {
|
|
67
|
-
const v = a.startsWith("--delimiter=") ? a.slice(12) : a.startsWith("-d=") ? a.slice(3) : a.length > 2 && a.startsWith("-d") ? a.slice(2) : opArgs[++i];
|
|
68
|
-
if (!v || Array.from(v).length !== 1)
|
|
69
|
-
return undefined;
|
|
70
|
-
res.delimiter = v;
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (a === "-q" || a.startsWith("-q") || a === "--quotechar" || a.startsWith("--quotechar=")) {
|
|
74
|
-
const v = a.startsWith("--quotechar=") ? a.slice(12) : a.startsWith("-q=") ? a.slice(3) : a.length > 2 && a.startsWith("-q") ? a.slice(2) : opArgs[++i];
|
|
75
|
-
if (!v || Array.from(v).length !== 1)
|
|
76
|
-
return undefined;
|
|
77
|
-
res.quotechar = v;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (a === "-p" || a === "--escapechar") {
|
|
81
|
-
const v = opArgs[++i];
|
|
82
|
-
if (!v || Array.from(v).length !== 1)
|
|
83
|
-
return undefined;
|
|
84
|
-
res.escapechar = v;
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
if (a === "-K" || a.startsWith("-K") || a === "--skip-lines" || a.startsWith("--skip-lines=")) {
|
|
88
|
-
const v = a.startsWith("--skip-lines=") ? a.slice(13) : a.startsWith("-K=") ? a.slice(3) : a.length > 2 && a.startsWith("-K") ? a.slice(2) : opArgs[++i];
|
|
89
|
-
if (v === undefined || !/^[0-9]+$/.test(v))
|
|
90
|
-
return undefined;
|
|
91
|
-
res.skipLines = Number(v);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (a === "-y" || a === "--snifflimit") {
|
|
95
|
-
const v = opArgs[++i];
|
|
96
|
-
if (v === undefined || !/^-?[0-9]+$/.test(v))
|
|
97
|
-
return undefined;
|
|
98
|
-
res.sniffLimit = Number(v);
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
if (mode === "csvlook") {
|
|
102
|
-
if (a === "--no-number-ellipsis") {
|
|
103
|
-
res.noNumberEllipsis = true;
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (a === "--max-rows" || a === "--max-columns" || a === "--max-column-width" || a === "--max-precision") {
|
|
107
|
-
const v = opArgs[++i];
|
|
108
|
-
if (v === undefined || !/^[0-9]+$/.test(v))
|
|
109
|
-
return undefined;
|
|
110
|
-
const n = Number(v);
|
|
111
|
-
if (a === "--max-rows")
|
|
112
|
-
res.maxRows = n;
|
|
113
|
-
else if (a === "--max-columns")
|
|
114
|
-
res.maxColumns = n;
|
|
115
|
-
else if (a === "--max-column-width")
|
|
116
|
-
res.maxColumnWidth = n;
|
|
117
|
-
else
|
|
118
|
-
res.maxPrecision = n;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
if (a === "--stream") {
|
|
124
|
-
res.streamOutput = true;
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
if (a === "-i" || a.startsWith("-i") || a === "--indent" || a.startsWith("--indent=")) {
|
|
128
|
-
const v = a.startsWith("--indent=") ? a.slice(9) : a.startsWith("-i=") ? a.slice(3) : a.length > 2 && a.startsWith("-i") ? a.slice(2) : opArgs[++i];
|
|
129
|
-
if (v === undefined || !/^[0-9]+$/.test(v))
|
|
130
|
-
return undefined;
|
|
131
|
-
res.indent = Number(v);
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
if (a === "-k" || a.startsWith("-k") || a === "--key" || a.startsWith("--key=")) {
|
|
135
|
-
const v = a.startsWith("--key=") ? a.slice(6) : a.startsWith("-k=") ? a.slice(3) : a.length > 2 && a.startsWith("-k") ? a.slice(2) : opArgs[++i];
|
|
136
|
-
if (v === undefined)
|
|
137
|
-
return undefined;
|
|
138
|
-
res.key = v;
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (!a.startsWith("--") && a.length > 2) {
|
|
143
|
-
let ok = true;
|
|
144
|
-
for (let j = 1; j < a.length; j++) {
|
|
145
|
-
const ch = a[j];
|
|
146
|
-
if (ch === "t")
|
|
147
|
-
res.tabs = true;
|
|
148
|
-
else if (ch === "b")
|
|
149
|
-
res.noDoublequote = true;
|
|
150
|
-
else if (ch === "S")
|
|
151
|
-
res.skipInitialSpace = true;
|
|
152
|
-
else if (ch === "H")
|
|
153
|
-
res.noHeaderRow = true;
|
|
154
|
-
else if (ch === "l")
|
|
155
|
-
res.lineNumbers = true;
|
|
156
|
-
else if (ch === "I")
|
|
157
|
-
res.noInference = true;
|
|
158
|
-
else {
|
|
159
|
-
ok = false;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (ok)
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
if (res.filePath !== undefined)
|
|
169
|
-
return undefined;
|
|
170
|
-
res.filePath = a;
|
|
171
|
-
}
|
|
172
|
-
return res;
|
|
173
|
-
}
|
|
174
|
-
function loadSyncTypedTable(inBytes, opts, readFileSync) {
|
|
175
|
-
let sourceBytes = inBytes;
|
|
176
|
-
if (opts.filePath !== undefined && opts.filePath !== "-") {
|
|
177
|
-
if (!readFileSync)
|
|
178
|
-
return undefined;
|
|
179
|
-
sourceBytes = readFileSync(opts.filePath);
|
|
180
|
-
}
|
|
181
|
-
if (!sourceBytes || sourceBytes.byteLength > 16384)
|
|
182
|
-
return undefined;
|
|
183
|
-
let text;
|
|
184
|
-
try {
|
|
185
|
-
text = syncUtf8Decoder.decode(sourceBytes);
|
|
186
|
-
}
|
|
187
|
-
catch {
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
if (text.charCodeAt(0) === 0xfeff)
|
|
191
|
-
text = text.slice(1);
|
|
192
|
-
if (opts.skipLines > 0) {
|
|
193
|
-
let linesLeft = opts.skipLines;
|
|
194
|
-
let pos = 0;
|
|
195
|
-
while (pos < text.length && linesLeft > 0) {
|
|
196
|
-
const ch = text[pos++];
|
|
197
|
-
if (ch === "\r") {
|
|
198
|
-
if (text[pos] === "\n")
|
|
199
|
-
pos++;
|
|
200
|
-
linesLeft--;
|
|
201
|
-
}
|
|
202
|
-
else if (ch === "\n") {
|
|
203
|
-
linesLeft--;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
text = text.slice(pos);
|
|
207
|
-
}
|
|
208
|
-
const explicitDelimiter = opts.tabs ? "\t" : opts.delimiter;
|
|
209
|
-
let dialect = {
|
|
210
|
-
...(explicitDelimiter !== undefined ? { delimiter: explicitDelimiter } : {}),
|
|
211
|
-
...(opts.quotechar !== undefined ? { quotechar: opts.quotechar } : {}),
|
|
212
|
-
...(opts.escapechar !== undefined ? { escapechar: opts.escapechar } : {}),
|
|
213
|
-
doublequote: !opts.noDoublequote,
|
|
214
|
-
skipinitialspace: opts.skipInitialSpace,
|
|
215
|
-
};
|
|
216
|
-
if (!opts.tabs &&
|
|
217
|
-
opts.delimiter === undefined &&
|
|
218
|
-
opts.quotechar === undefined &&
|
|
219
|
-
opts.escapechar === undefined &&
|
|
220
|
-
!opts.noDoublequote &&
|
|
221
|
-
!opts.skipInitialSpace &&
|
|
222
|
-
opts.sniffLimit !== 0 &&
|
|
223
|
-
text.length > 0) {
|
|
224
|
-
const sample = opts.sniffLimit > 0 ? text.slice(0, opts.sniffLimit) : text;
|
|
225
|
-
if (sample.includes(",") && !/[\t;|:\x27]/.test(sample)) {
|
|
226
|
-
dialect = { delimiter: ",", quotechar: "\"", doublequote: true, skipinitialspace: false };
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
const sniffed = sniff(sample);
|
|
230
|
-
if (sniffed)
|
|
231
|
-
dialect = sniffed;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
let headers;
|
|
235
|
-
const rows = [];
|
|
236
|
-
const rowLimit = opts.maxRows;
|
|
237
|
-
for (const record of readCsv(text, dialect)) {
|
|
238
|
-
const values = record.cells.map(c => pythonValueText(c));
|
|
239
|
-
const cells = opts.lineNumbers
|
|
240
|
-
? [!opts.noHeaderRow && record.line === 1 ? "line_numbers" : String(record.line - (opts.noHeaderRow ? 0 : 1)), ...values]
|
|
241
|
-
: values;
|
|
242
|
-
if (headers === undefined) {
|
|
243
|
-
headers = opts.noHeaderRow ? defaultHeaders(cells.length) : cells;
|
|
244
|
-
if (headers.some(name => !name) || new Set(headers).size !== headers.length)
|
|
245
|
-
return undefined;
|
|
246
|
-
if (!opts.noHeaderRow) {
|
|
247
|
-
if (rowLimit === 0)
|
|
248
|
-
break;
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
rows.push(cells);
|
|
253
|
-
if (rowLimit !== undefined && rows.length >= rowLimit)
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
const inferenceOpts = {
|
|
257
|
-
now: Date.now(),
|
|
258
|
-
timezone: "UTC",
|
|
259
|
-
noInference: opts.noInference,
|
|
260
|
-
numberTextOnly: false,
|
|
261
|
-
blanks: opts.blanks,
|
|
262
|
-
nullValues: [],
|
|
263
|
-
noLeadingZeroes: opts.noLeadingZeroes,
|
|
264
|
-
maxDecimalDigits: Infinity,
|
|
265
|
-
maxDecimalExponent: Infinity,
|
|
266
|
-
};
|
|
267
|
-
return inferTable(headers ?? [], rows, inferenceOpts);
|
|
268
|
-
}
|
|
269
|
-
function syncPrecision(values) {
|
|
270
|
-
let whole = 1;
|
|
271
|
-
let places = 0;
|
|
272
|
-
for (const value of values) {
|
|
273
|
-
if (value === null || typeof value !== "object" || value.kind !== "decimal")
|
|
274
|
-
continue;
|
|
275
|
-
const d = Decimal.parse(value.value).normalized();
|
|
276
|
-
if (d.special || Math.abs(Number(d.toString())) === Infinity)
|
|
277
|
-
continue;
|
|
278
|
-
places = Math.max(places, -d.exponent);
|
|
279
|
-
whole = Math.max(whole, d.coefficient.toString().length + d.exponent);
|
|
280
|
-
}
|
|
281
|
-
return Math.min(places, 28 - whole);
|
|
282
|
-
}
|
|
283
|
-
function syncNumberText(value, places, ellipsis) {
|
|
284
|
-
const d = Decimal.parse(value);
|
|
285
|
-
if (d.special === "Infinity" || Math.abs(Number(d.toString())) === Infinity)
|
|
286
|
-
return value;
|
|
287
|
-
places = Math.max(0, places);
|
|
288
|
-
if (d.special) {
|
|
289
|
-
const digits = "NaN" + d.payload;
|
|
290
|
-
let grouped = "";
|
|
291
|
-
for (let i = 0; i < digits.length; i++) {
|
|
292
|
-
if (i && (digits.length - i) % 3 === 0)
|
|
293
|
-
grouped += ",";
|
|
294
|
-
grouped += digits[i];
|
|
295
|
-
}
|
|
296
|
-
return grouped + (places ? "." + "0".repeat(places) : "") + ellipsis;
|
|
297
|
-
}
|
|
298
|
-
let coefficient = d.coefficient;
|
|
299
|
-
const shift = d.exponent + places;
|
|
300
|
-
if (shift >= 0)
|
|
301
|
-
coefficient *= 10n ** BigInt(shift);
|
|
302
|
-
else {
|
|
303
|
-
const divisor = 10n ** BigInt(-shift);
|
|
304
|
-
const rest = coefficient % divisor;
|
|
305
|
-
coefficient /= divisor;
|
|
306
|
-
if (rest * 2n > divisor || (rest * 2n === divisor && coefficient % 2n !== 0n))
|
|
307
|
-
coefficient++;
|
|
308
|
-
}
|
|
309
|
-
if (coefficient.toString().length > 28)
|
|
310
|
-
throw new Error("InvalidOperation");
|
|
311
|
-
const digits = coefficient.toString().padStart(places + 1, "0");
|
|
312
|
-
const whole = digits.slice(0, digits.length - places);
|
|
313
|
-
let grouped = "";
|
|
314
|
-
for (let i = 0; i < whole.length; i++) {
|
|
315
|
-
if (i && (whole.length - i) % 3 === 0)
|
|
316
|
-
grouped += ",";
|
|
317
|
-
grouped += whole[i];
|
|
318
|
-
}
|
|
319
|
-
return (d.negative ? "-" : "") + grouped + (places ? "." + digits.slice(-places) : "") + ellipsis;
|
|
320
|
-
}
|
|
321
|
-
export function evalSyncCsvlook(inBytes, opArgs, readFileSync) {
|
|
322
|
-
try {
|
|
323
|
-
const opts = parseSyncCsvkitCommon(opArgs, "csvlook");
|
|
324
|
-
if (!opts)
|
|
325
|
-
return undefined;
|
|
326
|
-
const table = loadSyncTypedTable(inBytes, opts, readFileSync);
|
|
327
|
-
if (!table)
|
|
328
|
-
return undefined;
|
|
329
|
-
const maxColumns = opts.maxColumns ?? table.headers.length;
|
|
330
|
-
const width = opts.maxColumnWidth;
|
|
331
|
-
const maxPrecision = opts.maxPrecision ?? 3;
|
|
332
|
-
const cpLen = (v) => Array.from(v).length;
|
|
333
|
-
const truncate = (v) => {
|
|
334
|
-
const chars = Array.from(v);
|
|
335
|
-
return width !== undefined && chars.length > width ? chars.slice(0, width - 3).join("") + "..." : v;
|
|
336
|
-
};
|
|
337
|
-
const names = table.headers.slice(0, maxColumns).map(truncate);
|
|
338
|
-
if (maxColumns < table.headers.length)
|
|
339
|
-
names.push("...");
|
|
340
|
-
const widths = names.map(cpLen);
|
|
341
|
-
const formats = table.columns.map((column, index) => {
|
|
342
|
-
if (index >= maxColumns || column.type !== "Number")
|
|
343
|
-
return undefined;
|
|
344
|
-
const places = syncPrecision(table.rows.map(row => row[index]));
|
|
345
|
-
return { places: Math.min(places, maxPrecision), ellipsis: places > maxPrecision && !opts.noNumberEllipsis ? "…" : "" };
|
|
346
|
-
});
|
|
347
|
-
const renderedRows = table.rows.map(row => {
|
|
348
|
-
const cells = [];
|
|
349
|
-
for (const [j, value] of row.entries()) {
|
|
350
|
-
const format = formats[j];
|
|
351
|
-
let text = j >= maxColumns
|
|
352
|
-
? "..."
|
|
353
|
-
: value === null
|
|
354
|
-
? ""
|
|
355
|
-
: format && typeof value === "object" && value.kind === "decimal"
|
|
356
|
-
? syncNumberText(value.value, format.places, format.ellipsis)
|
|
357
|
-
: pythonValueText(value).replaceAll("\n", "↵");
|
|
358
|
-
text = truncate(text);
|
|
359
|
-
widths[j] = Math.max(widths[j], cpLen(text));
|
|
360
|
-
cells.push(text);
|
|
361
|
-
if (j >= maxColumns)
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
return cells;
|
|
365
|
-
});
|
|
366
|
-
const formatRow = (cells) => {
|
|
367
|
-
const fields = cells.map((cell, j) => {
|
|
368
|
-
const col = table.columns[j];
|
|
369
|
-
if (!col)
|
|
370
|
-
throw new Error("IndexError");
|
|
371
|
-
const spaces = widths[j] - cpLen(cell);
|
|
372
|
-
const padding = " ".repeat(Math.max(0, spaces));
|
|
373
|
-
return col.type === "Text" ? " " + cell + padding + " " : " " + padding + cell + " ";
|
|
374
|
-
});
|
|
375
|
-
return "|" + fields.join("|") + "|\n";
|
|
376
|
-
};
|
|
377
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
378
|
-
out += formatRow(names);
|
|
379
|
-
out += "| " + widths.map(size => "-".repeat(size)).join(" | ") + " |\n";
|
|
380
|
-
for (const row of renderedRows)
|
|
381
|
-
out += formatRow(row);
|
|
382
|
-
return out;
|
|
383
|
-
}
|
|
384
|
-
catch {
|
|
385
|
-
return undefined;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
function syncFloatText(value) {
|
|
389
|
-
if (Number.isNaN(value))
|
|
390
|
-
return "NaN";
|
|
391
|
-
if (!Number.isFinite(value))
|
|
392
|
-
return value < 0 ? "-Infinity" : "Infinity";
|
|
393
|
-
if (Object.is(value, -0))
|
|
394
|
-
return "-0.0";
|
|
395
|
-
const exponent = Number(value.toExponential().split("e")[1]);
|
|
396
|
-
if (value !== 0 && (exponent < -4 || exponent >= 16)) {
|
|
397
|
-
const [digits, power] = value.toExponential().split("e");
|
|
398
|
-
const exp = Number(power);
|
|
399
|
-
return digits + "e" + (exp < 0 ? "-" : "+") + String(Math.abs(exp)).padStart(2, "0");
|
|
400
|
-
}
|
|
401
|
-
return String(value) + (Number.isInteger(value) ? ".0" : "");
|
|
402
|
-
}
|
|
403
|
-
function emitSyncJson(cur, indent, d = 0) {
|
|
404
|
-
if (typeof cur === "number")
|
|
405
|
-
return syncFloatText(cur);
|
|
406
|
-
if (cur === null || typeof cur === "string" || typeof cur === "boolean")
|
|
407
|
-
return JSON.stringify(cur);
|
|
408
|
-
if (cur instanceof Map) {
|
|
409
|
-
let buf = "{";
|
|
410
|
-
let index = 0;
|
|
411
|
-
const childPad = indent !== null ? "\n" + " ".repeat(indent * (d + 1)) : "";
|
|
412
|
-
for (const [key, child] of cur.entries()) {
|
|
413
|
-
if (index++)
|
|
414
|
-
buf += indent === null ? ", " : ",";
|
|
415
|
-
if (indent !== null)
|
|
416
|
-
buf += childPad;
|
|
417
|
-
buf += JSON.stringify(key) + ": " + emitSyncJson(child, indent, d + 1);
|
|
418
|
-
}
|
|
419
|
-
if (cur.size && indent !== null)
|
|
420
|
-
buf += "\n" + " ".repeat(indent * d);
|
|
421
|
-
buf += "}";
|
|
422
|
-
return buf;
|
|
423
|
-
}
|
|
424
|
-
const arr = cur;
|
|
425
|
-
let buf = "[";
|
|
426
|
-
const childPad = indent !== null ? "\n" + " ".repeat(indent * (d + 1)) : "";
|
|
427
|
-
for (let index = 0; index < arr.length; index++) {
|
|
428
|
-
if (index)
|
|
429
|
-
buf += indent === null ? ", " : ",";
|
|
430
|
-
if (indent !== null)
|
|
431
|
-
buf += childPad;
|
|
432
|
-
buf += emitSyncJson(arr[index], indent, d + 1);
|
|
433
|
-
}
|
|
434
|
-
if (arr.length && indent !== null)
|
|
435
|
-
buf += "\n" + " ".repeat(indent * d);
|
|
436
|
-
buf += "]";
|
|
437
|
-
return buf;
|
|
438
|
-
}
|
|
439
|
-
export function evalSyncCsvjson(inBytes, opArgs, readFileSync) {
|
|
440
|
-
try {
|
|
441
|
-
const opts = parseSyncCsvkitCommon(opArgs, "csvjson");
|
|
442
|
-
if (!opts)
|
|
443
|
-
return undefined;
|
|
444
|
-
if (opts.streamOutput && opts.key !== null)
|
|
445
|
-
return undefined;
|
|
446
|
-
if (opts.streamOutput && opts.indent !== null)
|
|
447
|
-
return undefined;
|
|
448
|
-
const table = loadSyncTypedTable(inBytes, opts, readFileSync);
|
|
449
|
-
if (!table)
|
|
450
|
-
return undefined;
|
|
451
|
-
const jsonify = (value) => {
|
|
452
|
-
if (typeof value !== "object" || value === null)
|
|
453
|
-
return value;
|
|
454
|
-
if (value.kind === "decimal")
|
|
455
|
-
return value.value.includes("NaN") ? NaN : Number(value.value);
|
|
456
|
-
if (value.kind === "datetime")
|
|
457
|
-
return value.value.replace(" ", "T");
|
|
458
|
-
return pythonValueText(value);
|
|
459
|
-
};
|
|
460
|
-
const rows = table.rows.map(row => new Map(table.headers.map((name, index) => [name, jsonify(row[index])])));
|
|
461
|
-
let output = rows;
|
|
462
|
-
if (opts.key !== null) {
|
|
463
|
-
const column = table.headers.indexOf(opts.key);
|
|
464
|
-
if (column < 0 && rows.length)
|
|
465
|
-
return undefined;
|
|
466
|
-
const keyed = new Map();
|
|
467
|
-
for (const [index, row] of table.rows.entries()) {
|
|
468
|
-
const cell = row[column];
|
|
469
|
-
const value = cell === null
|
|
470
|
-
? "None"
|
|
471
|
-
: typeof cell === "object" && cell.kind === "decimal"
|
|
472
|
-
? Decimal.parse(cell.value).normalized().toString()
|
|
473
|
-
: pythonValueText(cell);
|
|
474
|
-
if (keyed.has(value))
|
|
475
|
-
return undefined;
|
|
476
|
-
keyed.set(value, rows[index]);
|
|
477
|
-
}
|
|
478
|
-
output = keyed;
|
|
479
|
-
}
|
|
480
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
481
|
-
if (opts.streamOutput) {
|
|
482
|
-
for (const row of rows) {
|
|
483
|
-
out += emitSyncJson(row, opts.indent) + "\n";
|
|
484
|
-
}
|
|
485
|
-
return out;
|
|
486
|
-
}
|
|
487
|
-
out += emitSyncJson(output, opts.indent);
|
|
488
|
-
return out;
|
|
489
|
-
}
|
|
490
|
-
catch {
|
|
491
|
-
return undefined;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
export function evalSyncCsvsort(inBytes, opArgs, readFileSync) {
|
|
495
|
-
try {
|
|
496
|
-
let columnsSpec = null;
|
|
497
|
-
let reverse = false;
|
|
498
|
-
let ignoreCase = false;
|
|
499
|
-
let namesOnly = false;
|
|
500
|
-
let zeroBased = false;
|
|
501
|
-
const filteredArgs = [];
|
|
502
|
-
let posDone = false;
|
|
503
|
-
for (let i = 0; i < opArgs.length; i++) {
|
|
504
|
-
const a = opArgs[i];
|
|
505
|
-
if (!posDone && a === "--") {
|
|
506
|
-
posDone = true;
|
|
507
|
-
filteredArgs.push(a);
|
|
508
|
-
continue;
|
|
509
|
-
}
|
|
510
|
-
if (!posDone && a.startsWith("-") && a !== "-") {
|
|
511
|
-
if (a === "-r" || a === "--reverse") {
|
|
512
|
-
reverse = true;
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
if (a === "-i" || a === "--ignore-case") {
|
|
516
|
-
ignoreCase = true;
|
|
517
|
-
continue;
|
|
518
|
-
}
|
|
519
|
-
if (a === "-n" || a === "--names") {
|
|
520
|
-
namesOnly = true;
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
if (a === "--zero") {
|
|
524
|
-
zeroBased = true;
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
if (a === "-ri" || a === "-ir") {
|
|
528
|
-
reverse = true;
|
|
529
|
-
ignoreCase = true;
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
if (a === "-c" || a.startsWith("-c") || a === "--columns" || a.startsWith("--columns=")) {
|
|
533
|
-
const v = a.startsWith("--columns=") ? a.slice(10) : a.startsWith("-c=") ? a.slice(3) : a.length > 2 && a.startsWith("-c") ? a.slice(2) : opArgs[++i];
|
|
534
|
-
if (v === undefined)
|
|
535
|
-
return undefined;
|
|
536
|
-
columnsSpec = v;
|
|
537
|
-
continue;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
filteredArgs.push(a);
|
|
541
|
-
}
|
|
542
|
-
const opts = parseSyncCsvkitCommon(filteredArgs, "csvlook");
|
|
543
|
-
if (!opts)
|
|
544
|
-
return undefined;
|
|
545
|
-
const table = loadSyncTypedTable(inBytes, opts, readFileSync);
|
|
546
|
-
if (!table)
|
|
547
|
-
return undefined;
|
|
548
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
549
|
-
if (namesOnly) {
|
|
550
|
-
if (opts.noHeaderRow)
|
|
551
|
-
return undefined;
|
|
552
|
-
for (let i = 0; i < table.headers.length; i++) {
|
|
553
|
-
out += `${String(i + (zeroBased ? 0 : 1)).padStart(3, " ")}: ${table.headers[i]}\n`;
|
|
554
|
-
}
|
|
555
|
-
return out;
|
|
556
|
-
}
|
|
557
|
-
const columns = parseColumnIdentifiers(columnsSpec, table.headers, zeroBased ? 0 : 1, null, () => { }, true);
|
|
558
|
-
const rows = [...table.rows];
|
|
559
|
-
const keyed = rows.map(row => columns.map(idx => {
|
|
560
|
-
const val = row[idx];
|
|
561
|
-
return ignoreCase && typeof val === "string" ? val.toUpperCase() : val;
|
|
562
|
-
}));
|
|
563
|
-
const indices = rows.map((_, i) => i);
|
|
564
|
-
indices.sort((a, b) => {
|
|
565
|
-
for (let c = 0; c < columns.length; c++) {
|
|
566
|
-
const x = keyed[a][c];
|
|
567
|
-
const y = keyed[b][c];
|
|
568
|
-
let order = 0;
|
|
569
|
-
if (x === null || y === null)
|
|
570
|
-
order = x === null ? (y === null ? 0 : 1) : -1;
|
|
571
|
-
else if (typeof x === "string" && typeof y === "string") {
|
|
572
|
-
order = x < y ? -1 : x > y ? 1 : 0;
|
|
573
|
-
}
|
|
574
|
-
else if (typeof x === "boolean" && typeof y === "boolean") {
|
|
575
|
-
order = Number(x) - Number(y);
|
|
576
|
-
}
|
|
577
|
-
else if (typeof x === "object" && typeof y === "object" && x.kind === "decimal" && y.kind === "decimal") {
|
|
578
|
-
if (x.value.includes("NaN") || y.value.includes("NaN"))
|
|
579
|
-
throw new Error("NaN");
|
|
580
|
-
order = Decimal.parse(x.value).compare(Decimal.parse(y.value));
|
|
581
|
-
}
|
|
582
|
-
else if (typeof x === "object" && typeof y === "object" && (x.kind === "date" || x.kind === "datetime") && (y.kind === "date" || y.kind === "datetime") && x.kind === y.kind) {
|
|
583
|
-
order = x.value < y.value ? -1 : x.value > y.value ? 1 : 0;
|
|
584
|
-
}
|
|
585
|
-
else if (typeof x === "object" && typeof y === "object" && x.kind === "timedelta" && y.kind === "timedelta") {
|
|
586
|
-
order = x.microseconds < y.microseconds ? -1 : x.microseconds > y.microseconds ? 1 : 0;
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
throw new Error("unsupported type");
|
|
590
|
-
}
|
|
591
|
-
if (order !== 0)
|
|
592
|
-
return reverse ? -order : order;
|
|
593
|
-
}
|
|
594
|
-
return 0;
|
|
595
|
-
});
|
|
596
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
597
|
-
out += writeCsvRow(table.headers, outDialect);
|
|
598
|
-
for (const idx of indices) {
|
|
599
|
-
const formattedCells = rows[idx].map(v => {
|
|
600
|
-
if (v === null)
|
|
601
|
-
return "";
|
|
602
|
-
if (typeof v === "object" && v.kind === "datetime")
|
|
603
|
-
return v.value.replace(" ", "T");
|
|
604
|
-
return pythonValueText(v);
|
|
605
|
-
});
|
|
606
|
-
out += writeCsvRow(formattedCells, outDialect);
|
|
607
|
-
}
|
|
608
|
-
return out;
|
|
609
|
-
}
|
|
610
|
-
catch {
|
|
611
|
-
return undefined;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
export function evalSyncCsvformat(inBytes, opArgs, readFileSync) {
|
|
615
|
-
try {
|
|
616
|
-
let outDelimiter = ",";
|
|
617
|
-
let outTabs = false;
|
|
618
|
-
let outAsv = false;
|
|
619
|
-
let outQuotechar = "\"";
|
|
620
|
-
let outQuoting = 0;
|
|
621
|
-
let outNoDoublequote = false;
|
|
622
|
-
let outEscapechar;
|
|
623
|
-
let outLineterminator = "\n";
|
|
624
|
-
let skipHeader = false;
|
|
625
|
-
const filteredArgs = [];
|
|
626
|
-
let posDone = false;
|
|
627
|
-
for (let i = 0; i < opArgs.length; i++) {
|
|
628
|
-
const a = opArgs[i];
|
|
629
|
-
if (!posDone && a === "--") {
|
|
630
|
-
posDone = true;
|
|
631
|
-
filteredArgs.push(a);
|
|
632
|
-
continue;
|
|
633
|
-
}
|
|
634
|
-
if (!posDone && a.startsWith("-") && a !== "-") {
|
|
635
|
-
if (a === "-E" || a === "--skip-header") {
|
|
636
|
-
skipHeader = true;
|
|
637
|
-
continue;
|
|
638
|
-
}
|
|
639
|
-
if (a === "-T" || a === "--out-tabs") {
|
|
640
|
-
outTabs = true;
|
|
641
|
-
continue;
|
|
642
|
-
}
|
|
643
|
-
if (a === "-A" || a === "--out-asv") {
|
|
644
|
-
outAsv = true;
|
|
645
|
-
continue;
|
|
646
|
-
}
|
|
647
|
-
if (a === "-B" || a === "--out-no-doublequote") {
|
|
648
|
-
outNoDoublequote = true;
|
|
649
|
-
continue;
|
|
650
|
-
}
|
|
651
|
-
if (a === "-D" || a.startsWith("-D") || a === "--out-delimiter" || a.startsWith("--out-delimiter=")) {
|
|
652
|
-
const v = a.startsWith("--out-delimiter=") ? a.slice(16) : a.startsWith("-D=") ? a.slice(3) : a.length > 2 && a.startsWith("-D") ? a.slice(2) : opArgs[++i];
|
|
653
|
-
if (!v || Array.from(v).length !== 1)
|
|
654
|
-
return undefined;
|
|
655
|
-
outDelimiter = v;
|
|
656
|
-
continue;
|
|
657
|
-
}
|
|
658
|
-
if (a === "-Q" || a.startsWith("-Q") || a === "--out-quotechar" || a.startsWith("--out-quotechar=")) {
|
|
659
|
-
const v = a.startsWith("--out-quotechar=") ? a.slice(16) : a.startsWith("-Q=") ? a.slice(3) : a.length > 2 && a.startsWith("-Q") ? a.slice(2) : opArgs[++i];
|
|
660
|
-
if (!v || Array.from(v).length !== 1)
|
|
661
|
-
return undefined;
|
|
662
|
-
outQuotechar = v;
|
|
663
|
-
continue;
|
|
664
|
-
}
|
|
665
|
-
if (a === "-P" || a === "--out-escapechar") {
|
|
666
|
-
const v = opArgs[++i];
|
|
667
|
-
if (!v || Array.from(v).length !== 1)
|
|
668
|
-
return undefined;
|
|
669
|
-
outEscapechar = v;
|
|
670
|
-
continue;
|
|
671
|
-
}
|
|
672
|
-
if (a === "-M" || a.startsWith("-M") || a === "--out-lineterminator" || a.startsWith("--out-lineterminator=")) {
|
|
673
|
-
const v = a.startsWith("--out-lineterminator=") ? a.slice(21) : a.startsWith("-M=") ? a.slice(3) : a.length > 2 && a.startsWith("-M") ? a.slice(2) : opArgs[++i];
|
|
674
|
-
if (v === undefined)
|
|
675
|
-
return undefined;
|
|
676
|
-
outLineterminator = v;
|
|
677
|
-
continue;
|
|
678
|
-
}
|
|
679
|
-
if (a === "-U" || a.startsWith("-U") || a === "--out-quoting" || a.startsWith("--out-quoting=")) {
|
|
680
|
-
const v = a.startsWith("--out-quoting=") ? a.slice(14) : a.startsWith("-U=") ? a.slice(3) : a.length > 2 && a.startsWith("-U") ? a.slice(2) : opArgs[++i];
|
|
681
|
-
if (v === undefined || !/^[0123]$/.test(v))
|
|
682
|
-
return undefined;
|
|
683
|
-
outQuoting = Number(v);
|
|
684
|
-
continue;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
filteredArgs.push(a);
|
|
688
|
-
}
|
|
689
|
-
const opts = parseSyncCsvkitCommon(filteredArgs, "csvlook");
|
|
690
|
-
if (!opts)
|
|
691
|
-
return undefined;
|
|
692
|
-
let sourceBytes = inBytes;
|
|
693
|
-
if (opts.filePath !== undefined && opts.filePath !== "-") {
|
|
694
|
-
if (!readFileSync)
|
|
695
|
-
return undefined;
|
|
696
|
-
sourceBytes = readFileSync(opts.filePath);
|
|
697
|
-
}
|
|
698
|
-
if (!sourceBytes || sourceBytes.byteLength > 16384)
|
|
699
|
-
return undefined;
|
|
700
|
-
let text = syncUtf8Decoder.decode(sourceBytes);
|
|
701
|
-
if (text.charCodeAt(0) === 0xfeff)
|
|
702
|
-
text = text.slice(1);
|
|
703
|
-
if (opts.skipLines > 0) {
|
|
704
|
-
let linesLeft = opts.skipLines;
|
|
705
|
-
let pos = 0;
|
|
706
|
-
while (pos < text.length && linesLeft > 0) {
|
|
707
|
-
const ch = text[pos++];
|
|
708
|
-
if (ch === "\r") {
|
|
709
|
-
if (text[pos] === "\n")
|
|
710
|
-
pos++;
|
|
711
|
-
linesLeft--;
|
|
712
|
-
}
|
|
713
|
-
else if (ch === "\n")
|
|
714
|
-
linesLeft--;
|
|
715
|
-
}
|
|
716
|
-
text = text.slice(pos);
|
|
717
|
-
}
|
|
718
|
-
const explicitInDelimiter = opts.tabs ? "\t" : opts.delimiter;
|
|
719
|
-
let inDialect = {
|
|
720
|
-
...(explicitInDelimiter !== undefined ? { delimiter: explicitInDelimiter } : {}),
|
|
721
|
-
...(opts.quotechar !== undefined ? { quotechar: opts.quotechar } : {}),
|
|
722
|
-
...(opts.escapechar !== undefined ? { escapechar: opts.escapechar } : {}),
|
|
723
|
-
doublequote: !opts.noDoublequote,
|
|
724
|
-
skipinitialspace: opts.skipInitialSpace,
|
|
725
|
-
};
|
|
726
|
-
if (!opts.tabs &&
|
|
727
|
-
opts.delimiter === undefined &&
|
|
728
|
-
opts.quotechar === undefined &&
|
|
729
|
-
opts.escapechar === undefined &&
|
|
730
|
-
!opts.noDoublequote &&
|
|
731
|
-
!opts.skipInitialSpace &&
|
|
732
|
-
opts.sniffLimit !== 0 &&
|
|
733
|
-
text.length > 0) {
|
|
734
|
-
const sample = opts.sniffLimit > 0 ? text.slice(0, opts.sniffLimit) : text;
|
|
735
|
-
if (sample.includes(",") && !/[\t;|:\x27]/.test(sample)) {
|
|
736
|
-
inDialect = { delimiter: ",", quotechar: "\"", doublequote: true, skipinitialspace: false };
|
|
737
|
-
}
|
|
738
|
-
else {
|
|
739
|
-
const sniffed = sniff(sample);
|
|
740
|
-
if (sniffed)
|
|
741
|
-
inDialect = sniffed;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
const outDialect = {
|
|
745
|
-
delimiter: outAsv ? "\x1f" : outTabs ? "\t" : outDelimiter,
|
|
746
|
-
lineterminator: outAsv ? "\x1e" : outLineterminator,
|
|
747
|
-
quotechar: outQuotechar,
|
|
748
|
-
quoting: outQuoting,
|
|
749
|
-
doublequote: !outNoDoublequote,
|
|
750
|
-
...(outEscapechar !== undefined ? { escapechar: outEscapechar } : {}),
|
|
751
|
-
};
|
|
752
|
-
writeCsvRow([], outDialect);
|
|
753
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
754
|
-
let first = true;
|
|
755
|
-
for (const record of readCsv(text, inDialect)) {
|
|
756
|
-
const values = record.cells.map(c => pythonValueText(c));
|
|
757
|
-
if (first) {
|
|
758
|
-
first = false;
|
|
759
|
-
if (opts.noHeaderRow) {
|
|
760
|
-
if (!skipHeader) {
|
|
761
|
-
const hdr = defaultHeaders(values.length);
|
|
762
|
-
out += writeCsvRow(opts.lineNumbers ? ["line_number", ...hdr] : hdr, outDialect);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
else {
|
|
766
|
-
if (!skipHeader) {
|
|
767
|
-
out += writeCsvRow(opts.lineNumbers ? ["line_number", ...values] : values, outDialect);
|
|
768
|
-
}
|
|
769
|
-
continue;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
const rowCells = opts.lineNumbers ? [String(record.line - (opts.noHeaderRow ? 0 : 1)), ...values] : values;
|
|
773
|
-
out += writeCsvRow(rowCells, outDialect);
|
|
774
|
-
}
|
|
775
|
-
return out;
|
|
776
|
-
}
|
|
777
|
-
catch {
|
|
778
|
-
return undefined;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
export function evalSyncCsvstat(inBytes, opArgs, readFileSync) {
|
|
782
|
-
try {
|
|
783
|
-
let countOnly = false;
|
|
784
|
-
let namesOnly = false;
|
|
785
|
-
let zeroBased = false;
|
|
786
|
-
let noGrouping = false;
|
|
787
|
-
let columnsSpec = null;
|
|
788
|
-
let metricOp;
|
|
789
|
-
const filteredArgs = [];
|
|
790
|
-
let posDone = false;
|
|
791
|
-
for (let i = 0; i < opArgs.length; i++) {
|
|
792
|
-
const a = opArgs[i];
|
|
793
|
-
if (!posDone && a === "--") {
|
|
794
|
-
posDone = true;
|
|
795
|
-
filteredArgs.push(a);
|
|
796
|
-
continue;
|
|
797
|
-
}
|
|
798
|
-
if (!posDone && a.startsWith("-") && a !== "-") {
|
|
799
|
-
if (a === "--count") {
|
|
800
|
-
countOnly = true;
|
|
801
|
-
continue;
|
|
802
|
-
}
|
|
803
|
-
if (a === "-n" || a === "--names") {
|
|
804
|
-
namesOnly = true;
|
|
805
|
-
continue;
|
|
806
|
-
}
|
|
807
|
-
if (a === "--zero") {
|
|
808
|
-
zeroBased = true;
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
if (a === "-G" || a === "--no-grouping-separator") {
|
|
812
|
-
noGrouping = true;
|
|
813
|
-
continue;
|
|
814
|
-
}
|
|
815
|
-
if (a === "-c" || a.startsWith("-c") || a === "--columns" || a.startsWith("--columns=")) {
|
|
816
|
-
const v = a.startsWith("--columns=") ? a.slice(10) : a.startsWith("-c=") ? a.slice(3) : a.length > 2 && a.startsWith("-c") ? a.slice(2) : opArgs[++i];
|
|
817
|
-
if (!v)
|
|
818
|
-
return undefined;
|
|
819
|
-
columnsSpec = v;
|
|
820
|
-
continue;
|
|
821
|
-
}
|
|
822
|
-
const mMap = {
|
|
823
|
-
"--type": "type", "--nulls": "nulls", "--non-nulls": "nonnulls",
|
|
824
|
-
"--unique": "unique", "--min": "min", "--max": "max",
|
|
825
|
-
"--sum": "sum", "--mean": "mean", "--median": "median",
|
|
826
|
-
"--stdev": "stdev", "--max-precision": "max_precision", "--len": "len",
|
|
827
|
-
};
|
|
828
|
-
if (mMap[a]) {
|
|
829
|
-
if (metricOp !== undefined)
|
|
830
|
-
return undefined;
|
|
831
|
-
metricOp = mMap[a];
|
|
832
|
-
continue;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
filteredArgs.push(a);
|
|
836
|
-
}
|
|
837
|
-
const modeCount = (countOnly ? 1 : 0) + (namesOnly ? 1 : 0) + (metricOp ? 1 : 0);
|
|
838
|
-
if (modeCount !== 1)
|
|
839
|
-
return undefined;
|
|
840
|
-
const opts = parseSyncCsvkitCommon(filteredArgs, "csvlook");
|
|
841
|
-
if (!opts)
|
|
842
|
-
return undefined;
|
|
843
|
-
const table = loadSyncTypedTable(inBytes, opts, readFileSync);
|
|
844
|
-
if (!table)
|
|
845
|
-
return undefined;
|
|
846
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
847
|
-
if (namesOnly) {
|
|
848
|
-
if (opts.noHeaderRow)
|
|
849
|
-
return undefined;
|
|
850
|
-
for (let i = 0; i < table.headers.length; i++) {
|
|
851
|
-
out += `${String(i + (zeroBased ? 0 : 1)).padStart(3, " ")}: ${table.headers[i]}\n`;
|
|
852
|
-
}
|
|
853
|
-
return out;
|
|
854
|
-
}
|
|
855
|
-
if (countOnly) {
|
|
856
|
-
return out + `${table.rows.length}\n`;
|
|
857
|
-
}
|
|
858
|
-
const ids = parseColumnIdentifiers(columnsSpec, table.headers, zeroBased ? 0 : 1, undefined, () => { }, true);
|
|
859
|
-
const fmtDec = (d) => {
|
|
860
|
-
const num = Number(d.toString());
|
|
861
|
-
if (!Number.isFinite(num))
|
|
862
|
-
return d.toString();
|
|
863
|
-
let s = num.toFixed(3);
|
|
864
|
-
while (s.endsWith("0"))
|
|
865
|
-
s = s.slice(0, -1);
|
|
866
|
-
if (s.endsWith("."))
|
|
867
|
-
s = s.slice(0, -1);
|
|
868
|
-
if (!noGrouping) {
|
|
869
|
-
const [intPart = "", fracPart] = s.split(".");
|
|
870
|
-
const sign = intPart.startsWith("-") ? "-" : "";
|
|
871
|
-
const digits = sign ? intPart.slice(1) : intPart;
|
|
872
|
-
const grouped = digits.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
873
|
-
s = sign + grouped + (fracPart !== undefined ? "." + fracPart : "");
|
|
874
|
-
}
|
|
875
|
-
return s;
|
|
876
|
-
};
|
|
877
|
-
for (const id of ids) {
|
|
878
|
-
const colType = table.columns[id].type;
|
|
879
|
-
const values = table.rows.map(r => r[id]);
|
|
880
|
-
const nonNull = values.filter(v => v !== null);
|
|
881
|
-
let valStr = "None";
|
|
882
|
-
if (metricOp === "type")
|
|
883
|
-
valStr = colType;
|
|
884
|
-
else if (metricOp === "nulls")
|
|
885
|
-
valStr = nonNull.length !== values.length ? "True" : "False";
|
|
886
|
-
else if (metricOp === "nonnulls")
|
|
887
|
-
valStr = String(nonNull.length);
|
|
888
|
-
else if (metricOp === "unique") {
|
|
889
|
-
const seen = new Set(values.map(v => v === null ? "null" : typeof v === "object" && v.kind === "decimal" ? "d:" + Decimal.parse(v.value).normalized().toString() : typeof v + ":" + pythonValueText(v)));
|
|
890
|
-
valStr = String(seen.size);
|
|
891
|
-
}
|
|
892
|
-
else if (metricOp === "len" && colType === "Text") {
|
|
893
|
-
let maxLen = 0;
|
|
894
|
-
for (const v of nonNull)
|
|
895
|
-
maxLen = Math.max(maxLen, Array.from(String(v)).length);
|
|
896
|
-
valStr = fmtDec(Decimal.parse(String(maxLen)));
|
|
897
|
-
}
|
|
898
|
-
else if ((metricOp === "min" || metricOp === "max") && colType !== "Number") {
|
|
899
|
-
if (nonNull.length > 0) {
|
|
900
|
-
const strs = nonNull.map(v => typeof v === "object" && v !== null && "value" in v ? String(v.value) : pythonValueText(v));
|
|
901
|
-
let best = strs[0];
|
|
902
|
-
for (let k = 1; k < strs.length; k++) {
|
|
903
|
-
if (metricOp === "min" ? strs[k] < best : strs[k] > best)
|
|
904
|
-
best = strs[k];
|
|
905
|
-
}
|
|
906
|
-
valStr = best;
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
else if ((metricOp === "min" || metricOp === "max" || metricOp === "sum" || metricOp === "mean" || metricOp === "median" || metricOp === "stdev" || metricOp === "max_precision") && colType === "Number") {
|
|
910
|
-
if (nonNull.length > 0) {
|
|
911
|
-
const decs = nonNull.map(v => Decimal.parse(v.value));
|
|
912
|
-
if (metricOp === "min" || metricOp === "max") {
|
|
913
|
-
let best = decs[0];
|
|
914
|
-
for (let k = 1; k < decs.length; k++) {
|
|
915
|
-
if (metricOp === "min" ? decs[k].compare(best) < 0 : decs[k].compare(best) > 0)
|
|
916
|
-
best = decs[k];
|
|
917
|
-
}
|
|
918
|
-
valStr = fmtDec(best);
|
|
919
|
-
}
|
|
920
|
-
else if (metricOp === "max_precision") {
|
|
921
|
-
let maxP = 0;
|
|
922
|
-
for (const d of decs) {
|
|
923
|
-
const norm = d.normalized();
|
|
924
|
-
if (!norm.special && -norm.exponent > maxP)
|
|
925
|
-
maxP = -norm.exponent;
|
|
926
|
-
}
|
|
927
|
-
valStr = fmtDec(Decimal.parse(String(maxP)));
|
|
928
|
-
}
|
|
929
|
-
else if (metricOp === "median") {
|
|
930
|
-
const sorted = [...decs].sort((a, b) => a.compare(b));
|
|
931
|
-
const mid = Math.floor(sorted.length / 2);
|
|
932
|
-
const med = sorted.length % 2 === 1
|
|
933
|
-
? sorted[mid]
|
|
934
|
-
: sorted[mid - 1].add(sorted[mid]).divide(Decimal.parse("2"));
|
|
935
|
-
valStr = fmtDec(med);
|
|
936
|
-
}
|
|
937
|
-
else if (metricOp === "stdev") {
|
|
938
|
-
if (decs.length >= 2) {
|
|
939
|
-
const nums = decs.map(d => Number(d.toString()));
|
|
940
|
-
if (nums.some(n => !Number.isFinite(n)))
|
|
941
|
-
return undefined;
|
|
942
|
-
const mean = nums.reduce((a, b) => a + b, 0) / nums.length;
|
|
943
|
-
const variance = nums.reduce((acc, n) => acc + (n - mean) * (n - mean), 0) / (nums.length - 1);
|
|
944
|
-
valStr = fmtDec(Decimal.parse(String(Math.sqrt(variance))));
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
else {
|
|
948
|
-
let sum = Decimal.parse("0");
|
|
949
|
-
for (const d of decs)
|
|
950
|
-
sum = sum.add(d);
|
|
951
|
-
valStr = fmtDec(metricOp === "sum" ? sum : sum.divide(Decimal.parse(String(decs.length))));
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
else {
|
|
956
|
-
return undefined;
|
|
957
|
-
}
|
|
958
|
-
out += (ids.length === 1 ? "" : `${String(id + 1).padStart(3)}. ${table.headers[id]}: `) + valStr + "\n";
|
|
959
|
-
}
|
|
960
|
-
return out;
|
|
961
|
-
}
|
|
962
|
-
catch {
|
|
963
|
-
return undefined;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
export function evalSyncIn2csv(inBytes, opArgs, readFileSync) {
|
|
967
|
-
try {
|
|
968
|
-
let formatSpec;
|
|
969
|
-
let keySpec;
|
|
970
|
-
let schemaSpec;
|
|
971
|
-
let sheetSpec;
|
|
972
|
-
let namesOnly = false;
|
|
973
|
-
const filteredArgs = [];
|
|
974
|
-
let posDone = false;
|
|
975
|
-
for (let i = 0; i < opArgs.length; i++) {
|
|
976
|
-
const a = opArgs[i];
|
|
977
|
-
if (!posDone && a === "--") {
|
|
978
|
-
posDone = true;
|
|
979
|
-
filteredArgs.push(a);
|
|
980
|
-
continue;
|
|
981
|
-
}
|
|
982
|
-
if (!posDone && a.startsWith("-") && a !== "-") {
|
|
983
|
-
if (a === "-n" || a === "--names") {
|
|
984
|
-
namesOnly = true;
|
|
985
|
-
continue;
|
|
986
|
-
}
|
|
987
|
-
if (a === "-f" || a.startsWith("-f") || a === "--format" || a.startsWith("--format=")) {
|
|
988
|
-
const v = a.startsWith("--format=") ? a.slice(9) : a.startsWith("-f=") ? a.slice(3) : a.length > 2 && a.startsWith("-f") ? a.slice(2) : opArgs[++i];
|
|
989
|
-
if (!v)
|
|
990
|
-
return undefined;
|
|
991
|
-
formatSpec = v.toLowerCase();
|
|
992
|
-
continue;
|
|
993
|
-
}
|
|
994
|
-
if (a === "-k" || a.startsWith("-k") || a === "--key" || a.startsWith("--key=")) {
|
|
995
|
-
const v = a.startsWith("--key=") ? a.slice(6) : a.startsWith("-k=") ? a.slice(3) : a.length > 2 && a.startsWith("-k") ? a.slice(2) : opArgs[++i];
|
|
996
|
-
if (!v)
|
|
997
|
-
return undefined;
|
|
998
|
-
keySpec = v;
|
|
999
|
-
continue;
|
|
1000
|
-
}
|
|
1001
|
-
if (a === "--sheet" || a.startsWith("--sheet=")) {
|
|
1002
|
-
const v = a.startsWith("--sheet=") ? a.slice(8) : opArgs[++i];
|
|
1003
|
-
if (!v)
|
|
1004
|
-
return undefined;
|
|
1005
|
-
sheetSpec = v;
|
|
1006
|
-
continue;
|
|
1007
|
-
}
|
|
1008
|
-
if (a === "-s" || a.startsWith("-s") || a === "--schema" || a.startsWith("--schema=")) {
|
|
1009
|
-
const v = a.startsWith("--schema=") ? a.slice(9) : a.startsWith("-s=") ? a.slice(3) : a.length > 2 && a.startsWith("-s") ? a.slice(2) : opArgs[++i];
|
|
1010
|
-
if (!v)
|
|
1011
|
-
return undefined;
|
|
1012
|
-
schemaSpec = v;
|
|
1013
|
-
continue;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
filteredArgs.push(a);
|
|
1017
|
-
}
|
|
1018
|
-
const opts = parseSyncCsvkitCommon(filteredArgs, "csvlook");
|
|
1019
|
-
if (!opts)
|
|
1020
|
-
return undefined;
|
|
1021
|
-
let sourceBytes = inBytes;
|
|
1022
|
-
if (opts.filePath !== undefined && opts.filePath !== "-") {
|
|
1023
|
-
if (!readFileSync)
|
|
1024
|
-
return undefined;
|
|
1025
|
-
sourceBytes = readFileSync(opts.filePath);
|
|
1026
|
-
}
|
|
1027
|
-
if (!sourceBytes || sourceBytes.byteLength > 16384)
|
|
1028
|
-
return undefined;
|
|
1029
|
-
let fmt = formatSpec;
|
|
1030
|
-
if (!fmt && opts.filePath && opts.filePath !== "-") {
|
|
1031
|
-
const lower = opts.filePath.toLowerCase();
|
|
1032
|
-
if (lower.endsWith(".geojson"))
|
|
1033
|
-
fmt = "geojson";
|
|
1034
|
-
else if (lower.endsWith(".xlsx"))
|
|
1035
|
-
fmt = "xlsx";
|
|
1036
|
-
else if (lower.endsWith(".json") || lower.endsWith(".js"))
|
|
1037
|
-
fmt = "json";
|
|
1038
|
-
else if (lower.endsWith(".ndjson") || lower.endsWith(".jsonl"))
|
|
1039
|
-
fmt = "ndjson";
|
|
1040
|
-
else if (lower.endsWith(".csv") || lower.endsWith(".tsv"))
|
|
1041
|
-
fmt = "csv";
|
|
1042
|
-
}
|
|
1043
|
-
if (!fmt && schemaSpec !== undefined)
|
|
1044
|
-
fmt = "fixed";
|
|
1045
|
-
if (!fmt && keySpec !== undefined)
|
|
1046
|
-
fmt = "json";
|
|
1047
|
-
if (fmt === "geojson") {
|
|
1048
|
-
if (namesOnly)
|
|
1049
|
-
return undefined;
|
|
1050
|
-
let text = syncUtf8Decoder.decode(sourceBytes);
|
|
1051
|
-
if (text.charCodeAt(0) === 0xfeff)
|
|
1052
|
-
text = text.slice(1);
|
|
1053
|
-
const doc = JSON.parse(text);
|
|
1054
|
-
if (!doc || typeof doc !== "object" || Array.isArray(doc) || doc.type !== "FeatureCollection" || !Array.isArray(doc.features)) {
|
|
1055
|
-
return undefined;
|
|
1056
|
-
}
|
|
1057
|
-
const propKeys = [];
|
|
1058
|
-
const seenProps = new Set();
|
|
1059
|
-
for (const feat of doc.features) {
|
|
1060
|
-
if (!feat || typeof feat !== "object" || Array.isArray(feat))
|
|
1061
|
-
return undefined;
|
|
1062
|
-
const props = feat.properties && typeof feat.properties === "object" && !Array.isArray(feat.properties) ? feat.properties : {};
|
|
1063
|
-
for (const k of Object.keys(props)) {
|
|
1064
|
-
if (!seenProps.has(k)) {
|
|
1065
|
-
seenProps.add(k);
|
|
1066
|
-
propKeys.push(k);
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1071
|
-
let out = writeCsvRow(["id", ...propKeys, "geojson", "type", "longitude", "latitude"], outDialect);
|
|
1072
|
-
for (const feat of doc.features) {
|
|
1073
|
-
const props = feat.properties && typeof feat.properties === "object" && !Array.isArray(feat.properties) ? feat.properties : {};
|
|
1074
|
-
const geom = feat.geometry && typeof feat.geometry === "object" && !Array.isArray(feat.geometry) ? feat.geometry : null;
|
|
1075
|
-
const gType = geom ? String(geom.type ?? "") : "";
|
|
1076
|
-
const coords = gType === "Point" && Array.isArray(geom?.coordinates) && geom.coordinates.length >= 2 ? geom.coordinates : undefined;
|
|
1077
|
-
const fmtVal = (v, isProp = false) => {
|
|
1078
|
-
if (v === undefined || v === null)
|
|
1079
|
-
return "";
|
|
1080
|
-
if (typeof v === "boolean")
|
|
1081
|
-
return v ? "True" : "False";
|
|
1082
|
-
if (typeof v === "object")
|
|
1083
|
-
return isProp ? JSON.stringify(v) : "";
|
|
1084
|
-
return String(v);
|
|
1085
|
-
};
|
|
1086
|
-
const geomJson = JSON.stringify(geom).replace(/":/g, '": ').replace(/,"/g, ', "');
|
|
1087
|
-
const rowCells = [
|
|
1088
|
-
fmtVal(feat.id),
|
|
1089
|
-
...propKeys.map((k) => fmtVal(props[k], true)),
|
|
1090
|
-
geomJson,
|
|
1091
|
-
gType,
|
|
1092
|
-
coords ? fmtVal(coords[0]) : "",
|
|
1093
|
-
coords ? fmtVal(coords[1]) : "",
|
|
1094
|
-
];
|
|
1095
|
-
out += writeCsvRow(rowCells, outDialect);
|
|
1096
|
-
}
|
|
1097
|
-
return out;
|
|
1098
|
-
}
|
|
1099
|
-
if (fmt === "xlsx") {
|
|
1100
|
-
if (sourceBytes[0] !== 80 || sourceBytes[1] !== 75)
|
|
1101
|
-
return undefined;
|
|
1102
|
-
const entries = readZipArchiveEntries(sourceBytes);
|
|
1103
|
-
if (entries.has("EncryptionInfo") || entries.has("EncryptedPackage"))
|
|
1104
|
-
return undefined;
|
|
1105
|
-
const wbXmlBytes = entries.get("xl/workbook.xml");
|
|
1106
|
-
if (!wbXmlBytes)
|
|
1107
|
-
return undefined;
|
|
1108
|
-
const wbXml = syncUtf8Decoder.decode(wbXmlBytes);
|
|
1109
|
-
const sheetNames = [];
|
|
1110
|
-
for (const m of wbXml.matchAll(/<sheet\b[^>]*\bname="([^"]+)"/g)) {
|
|
1111
|
-
sheetNames.push(m[1]);
|
|
1112
|
-
}
|
|
1113
|
-
if (sheetNames.length === 0)
|
|
1114
|
-
return undefined;
|
|
1115
|
-
if (namesOnly) {
|
|
1116
|
-
return sheetNames.map((n) => n + "\n").join("");
|
|
1117
|
-
}
|
|
1118
|
-
const targetIdx = sheetSpec ? sheetNames.indexOf(sheetSpec) : 0;
|
|
1119
|
-
if (targetIdx < 0)
|
|
1120
|
-
return undefined;
|
|
1121
|
-
const sheetBytes = entries.get(`xl/worksheets/sheet${targetIdx + 1}.xml`);
|
|
1122
|
-
if (!sheetBytes)
|
|
1123
|
-
return undefined;
|
|
1124
|
-
const sheetXml = syncUtf8Decoder.decode(sheetBytes);
|
|
1125
|
-
if (/<f(?:\s|>)/u.test(sheetXml))
|
|
1126
|
-
return undefined;
|
|
1127
|
-
const sharedStrings = [];
|
|
1128
|
-
const sstBytes = entries.get("xl/sharedStrings.xml");
|
|
1129
|
-
if (sstBytes) {
|
|
1130
|
-
const sstXml = syncUtf8Decoder.decode(sstBytes);
|
|
1131
|
-
for (const si of sstXml.matchAll(/<si\b[\s\S]*?<\/si>/g)) {
|
|
1132
|
-
const parts = [...si[0].matchAll(/<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/g)].map((t) => (t[1] ?? "").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&"));
|
|
1133
|
-
sharedStrings.push(parts.join(""));
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
const csvRows = [];
|
|
1137
|
-
for (const rm of sheetXml.matchAll(/<row\b[\s\S]*?<\/row>/g)) {
|
|
1138
|
-
const cells = [];
|
|
1139
|
-
for (const cm of rm[0].matchAll(/<c\b([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/g)) {
|
|
1140
|
-
const attrs = cm[1] ?? "";
|
|
1141
|
-
const body = cm[2] ?? "";
|
|
1142
|
-
const refM = /\br="([A-Z]+)\d+"/i.exec(attrs);
|
|
1143
|
-
if (refM?.[1]) {
|
|
1144
|
-
let col = 0;
|
|
1145
|
-
for (const ch of refM[1].toUpperCase())
|
|
1146
|
-
col = col * 26 + (ch.charCodeAt(0) - 64);
|
|
1147
|
-
col -= 1;
|
|
1148
|
-
while (cells.length < col)
|
|
1149
|
-
cells.push("");
|
|
1150
|
-
}
|
|
1151
|
-
if (cm[2] === undefined) {
|
|
1152
|
-
cells.push("");
|
|
1153
|
-
continue;
|
|
1154
|
-
}
|
|
1155
|
-
const tM = /\bt="([^"]+)"/.exec(attrs);
|
|
1156
|
-
const cType = tM?.[1] ?? "n";
|
|
1157
|
-
if (cType === "inlineStr") {
|
|
1158
|
-
const tv = /<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/.exec(body);
|
|
1159
|
-
cells.push((tv?.[1] ?? "").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&"));
|
|
1160
|
-
}
|
|
1161
|
-
else {
|
|
1162
|
-
const vv = /<v>([\s\S]*?)<\/v>/.exec(body);
|
|
1163
|
-
const raw = (vv?.[1] ?? "").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
1164
|
-
cells.push(cType === "s" ? (sharedStrings[Number.parseInt(raw, 10)] ?? "") : raw);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
csvRows.push(cells);
|
|
1168
|
-
}
|
|
1169
|
-
const synthDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1170
|
-
const synthCsv = csvRows.map((r) => writeCsvRow(r, synthDialect)).join("");
|
|
1171
|
-
const synthBytes = new TextEncoder().encode(synthCsv);
|
|
1172
|
-
const table = loadSyncTypedTable(synthBytes, { ...opts, filePath: "-" }, undefined);
|
|
1173
|
-
if (!table)
|
|
1174
|
-
return undefined;
|
|
1175
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
1176
|
-
out += writeCsvRow(table.headers, synthDialect);
|
|
1177
|
-
for (const row of table.rows) {
|
|
1178
|
-
out += writeCsvRow(row.map((v) => (v === null ? "" : typeof v === "object" && v.kind === "datetime" ? v.value.replace(" ", "T") : pythonValueText(v))), synthDialect);
|
|
1179
|
-
}
|
|
1180
|
-
return out;
|
|
1181
|
-
}
|
|
1182
|
-
if (fmt === "fixed") {
|
|
1183
|
-
if (!schemaSpec || !readFileSync)
|
|
1184
|
-
return undefined;
|
|
1185
|
-
const schemaBytes = readFileSync(schemaSpec);
|
|
1186
|
-
if (!schemaBytes || schemaBytes.byteLength > 16384)
|
|
1187
|
-
return undefined;
|
|
1188
|
-
let schemaText = syncUtf8Decoder.decode(schemaBytes);
|
|
1189
|
-
if (schemaText.charCodeAt(0) === 0xfeff)
|
|
1190
|
-
schemaText = schemaText.slice(1);
|
|
1191
|
-
const schemaRows = Array.from(readCsv(schemaText, { delimiter: ",", quotechar: "\"", doublequote: true }), record => record.cells);
|
|
1192
|
-
if (schemaRows.length < 2)
|
|
1193
|
-
return undefined;
|
|
1194
|
-
const sHead = schemaRows[0];
|
|
1195
|
-
const colIdx = sHead.indexOf("column");
|
|
1196
|
-
const startIdx = sHead.indexOf("start");
|
|
1197
|
-
const lenIdx = sHead.indexOf("length");
|
|
1198
|
-
if (colIdx < 0 || startIdx < 0 || lenIdx < 0)
|
|
1199
|
-
return undefined;
|
|
1200
|
-
let oneBased;
|
|
1201
|
-
const fields = [];
|
|
1202
|
-
for (let r = 1; r < schemaRows.length; r++) {
|
|
1203
|
-
const row = schemaRows[r];
|
|
1204
|
-
if (row.length === 0 || (row.length === 1 && row[0] === ""))
|
|
1205
|
-
continue;
|
|
1206
|
-
const stNum = Number(row[startIdx]);
|
|
1207
|
-
const lnNum = Number(row[lenIdx]);
|
|
1208
|
-
if (!Number.isSafeInteger(stNum) || !Number.isSafeInteger(lnNum) || stNum < 0 || lnNum < 0)
|
|
1209
|
-
return undefined;
|
|
1210
|
-
oneBased ??= stNum === 1;
|
|
1211
|
-
fields.push({ name: row[colIdx], start: stNum - (oneBased ? 1 : 0), length: lnNum });
|
|
1212
|
-
}
|
|
1213
|
-
let inText = syncUtf8Decoder.decode(sourceBytes);
|
|
1214
|
-
if (inText.charCodeAt(0) === 0xfeff)
|
|
1215
|
-
inText = inText.slice(1);
|
|
1216
|
-
const rawLines = inText.split(/\r?\n/);
|
|
1217
|
-
if (rawLines.length > 0 && rawLines[rawLines.length - 1] === "")
|
|
1218
|
-
rawLines.pop();
|
|
1219
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1220
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
1221
|
-
out += writeCsvRow(fields.map(f => f.name), outDialect);
|
|
1222
|
-
for (let idx = opts.skipLines; idx < rawLines.length; idx++) {
|
|
1223
|
-
const chars = Array.from(rawLines[idx]);
|
|
1224
|
-
const cells = fields.map(f => chars.slice(f.start, f.start + f.length).join("").trim());
|
|
1225
|
-
out += writeCsvRow(cells, outDialect);
|
|
1226
|
-
}
|
|
1227
|
-
return out;
|
|
1228
|
-
}
|
|
1229
|
-
if (namesOnly) {
|
|
1230
|
-
if (fmt !== "json")
|
|
1231
|
-
return undefined;
|
|
1232
|
-
let text = syncUtf8Decoder.decode(sourceBytes);
|
|
1233
|
-
if (text.charCodeAt(0) === 0xfeff)
|
|
1234
|
-
text = text.slice(1);
|
|
1235
|
-
const root = JSON.parse(text);
|
|
1236
|
-
if (!root || typeof root !== "object" || Array.isArray(root))
|
|
1237
|
-
return undefined;
|
|
1238
|
-
return Object.keys(root).map(k => k + "\n").join("");
|
|
1239
|
-
}
|
|
1240
|
-
if (fmt === "csv") {
|
|
1241
|
-
const table = loadSyncTypedTable(inBytes, opts, readFileSync);
|
|
1242
|
-
if (!table)
|
|
1243
|
-
return undefined;
|
|
1244
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1245
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
1246
|
-
out += writeCsvRow(table.headers, outDialect);
|
|
1247
|
-
for (const row of table.rows) {
|
|
1248
|
-
out += writeCsvRow(row.map(v => (v === null ? "" : typeof v === "object" && v.kind === "datetime" ? v.value.replace(" ", "T") : pythonValueText(v))), outDialect);
|
|
1249
|
-
}
|
|
1250
|
-
return out;
|
|
1251
|
-
}
|
|
1252
|
-
if (fmt !== "json" && fmt !== "ndjson")
|
|
1253
|
-
return undefined;
|
|
1254
|
-
if (fmt === "ndjson" && keySpec !== undefined)
|
|
1255
|
-
return undefined;
|
|
1256
|
-
let text = syncUtf8Decoder.decode(sourceBytes);
|
|
1257
|
-
if (text.charCodeAt(0) === 0xfeff)
|
|
1258
|
-
text = text.slice(1);
|
|
1259
|
-
let parsedItems;
|
|
1260
|
-
if (fmt === "ndjson") {
|
|
1261
|
-
parsedItems = [];
|
|
1262
|
-
for (const line of text.split(/\r?\n/)) {
|
|
1263
|
-
const trimmed = line.trim();
|
|
1264
|
-
if (!trimmed)
|
|
1265
|
-
continue;
|
|
1266
|
-
parsedItems.push(JSON.parse(trimmed));
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
else {
|
|
1270
|
-
let root = JSON.parse(text);
|
|
1271
|
-
if (root && typeof root === "object" && !Array.isArray(root)) {
|
|
1272
|
-
if (!keySpec || !(keySpec in root))
|
|
1273
|
-
return undefined;
|
|
1274
|
-
root = root[keySpec];
|
|
1275
|
-
}
|
|
1276
|
-
if (!Array.isArray(root))
|
|
1277
|
-
return undefined;
|
|
1278
|
-
parsedItems = root;
|
|
1279
|
-
}
|
|
1280
|
-
const headers = [];
|
|
1281
|
-
const known = new Set();
|
|
1282
|
-
const rawMaps = [];
|
|
1283
|
-
const flatten = (val, path, row) => {
|
|
1284
|
-
if (val !== null && typeof val === "object") {
|
|
1285
|
-
if (Array.isArray(val)) {
|
|
1286
|
-
for (let idx = 0; idx < val.length; idx++)
|
|
1287
|
-
flatten(val[idx], path + String(idx) + "/", row);
|
|
1288
|
-
}
|
|
1289
|
-
else {
|
|
1290
|
-
for (const [k, child] of Object.entries(val))
|
|
1291
|
-
flatten(child, path + k + "/", row);
|
|
1292
|
-
}
|
|
1293
|
-
return;
|
|
1294
|
-
}
|
|
1295
|
-
let start = 0;
|
|
1296
|
-
let end = path.length;
|
|
1297
|
-
while (path[start] === "/")
|
|
1298
|
-
start++;
|
|
1299
|
-
while (end > start && path[end - 1] === "/")
|
|
1300
|
-
end--;
|
|
1301
|
-
const name = path.slice(start, end);
|
|
1302
|
-
if (!name)
|
|
1303
|
-
throw new Error("empty header");
|
|
1304
|
-
const cell = val === null || val === undefined ? null : typeof val === "boolean" ? (val ? "True" : "False") : String(val);
|
|
1305
|
-
row.set(name, cell);
|
|
1306
|
-
};
|
|
1307
|
-
for (const item of parsedItems) {
|
|
1308
|
-
if (item === null || typeof item !== "object" || Array.isArray(item))
|
|
1309
|
-
return undefined;
|
|
1310
|
-
const row = new Map();
|
|
1311
|
-
flatten(item, "", row);
|
|
1312
|
-
for (const name of row.keys()) {
|
|
1313
|
-
if (!known.has(name)) {
|
|
1314
|
-
known.add(name);
|
|
1315
|
-
headers.push(name);
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
rawMaps.push(row);
|
|
1319
|
-
}
|
|
1320
|
-
if (headers.length === 0)
|
|
1321
|
-
return undefined;
|
|
1322
|
-
const stringRows = rawMaps.map((m, rIdx) => {
|
|
1323
|
-
const cells = headers.map(h => m.get(h) ?? "");
|
|
1324
|
-
return opts.lineNumbers ? [String(rIdx + 1), ...cells] : cells;
|
|
1325
|
-
});
|
|
1326
|
-
const finalHeaders = opts.lineNumbers ? ["line_number", ...headers] : headers;
|
|
1327
|
-
const inferenceOpts = {
|
|
1328
|
-
now: Date.now(),
|
|
1329
|
-
timezone: "UTC",
|
|
1330
|
-
noInference: opts.noInference,
|
|
1331
|
-
numberTextOnly: false,
|
|
1332
|
-
blanks: opts.blanks,
|
|
1333
|
-
nullValues: [],
|
|
1334
|
-
noLeadingZeroes: opts.noLeadingZeroes,
|
|
1335
|
-
maxDecimalDigits: Infinity,
|
|
1336
|
-
maxDecimalExponent: Infinity,
|
|
1337
|
-
};
|
|
1338
|
-
const table = inferTable(finalHeaders, stringRows, inferenceOpts);
|
|
1339
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1340
|
-
let out = opts.addBom ? "\ufeff" : "";
|
|
1341
|
-
out += writeCsvRow(table.headers, outDialect);
|
|
1342
|
-
for (const row of table.rows) {
|
|
1343
|
-
out += writeCsvRow(row.map(v => (v === null ? "" : typeof v === "object" && v.kind === "datetime" ? v.value.replace(" ", "T") : pythonValueText(v))), outDialect);
|
|
1344
|
-
}
|
|
1345
|
-
return out;
|
|
1346
|
-
}
|
|
1347
|
-
catch {
|
|
1348
|
-
return undefined;
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
export function evalSyncCsvstack(inBytes, opArgs, readFileSync) {
|
|
1352
|
-
try {
|
|
1353
|
-
let groupsSpec;
|
|
1354
|
-
let groupName = "group";
|
|
1355
|
-
let groupByFilenames = false;
|
|
1356
|
-
let noHeaderRow = false;
|
|
1357
|
-
let lineNumbers = false;
|
|
1358
|
-
let addBom = false;
|
|
1359
|
-
let delimiter = ",";
|
|
1360
|
-
let tabs = false;
|
|
1361
|
-
const files = [];
|
|
1362
|
-
let posDone = false;
|
|
1363
|
-
for (let i = 0; i < opArgs.length; i++) {
|
|
1364
|
-
const a = opArgs[i];
|
|
1365
|
-
if (!posDone && a === "--") {
|
|
1366
|
-
posDone = true;
|
|
1367
|
-
continue;
|
|
1368
|
-
}
|
|
1369
|
-
if (!posDone && a.startsWith("-") && a !== "-") {
|
|
1370
|
-
if (a === "-H" || a === "--no-header-row") {
|
|
1371
|
-
noHeaderRow = true;
|
|
1372
|
-
continue;
|
|
1373
|
-
}
|
|
1374
|
-
if (a === "-l" || a === "--linenumbers") {
|
|
1375
|
-
lineNumbers = true;
|
|
1376
|
-
continue;
|
|
1377
|
-
}
|
|
1378
|
-
if (a === "--add-bom") {
|
|
1379
|
-
addBom = true;
|
|
1380
|
-
continue;
|
|
1381
|
-
}
|
|
1382
|
-
if (a === "-t" || a === "--tabs") {
|
|
1383
|
-
tabs = true;
|
|
1384
|
-
continue;
|
|
1385
|
-
}
|
|
1386
|
-
if (a === "-d" || a === "--delimiter" || a.startsWith("--delimiter=")) {
|
|
1387
|
-
const v = a.startsWith("--delimiter=") ? a.slice(12) : opArgs[++i];
|
|
1388
|
-
if (!v || Array.from(v).length !== 1)
|
|
1389
|
-
return undefined;
|
|
1390
|
-
delimiter = v;
|
|
1391
|
-
continue;
|
|
1392
|
-
}
|
|
1393
|
-
if (a === "--filenames") {
|
|
1394
|
-
groupByFilenames = true;
|
|
1395
|
-
continue;
|
|
1396
|
-
}
|
|
1397
|
-
if (a === "-g" || a === "--groups") {
|
|
1398
|
-
const v = opArgs[++i];
|
|
1399
|
-
if (v === undefined)
|
|
1400
|
-
return undefined;
|
|
1401
|
-
groupsSpec = v;
|
|
1402
|
-
continue;
|
|
1403
|
-
}
|
|
1404
|
-
if (a === "-n" || a === "--group-name") {
|
|
1405
|
-
const v = opArgs[++i];
|
|
1406
|
-
if (v === undefined)
|
|
1407
|
-
return undefined;
|
|
1408
|
-
groupName = v;
|
|
1409
|
-
continue;
|
|
1410
|
-
}
|
|
1411
|
-
return undefined;
|
|
1412
|
-
}
|
|
1413
|
-
files.push(a);
|
|
1414
|
-
}
|
|
1415
|
-
if (files.length === 0)
|
|
1416
|
-
files.push("-");
|
|
1417
|
-
if (noHeaderRow)
|
|
1418
|
-
return undefined;
|
|
1419
|
-
const groups = groupsSpec !== undefined && !groupByFilenames ? groupsSpec.split(",") : undefined;
|
|
1420
|
-
if (groups && groups.length !== files.length)
|
|
1421
|
-
return undefined;
|
|
1422
|
-
const grouped = groupsSpec !== undefined || groupByFilenames;
|
|
1423
|
-
const parsedFiles = [];
|
|
1424
|
-
const unionHeaders = [];
|
|
1425
|
-
const seen = new Set();
|
|
1426
|
-
for (let idx = 0; idx < files.length; idx++) {
|
|
1427
|
-
const f = files[idx];
|
|
1428
|
-
const bytes = f === "-" ? inBytes : readFileSync ? readFileSync(f) : undefined;
|
|
1429
|
-
if (!bytes || bytes.byteLength > 16384)
|
|
1430
|
-
return undefined;
|
|
1431
|
-
let text = syncUtf8Decoder.decode(bytes);
|
|
1432
|
-
if (text.charCodeAt(0) === 0xfeff)
|
|
1433
|
-
text = text.slice(1);
|
|
1434
|
-
const recs = [...readCsv(text, { delimiter: tabs ? "\t" : delimiter, quotechar: "\"", doublequote: true, skipinitialspace: false })];
|
|
1435
|
-
const hdr = recs[0] ? recs[0].cells.map(c => pythonValueText(c)) : [];
|
|
1436
|
-
for (const h of hdr) {
|
|
1437
|
-
if (!seen.has(h)) {
|
|
1438
|
-
seen.add(h);
|
|
1439
|
-
unionHeaders.push(h);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
const groupVal = groups ? groups[idx] : f.split("/").at(-1);
|
|
1443
|
-
parsedFiles.push({
|
|
1444
|
-
group: groupVal,
|
|
1445
|
-
headers: hdr,
|
|
1446
|
-
rows: recs.slice(1).map(r => r.cells.map(c => pythonValueText(c))),
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
const outHeaders = grouped ? [groupName, ...unionHeaders] : [...unionHeaders];
|
|
1450
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1451
|
-
let out = addBom ? "\ufeff" : "";
|
|
1452
|
-
out += writeCsvRow(lineNumbers ? ["line_number", ...outHeaders] : outHeaders, outDialect);
|
|
1453
|
-
let lineNum = 1;
|
|
1454
|
-
for (const pf of parsedFiles) {
|
|
1455
|
-
for (const r of pf.rows) {
|
|
1456
|
-
const rowMap = new Map();
|
|
1457
|
-
for (let c = 0; c < pf.headers.length; c++)
|
|
1458
|
-
rowMap.set(pf.headers[c], r[c] ?? "");
|
|
1459
|
-
const cells = unionHeaders.map(h => rowMap.get(h) ?? "");
|
|
1460
|
-
if (grouped)
|
|
1461
|
-
cells.unshift(pf.group);
|
|
1462
|
-
if (lineNumbers)
|
|
1463
|
-
cells.unshift(String(lineNum++));
|
|
1464
|
-
out += writeCsvRow(cells, outDialect);
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
return out;
|
|
1468
|
-
}
|
|
1469
|
-
catch {
|
|
1470
|
-
return undefined;
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
export function evalSyncCsvjoin(inBytes, opArgs, readFileSync) {
|
|
1474
|
-
try {
|
|
1475
|
-
let columnsSpec;
|
|
1476
|
-
let joinMode = "inner";
|
|
1477
|
-
let noInference = false;
|
|
1478
|
-
let addBom = false;
|
|
1479
|
-
let delimiter;
|
|
1480
|
-
let tabs = false;
|
|
1481
|
-
const files = [];
|
|
1482
|
-
let posDone = false;
|
|
1483
|
-
for (let i = 0; i < opArgs.length; i++) {
|
|
1484
|
-
const a = opArgs[i];
|
|
1485
|
-
if (!posDone && a === "--") {
|
|
1486
|
-
posDone = true;
|
|
1487
|
-
continue;
|
|
1488
|
-
}
|
|
1489
|
-
if (!posDone && a.startsWith("-") && a !== "-") {
|
|
1490
|
-
if (a === "--left") {
|
|
1491
|
-
joinMode = "left";
|
|
1492
|
-
continue;
|
|
1493
|
-
}
|
|
1494
|
-
if (a === "--right") {
|
|
1495
|
-
joinMode = "right";
|
|
1496
|
-
continue;
|
|
1497
|
-
}
|
|
1498
|
-
if (a === "--outer") {
|
|
1499
|
-
joinMode = "outer";
|
|
1500
|
-
continue;
|
|
1501
|
-
}
|
|
1502
|
-
if (a === "-I" || a === "--no-inference") {
|
|
1503
|
-
noInference = true;
|
|
1504
|
-
continue;
|
|
1505
|
-
}
|
|
1506
|
-
if (a === "--add-bom") {
|
|
1507
|
-
addBom = true;
|
|
1508
|
-
continue;
|
|
1509
|
-
}
|
|
1510
|
-
if (a === "-t" || a === "--tabs") {
|
|
1511
|
-
tabs = true;
|
|
1512
|
-
continue;
|
|
1513
|
-
}
|
|
1514
|
-
if (a === "-d" || a === "--delimiter" || a.startsWith("--delimiter=")) {
|
|
1515
|
-
const v = a.startsWith("--delimiter=") ? a.slice(12) : opArgs[++i];
|
|
1516
|
-
if (!v || Array.from(v).length !== 1)
|
|
1517
|
-
return undefined;
|
|
1518
|
-
delimiter = v;
|
|
1519
|
-
continue;
|
|
1520
|
-
}
|
|
1521
|
-
if (a === "-c" || a === "--columns") {
|
|
1522
|
-
const v = opArgs[++i];
|
|
1523
|
-
if (v === undefined)
|
|
1524
|
-
return undefined;
|
|
1525
|
-
columnsSpec = v;
|
|
1526
|
-
continue;
|
|
1527
|
-
}
|
|
1528
|
-
return undefined;
|
|
1529
|
-
}
|
|
1530
|
-
files.push(a);
|
|
1531
|
-
}
|
|
1532
|
-
if (files.length !== 2)
|
|
1533
|
-
return undefined;
|
|
1534
|
-
const leftOpts = {
|
|
1535
|
-
...(delimiter === undefined ? {} : { delimiter }), tabs, noDoublequote: false, skipInitialSpace: false, noHeaderRow: false,
|
|
1536
|
-
skipLines: 0, lineNumbers: false, addBom: false, noInference, blanks: false,
|
|
1537
|
-
noLeadingZeroes: false, sniffLimit: 1024, noNumberEllipsis: false,
|
|
1538
|
-
indent: null, key: null, streamOutput: false, filePath: files[0],
|
|
1539
|
-
};
|
|
1540
|
-
const rightOpts = { ...leftOpts, filePath: files[1] };
|
|
1541
|
-
const leftTable = loadSyncTypedTable(inBytes, leftOpts, readFileSync);
|
|
1542
|
-
const rightTable = loadSyncTypedTable(inBytes, rightOpts, readFileSync);
|
|
1543
|
-
if (!leftTable || !rightTable)
|
|
1544
|
-
return undefined;
|
|
1545
|
-
if (!columnsSpec) {
|
|
1546
|
-
if (joinMode !== "inner")
|
|
1547
|
-
return undefined;
|
|
1548
|
-
const outHeaders = [
|
|
1549
|
-
...leftTable.headers,
|
|
1550
|
-
...rightTable.headers.map(h => (leftTable.headers.includes(h) ? h + "2" : h)),
|
|
1551
|
-
];
|
|
1552
|
-
if (new Set(outHeaders).size !== outHeaders.length)
|
|
1553
|
-
return undefined;
|
|
1554
|
-
const maxRows = Math.max(leftTable.rows.length, rightTable.rows.length);
|
|
1555
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1556
|
-
let out = addBom ? "\ufeff" : "";
|
|
1557
|
-
out += writeCsvRow(outHeaders, outDialect);
|
|
1558
|
-
for (let r = 0; r < maxRows; r++) {
|
|
1559
|
-
const lRow = leftTable.rows[r] ?? leftTable.headers.map(() => null);
|
|
1560
|
-
const rRow = rightTable.rows[r] ?? rightTable.headers.map(() => null);
|
|
1561
|
-
out += writeCsvRow([...lRow, ...rRow].map(v => (v === null ? "" : typeof v === "object" && v.kind === "datetime" ? v.value.replace(" ", "T") : pythonValueText(v))), outDialect);
|
|
1562
|
-
}
|
|
1563
|
-
return out;
|
|
1564
|
-
}
|
|
1565
|
-
const colParts = columnsSpec.split(",");
|
|
1566
|
-
if (colParts.length !== 1 && colParts.length !== 2)
|
|
1567
|
-
return undefined;
|
|
1568
|
-
const leftKey = matchColumnIdentifier(leftTable.headers, colParts[0], 1);
|
|
1569
|
-
const rightKey = matchColumnIdentifier(rightTable.headers, colParts[1] ?? colParts[0], 1);
|
|
1570
|
-
const full = joinMode === "outer" || joinMode === "right";
|
|
1571
|
-
const inner = joinMode === "inner";
|
|
1572
|
-
const keyVal = (v) => {
|
|
1573
|
-
if (v === null)
|
|
1574
|
-
return "null";
|
|
1575
|
-
if (typeof v === "string")
|
|
1576
|
-
return "text:" + v;
|
|
1577
|
-
if (typeof v === "boolean")
|
|
1578
|
-
return v ? "number:1:0" : "number:0";
|
|
1579
|
-
if (v.kind === "decimal") {
|
|
1580
|
-
const d = Decimal.parse(v.value).normalized();
|
|
1581
|
-
return "number:" + d.toString();
|
|
1582
|
-
}
|
|
1583
|
-
return "other:" + pythonValueText(v);
|
|
1584
|
-
};
|
|
1585
|
-
const includedRight = rightTable.headers.map((_, idx) => idx).filter(idx => full || idx !== rightKey);
|
|
1586
|
-
const outHeaders = [
|
|
1587
|
-
...leftTable.headers,
|
|
1588
|
-
...includedRight.map(idx => (leftTable.headers.includes(rightTable.headers[idx]) ? rightTable.headers[idx] + "2" : rightTable.headers[idx])),
|
|
1589
|
-
];
|
|
1590
|
-
if (new Set(outHeaders).size !== outHeaders.length)
|
|
1591
|
-
return undefined;
|
|
1592
|
-
const rightHash = new Map();
|
|
1593
|
-
const rightKeys = [];
|
|
1594
|
-
for (const row of rightTable.rows) {
|
|
1595
|
-
const k = keyVal(row[rightKey]);
|
|
1596
|
-
rightKeys.push(k);
|
|
1597
|
-
const list = rightHash.get(k);
|
|
1598
|
-
if (list)
|
|
1599
|
-
list.push(row);
|
|
1600
|
-
else
|
|
1601
|
-
rightHash.set(k, [row]);
|
|
1602
|
-
}
|
|
1603
|
-
const joinedRows = [];
|
|
1604
|
-
const seenKeys = new Set();
|
|
1605
|
-
for (const lRow of leftTable.rows) {
|
|
1606
|
-
const k = keyVal(lRow[leftKey]);
|
|
1607
|
-
const matches = k === "null" ? undefined : rightHash.get(k);
|
|
1608
|
-
if (matches) {
|
|
1609
|
-
seenKeys.add(k);
|
|
1610
|
-
for (const rRow of matches) {
|
|
1611
|
-
joinedRows.push([...lRow, ...includedRight.map(idx => rRow[idx])]);
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
else if (!inner && joinMode !== "right") {
|
|
1615
|
-
joinedRows.push([...lRow, ...includedRight.map(() => null)]);
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
if (full) {
|
|
1619
|
-
for (let i = 0; i < rightTable.rows.length; i++) {
|
|
1620
|
-
const k = rightKeys[i];
|
|
1621
|
-
if (k === "null" || !seenKeys.has(k)) {
|
|
1622
|
-
const rRow = rightTable.rows[i];
|
|
1623
|
-
joinedRows.push([...leftTable.headers.map(() => null), ...includedRight.map(idx => rRow[idx])]);
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
const outDialect = { delimiter: ",", quotechar: "\"", doublequote: true, lineterminator: "\n" };
|
|
1628
|
-
let out = addBom ? "\ufeff" : "";
|
|
1629
|
-
out += writeCsvRow(outHeaders, outDialect);
|
|
1630
|
-
for (const row of joinedRows) {
|
|
1631
|
-
out += writeCsvRow(row.map(v => (v === null ? "" : typeof v === "object" && v.kind === "datetime" ? v.value.replace(" ", "T") : pythonValueText(v))), outDialect);
|
|
1632
|
-
}
|
|
1633
|
-
return out;
|
|
1634
|
-
}
|
|
1635
|
-
catch {
|
|
1636
|
-
return undefined;
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
//# sourceMappingURL=sync.js.map
|