1import{a as J,r as T,j as r,B as y}from"./index-ns1xYkE3.js";import{T as v}from"./ToolContent-CAEuGU2l.js";import{T as g}from"./ToolTextInput-DfyWQL6-.js";import{T as L}from"./ToolTextResult-Cvq523nC.js";import{C as u}from"./CheckboxWithDesc-BcbjlaHI.js";import{T as d}from"./TextFieldWithDesc-C7cjd3t6.js";import"./TextField-C2-ggeEL.js";import"./ContentPaste-BtIU-5c9.js";import"./InputFooter-DxcfFvIG.js";import"./ResultFooter-D3pWGvfO.js";import"./index-D0txp6_X.js";import"./FormControlLabel-Dq83jjDQ.js";import"./Checkbox-DFMyd1TK.js";import"./SwitchBase-D71fLuiH.js";const j={delimiter:",",quote:'"',comment:"#",useHeaders:!0,skipEmptyLines:!0,dynamicTypes:!0},k=(o,e={})=>{const s={...j,...e},a=o.split(` 2`),m=[];let p=[];const c=a.filter(n=>{const i=n.trim();return i&&(!s.skipEmptyLines||!E(i,s.delimiter))&&!i.startsWith(s.comment)});if(c.length===0)return"[]";s.useHeaders&&(p=f(c[0],s),c.shift());for(const n of c){const i=f(n,s);if(s.useHeaders){const t={};p.forEach((C,x)=>{t[C]=h(i[x],s.dynamicTypes)}),m.push(t)}else m.push(i.map(t=>h(t,s.dynamicTypes)))}return JSON.stringify(m,null,2)},f=(o,e)=>{const s=[];let a="",m=!1;for(let p=0;p<o.length;p++){const c=o[p];c===e.quote?m=!m:c===e.delimiter&&!m?(s.push(a.trim()),a=""):a+=c}return s.push(a.trim()),s},h=(o,e)=>e?o.toLowerCase()==="true"?!0:o.toLowerCase()==="false"?!1:o==="null"?null:isNaN(Number(o))?o:Number(o):o;function E(o,e){return new RegExp(`^[${e}\\s]*$`).test(o)}const l={delimiter:",",quote:'"',comment:"#",useHeaders:!0,skipEmptyLines:!0,dynamicTypes:!0,indentationType:"space",spacesCount:2},S=[{title:"Basic CSV to JSON Array",description:"Convert a simple CSV file into a JSON array structure.",sampleText:`name,age,city 3John,30,New York 4Alice,25,London`,sampleResult:`[ 5 { 6 "name": "John", 7 "age": 30, 8 "city": "New York" 9 }, 10 { 11 "name": "Alice", 12 "age": 25, 13 "city": "London" 14 } 15]`,sampleOptions:{...l,useHeaders:!0,dynamicTypes:!0}},{title:"CSV with Custom Delimiter",description:"Convert a CSV file that uses semicolons as separators.",sampleText:`product;price;quantity 16Apple;1.99;50 17Banana;0.99;100`,sampleResult:`[ 18 { 19 "product": "Apple", 20 "price": 1.99, 21 "quantity": 50 22 }, 23 { 24 "product": "Banana", 25 "price": 0.99, 26 "quantity": 100 27 } 28]`,sampleOptions:{...l,delimiter:";"}},{title:"CSV with Comments and Empty Lines",description:"Process CSV data while handling comments and empty lines.",sampleText:`# This is a comment 29id,name,active 301,John,true 31 32# Another comment 332,Jane,false 34 353,Bob,true`,sampleResult:`[ 36 { 37 "id": 1, 38 "name": "John", 39 "active": true 40 }, 41 { 42 "id": 2, 43 "name": "Jane", 44 "active": false 45 }, 46 { 47 "id": 3, 48 "name": "Bob", 49 "active": true 50 } 51]`,sampleOptions:{...l,skipEmptyLines:!0,comment:"#"}}];function Q({title:o}){const{t:e}=J("csv"),[s,a]=T.useState(""),[m,p]=T.useState(""),c=(n,i)=>{if(i)try{const t=k(i,{delimiter:n.delimiter,quote:n.quote,comment:n.comment,useHeaders:n.useHeaders,skipEmptyLines:n.skipEmptyLines,dynamicTypes:n.dynamicTypes});p(t)}catch(t){p(`${e("csvToJson.error")}: ${t instanceof Error?t.message:e("csvToJson.invalidCsvFormat")}`)}};return r.jsx(v,{title:o,input:s,setInput:a,initialValues:l,compute:c,exampleCards:S,inputComponent:r.jsx(g,{title:e("csvToJson.inputTitle"),value:s,onChange:a}),resultComponent:r.jsx(L,{title:e("csvToJson.resultTitle"),value:m,extension:"json"}),getGroups:({values:n,updateField:i})=>[{title:e("csvToJson.inputCsvFormat"),component:r.jsxs(y,{children:[r.jsx(d,{description:e("csvToJson.columnSeparator"),value:n.delimiter,onOwnChange:t=>i("delimiter",t)}),r.jsx(d,{description:e("csvToJson.fieldQuote"),onOwnChange:t=>i("quote",t),value:n.quote}),r.jsx(d,{description:e("csvToJson.commentSymbol"),value:n.comment,onOwnChange:t=>i("comment",t)})]})},{title:e("csvToJson.conversionOptions"),component:r.jsxs(y,{children:[r.jsx(u,{checked:n.useHeaders,onChange:t=>i("useHeaders",t),title:e("csvToJson.useHeaders"),description:e("csvToJson.useHeadersDescription")}),r.jsx(u,{checked:n.skipEmptyLines,onChange:t=>i("skipEmptyLines",t),title:e("csvToJson.skipEmptyLines"),description:e("csvToJson.skipEmptyLinesDescription")}),r.jsx(u,{checked:n.dynamicTypes,onChange:t=>i("dynamicTypes",t),title:e("csvToJson.dynamicTypes"),description:e("csvToJson.dynamicTypesDescription")})]})}],toolInfo:{title:e("csvToJson.toolInfo.title"),description:e("csvToJson.toolInfo.description")}})}export{Q as default};
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.