import t from"file-saver";function r(r,n){var e=new Blob([n],{type:"text/plain;charset=utf-8"});t.saveAs(e,r)}function n(t,r,n){var e;return Object.keys(t).forEach((function(o){-1!==r[n].toLowerCase().indexOf(o)&&(e=t[o])})),e}function e(t,r,e,o,c){try{var a,l,i,f=t.split(/[\r\n]+/),h=[],p=f.length,u=0;for(a=0;a<f.length;a+=1){var v=f[a].split(",");for(h[a]=[],l=0;l<v.length;l+=1){var g=void 0;0===a?(g=n(r,v,l),u+=1):g=1===a?e[v[l]]:parseFloat(v[l]),h[a][l]=g}}var s={},b=[],j=f[0].split(",");for(a=0;a<u/2;a+=1){for(b=[],l=2;l<p;l+=1){var y={};for(i=0;i<2;i+=1)y[h[1][2*a+i]]=h[l][2*a+i];b.push(y)}var O=(S=j[2*a],k=void 0,(k=S.match(/(\d+\.?\d*)\s*FF/i))?parseFloat(k[1]):0),d={openhole_friction_factor:O,casing_friction_factor:O,points:b,title:j[2*a]};[].push(d);var _=h[0][2*a]?h[0][2*a]:"pick_up";s[_]||(s[_]=[]),s[_].push(d)}return 0===Object.keys(s).length?null:{data:{curves:s},effective_depth:o,end_depth:c}}catch(t){return null}var S,k}function o(t,r,n,e){for(var o="",c=0;c<t.length;c+=1)r[n[c]]?o+=e+r[n[c]]:o+=n[c],o+=c<t.length-1?",":"";t.length>0&&(o+="\n");for(var a=0;a<t.length;a+=1)o+=t[a],o+=a<t.length-1?",":"";return o}function c(t,r,n,e){var a=[],l=[],i="",f="";return e||(e=""),"[object Array]"===Object.prototype.toString.call(t)?function(t,r,n,e){if(!t||0===t.length)return"";for(var o="",a=Object.keys(t[0]),l=a.length,i=l,f=[],h=!1,p=0;p<t.length;p+=1)for(var u=0;u<l;u+=1)"[object Array]"===Object.prototype.toString.call(t[p][a[u]])&&(i=u);if(r)for(var v=0;v<i;v+=1)r[a[v]]?f[v]=e+r[a[v]]:f[v]=a[v];"\n"!==o[o.length-1]&&(o+="\n");for(var g=0;g<t.length;g+=1){if(!g||h){for(var s=0;s<i;s+=1)r&&(o+=f[s]),o+=s<i-1?",":"";o+="\n"}for(var b=0;b<l;b+=1)if("[object Array]"===Object.prototype.toString.call(t[g][a[b]])){h=!0;var j=n&&n[a[b]]?"".concat(n[a[b]]," "):"";o+="\n".concat(c(t[g][a[b]],r,n,e+j))}else(t[g][a[b]]||0===t[g][a[b]])&&(o+=t[g][a[b]]),o+=b<l-1?",":"";o+="\n"}return o}(t,r,n,e):(Object.keys(t).forEach((function(h){"[object Array]"===Object.prototype.toString.call(t[h])?(i+=o(a,r,l,e),a=[],l=[],"\n"!==i[i.length-1]&&(i+="\n"),f=n&&n[h]?"".concat(n[h]," "):"",i+=c(t[h],r,n,e+f)):"[object Object]"===Object.prototype.toString.call(t[h])?(i+=o(a,r,l,e),a=[],l=[],i.length>0&&"\n"!==i[i.length-1]&&(i+="\n"),f=n&&n[h]?"".concat(n[h]," "):"",i+=c(t[h],r,n,e+f)):t[h]&&t[h].toString().length>0&&(a.push(t[h]),l.push(h))})),"\n"!==i[i.length-1]&&(i+="\n"),(i+=o(a,r,l,e)).trim())}function a(t){return t.reduce((function(t,r){var n=r.title,e=r.csv;return"".concat(t,"\n").concat(n).concat(e)}),"")}export{a as concatCsv,e as convertCsvToJson,c as convertJsonToCsv,r as downloadFile};
//# sourceMappingURL=csvExport.js.map
