1import{m as w,a as $,p as i,r as k,b as M,u as _,i as v}from"./harness-CiOCBEeI.js";import"./vite-preload-ckwbz45p.js";import"./util-CkZ8KZK2.js";import"./csvShared-8k83eY5V.js";import"./vendor-papaparse-Btpkh8vH.js";import"./cjs-helpers-D6-XlEtG.js";import"./detectTableRegion-B60ufQHb.js";function C(t,a){const l=[...t.source.matchAll(/\(\?<([A-Za-z_][A-Za-z0-9_]*)>/g)].map(d=>d[1]);return Array.from({length:a},(d,r)=>l[r]??String(r+1))}function A(t,a){let l;try{l=new RegExp(a.pattern,`g${a.caseSensitive?"":"i"}`)}catch(m){throw new Error(`That is not a valid regular expression: ${m instanceof Error?m.message:"check the pattern"}.`)}const d=new RegExp(`${l.source}|`).exec(""),r=Math.max(0,((d==null?void 0:d.length)??1)-1),s=[];let u=0,f=0,o=0;for(const m of t){l.lastIndex=0;const e=[];if(a.allMatches)for(const n of m.matchAll(l)){if(r===0)e.push(n[0]??"");else for(let c=1;c<=r;c+=1)e.push(n[c]??"");if(e.length>=a.maxColumns)break}else{const n=l.exec(m);if(n)if(r===0)e.push(n[0]??"");else for(let c=1;c<=r;c+=1)e.push(n[c]??"")}e.length>0?u+=1:f+=1,o=Math.max(o,e.length),s.push(e)}o=Math.min(Math.max(o,1),a.maxColumns);const h=r===0?["match"]:C(l,r),p=Array.from({length:o},(m,e)=>a.allMatches&&o>h.length?`${h[e%h.length]}_${Math.floor(e/h.length)+1}`:h[e]??String(e+1));return{columns:Array.from({length:o},(m,e)=>s.map(n=>n[e]??"")),names:p,matched:u,unmatched:f}}function E(t){const a=$(t.options.column,t.header),l=t.header.indexOf(a),d=(t.options.pattern??"").trim();if(l<0||d==="")return{header:t.header,body:t.body,summary:[i(t.body.length,"row"),"no pattern yet"],warnings:["Type a regular expression above. Put brackets around each piece you want in a column of its own, for example (\\d{4})-(\\d{2}) to pull a year and a month out of a reference."],selected:{column:a}};const r={pattern:d,caseSensitive:t.options.caseSensitive!=="off",allMatches:t.options.matches==="all",maxColumns:Math.max(1,Math.min(50,k(t.options.maxColumns,12)))},s=A(t.body.map(e=>e[l]??""),r),u=M(t.options.keep,!0),f=(t.options.names??"").split(",").map(e=>e.trim()).filter(e=>e!=="");let o=t.header,h=t.body;const p=[...t.header];if(s.columns.forEach((e,n)=>{const c=f[n]??`${a}_${s.names[n]}`,g=_(c,p);p.push(g);const b=o.indexOf(a)+1+n,y=v(o,h,b,g,e);o=y.header,h=y.body}),!u){const e=o.indexOf(a);o=o.filter((n,c)=>c!==e),h=h.map(n=>n.filter((c,g)=>g!==e))}const x=[i(t.body.length,"row"),`extracted from "${a}"`,`/${r.pattern}/${r.caseSensitive?"":"i"}`,`${i(s.columns.length,"new column")}`,`${i(s.matched,"row")} matched`,...s.unmatched>0?[`${i(s.unmatched,"row")} did not match`]:[],u?"original kept":"original removed"],m=[];if(s.unmatched>0){const e=Math.round(s.unmatched/Math.max(1,t.body.length)*100);m.push(`${i(s.unmatched,"row")} (${e}%) did not match the pattern, so their new cells are blank. Check the pattern against one of those values before you rely on this file.`)}return s.matched===0&&m.push("Nothing matched at all. Remember that the pattern is a regular expression: a dot matches any character, and characters like ( ) [ ] + ? need a backslash in front of them to be taken literally."),{header:o,body:h,summary:x,warnings:m,selected:{column:a}}}const Z=w("extracted",E);export{Z as default,C as groupNames,A as runExtract};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.