1import{previewFromAoa as g,emptyPreview as $,textBlob as p,replaceExtension as v,stripBom as y,formatCount as w}from"./util-CkZ8KZK2.js";import{s as x}from"./extractShared-Dw8hkv3I.js";import{d as h,p as d,a as j}from"./jsonRelaxed-DdfPn7XG.js";function b(t){return!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function E(t,e,r){return r==="slash"?`${t}/${e.replace(/~/g,"~0").replace(/\//g,"~1")}`:r==="bracket"?`${t}[${JSON.stringify(e)}]`:b(e)?`${t}[${JSON.stringify(e)}]`:t.length===0?e:`${t}.${e}`}function A(t,e,r){return r==="slash"?`${t}/${e}`:r==="dot"?t.length===0?`[${e}]`:`${t}.${e}`:`${t}[${e}]`}function J(t,e,r=""){const s=[],a=(n,l)=>{if(Array.isArray(n)){if(n.length===0){s.push({path:l,value:[]});return}n.forEach((c,i)=>a(c,A(l,i,e)));return}if(n!==null&&typeof n=="object"){const c=Object.keys(n);if(c.length===0){s.push({path:l,value:{}});return}for(const i of c)a(n[i],E(l,i,e));return}s.push({path:l,value:n})};return a(t,r),s}function m(t){return typeof t=="string"?t:t===null?"null":t===void 0?"":JSON.stringify(t)??""}function N(t){return t===null?"null":Array.isArray(t)?"array":typeof t}function O(t,e){const r=y(t);if(r.trim().length===0)throw new Error("There is nothing to flatten. The input is empty.");const s=[];let a;try{a=JSON.parse(r)}catch(o){if(!e.relaxed)throw new Error(h(r,o));try{const u=d(r);a=u.value,s.push(j(u.fixes))}catch{throw new Error(h(r,o))}}const n=J(a,e.style);if(n.length===0)throw new Error("The document has no values in it.");const l=["path","value","type"],c=n.map(o=>[o.path,m(o.value),N(o.value)]);let i;if(e.output==="json"){const o={};for(const u of n)o[u.path]=u.value;i=`${JSON.stringify(o,null,2)} 2`}else e.output==="csv"?i=x(l,c):i=`${n.map(o=>`${o.path}${e.assignment}${m(o.value)}`).join(` 3`)} 4`;const f=Math.max(...n.map(o=>e.style==="slash"?o.path.split("/").length-1:(o.path.match(/\.|\[/g)??[]).length+1));return{entries:n,text:i,columns:l,rows:c,warnings:s,summary:[`${w(n.length)} path${n.length===1?"":"s"}`,`deepest is ${f} level${f===1?"":"s"}`,`${e.style} notation`]}}const z=async t=>{t.ctx.onProgress("Reading the JSONâ¦");const e=typeof t.text=="string"?t.text:t.file?await t.file.text():"";t.ctx.onProgress("Flatteningâ¦");const r=t.options.output??"listing",s=O(e,{style:t.options.style??"dot",output:r,assignment:t.options.assignment&&t.options.assignment.length>0?t.options.assignment:" = ",relaxed:t.options.relaxed!=="no"}),a=r==="csv"?"csv":r==="json"?"json":"txt",n=r==="csv"?"text/csv":r==="json"?"application/json":"text/plain";return{status:"ok",output:{filename:v(t.filename,a),blob:p(s.text,n),text:s.text,copyKind:r==="csv"?"csv":r==="json"?"json":"text",preview:r==="csv"?g([s.columns,...s.rows],25):$(),previewText:r==="csv"?void 0:s.text,fullRows:r==="csv"?s.rows:void 0,summary:s.summary,warnings:s.warnings}}};export{z as default,O as flattenDocument,J as flattenToPaths,A as joinIndex,E as joinKey,m as renderValue,N as typeName};
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.