'use strict'; var utilExtractor = require('@flatfile/util-extractor'); function f(c,o){try{let t=c.toString("utf8");if(!t)return console.log("Invalid file contents"),{};(o?.fileExt==="jsonl"||o?.fileExt==="jsonlines")&&(t=`[${t.split(` `).filter(e=>e.trim()!=="").map(e=>{try{return JSON.parse(e),e}catch{return console.error("Invalid JSON line:",e),null}}).filter(e=>e!==null).join(",")}]`);let a=JSON.parse(t);if(typeof a!="object"||a===null)return console.error("Invalid input: data must be an object."),{};let i={},u=Array.isArray(a)?{Sheet1:a}:a;for(let[r,e]of Object.entries(u))if(Array.isArray(e))try{i[r]=p(e);}catch(n){console.error(`Error processing sheet "${r}":`,n);}return i}catch(t){throw console.error("An error occurred:",t),t}}function p(c){try{let o=c.filter(r=>typeof r=="object"&&r!==null);if(o.length===0)return {};let t=(r,e="",n={})=>{for(let s in r){let l=e?`${e}.${s}`:s;typeof r[s]=="object"?t(r[s],l,n):n[l]=r[s];}return n},a=t(o[0]),i=Object.keys(a).filter(r=>r!==""),u=o.map(r=>{let e=t(r);return i.reduce((n,s)=>{let l=e[s];return n[s]={value:Array.isArray(l)?JSON.stringify(l):l},n},{})});return {headers:i,data:u}}catch(o){throw console.error("An error occurred:",o),o}}var h=c=>utilExtractor.Extractor(/\.(jsonl?|jsonlines)$/i,"json",f,c),m=f,S=h; exports.JSONExtractor = h; exports.jsonExtractorPlugin = S; exports.jsonParser = m; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map