select-csv 1.1.12 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/selectcsv.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "select-csv",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "Fastest, simplest and most powerful package of all existing libraries in npmjs. It converts .csv files into an array and even into lines. It contains two important functions parseCsv that handles a csv file, you only need a link to the file. And parseText deals with text, and they both have the same roles and and methods",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"csv",
|
package/selectcsv.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const fs=require("fs");function getData(e,i,t){let r,s=Buffer.alloc(i);return 0!==(r=fs.readSync(e,s,0,i,t))?[r,String(s)]:[0,""]}function getRowsChunk(e,i,t,r){let s,n,o,f,h,l,y,{header:a,linebreak:d,quote:x,col:u,d:b,csv:c,oJson:O}=t,p=d.length;c?([f,h]=c,s=n=r[0],o=0,[l,y]=getData(f,h,s),s+=l,e=y):(n=0,o=r[0]),x1=e.indexOf(d,o);let w,m,g=2,k=0,T=sbstr2="",q=[],E=[];for(;g;){if(u){let t=b.length;if(O){let r;if(E={},x)for(;-1!=x1;){if(T=e.slice(o,x1),m=T.indexOf('"'),r=0,-1!=m)for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),y1<m?(E[O[r]]=sbstr2,y0=y1+t,y1=T.indexOf(b,y0)):(z=y0,w=m+t,m=T.indexOf('"',w),-1!=m?(y1=T.indexOf(b,m+t),m=T.indexOf('"',y1+t),-1==m&&(m=T.length)):y1=T.indexOf(b,w)),r++;else for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),E[O[r]]=sbstr2,y0=y1+t,y1=T.indexOf(b,y0),r++;if(E[O[r]]=T.slice(y0),q.push(E),E={},k++,k>=i)break;o=x1+p,x1=e.indexOf(d,o)}else for(;-1!=x1;){for(T=e.slice(o,x1),y0=0,y1=T.indexOf(b),r=0;-1!=y1;)sbstr2=T.slice(y0,y1),E[O[r]]=sbstr2,y0=y1+t,y1=T.indexOf(b,y0),r++;if(E[O[r]]=T.slice(y0),q.push(E),E={},k++,k>=i)break;o=x1+p,x1=e.indexOf(d,o)}}else if(x)for(;-1!=x1;){if(T=e.slice(o,x1),m=T.indexOf('"'),-1!=m)for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),y1<m?(E.push(sbstr2),y0=y1+t,y1=T.indexOf(b,y0)):(z=y0,w=m+t,m=T.indexOf('"',w),-1!=m?(y1=T.indexOf(b,m+t),m=T.indexOf('"',y1+t),-1==m&&(m=T.length)):y1=T.indexOf(b,w));else for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),E.push(sbstr2),y0=y1+t,y1=T.indexOf(b,y0);if(E.push(T.slice(y0)),q.push(E),E=[],k++,k>=i)break;o=x1+p,x1=e.indexOf(d,o)}else for(;-1!=x1;){for(T=e.slice(o,x1),y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),E.push(sbstr2),y0=y1+t,y1=T.indexOf(b,y0);if(E.push(T.slice(y0)),q.push(E),E=[],k++,k>=i)break;o=x1+p,x1=e.indexOf(d,o)}}else for(;-1!=x1&&(E.push(e.slice(o,x1)),q.push(E),E=[],k++,!(k>=i));)o=x1+p,x1=e.indexOf(d,o);if(k>=i){o=x1+p;break}if(g--,-1==x1)if(g)if(c){for(l=1,e=e.slice(o),n+=o,o=0;l&&-1==x1;)[l,y]=getData(f,h,s),s+=l,e+=y,x1=e.indexOf(d);-1==x1&&(x1=e.length),l&&g++}else x1=e.length;else o=x1}return{get:{rows:q,row_count:k},offs:[n+o,k+r[1]],row_count:k}}function getAllRows(e,i,t){let r,s,n,o,f,h,{header:l,linebreak:y,quote:a,col:d,d:x,csv:u,oJson:b}=i,c=y.length,O=x0=t;u&&([n,o]=u,r=e.length,f=1),s=e.indexOf(y,x0);let p,w,m=2,g=0,k=sbstr2="",T=[],q=[];for(;m;){if(d){let i=x.length;if(b){let t;if(q={},a)for(;-1!=s;){if(k=e.slice(x0,s),w=k.indexOf('"'),-1!=w)for(y0=0,y1=k.indexOf(x),t=0;-1!=y1;)sbstr2=k.slice(y0,y1),y1<w?(q[b[t]]=sbstr2,y0=y1+i,y1=k.indexOf(x,y0)):(z=y0,p=w+i,w=k.indexOf('"',p),-1!=w?(y1=k.indexOf(x,w+i),w=k.indexOf('"',y1+i),-1==w&&(w=k.length)):y1=k.indexOf(x,p)),t++;else for(y0=0,y1=k.indexOf(x),t=0;-1!=y1;)sbstr2=k.slice(y0,y1),q[b[t]]=sbstr2,y0=y1+i,y1=k.indexOf(x,y0),t++;q[b[t]]=k.slice(y0),T.push(q),q={},x0=s+c,s=e.indexOf(y,x0),g++}else for(;-1!=s;){for(k=e.slice(x0,s),y0=0,y1=k.indexOf(x),t=0;-1!=y1;)sbstr2=k.slice(y0,y1),q[b[t]]=sbstr2,y0=y1+i,y1=k.indexOf(x,y0),t++;q[b[t]]=k.slice(y0),T.push(q),q={},x0=s+c,s=e.indexOf(y,x0),g++}}else if(a)for(;-1!=s;){if(k=e.slice(x0,s),w=k.indexOf('"'),-1!=w)for(y0=0,y1=k.indexOf(x);-1!=y1;)sbstr2=k.slice(y0,y1),y1<w?(q.push(sbstr2),y0=y1+i,y1=k.indexOf(x,y0)):(z=y0,p=w+i,w=k.indexOf('"',p),-1!=w?(y1=k.indexOf(x,w+i),w=k.indexOf('"',y1+i),-1==w&&(w=k.length)):y1=k.indexOf(x,p));else for(y0=0,y1=k.indexOf(x);-1!=y1;)sbstr2=k.slice(y0,y1),q.push(sbstr2),y0=y1+i,y1=k.indexOf(x,y0);q.push(k.slice(y0)),T.push(q),q=[],x0=s+c,s=e.indexOf(y,x0),g++}else for(;-1!=s;){for(k=e.slice(x0,s),y0=0,y1=k.indexOf(x);-1!=y1;)sbstr2=k.slice(y0,y1),q.push(sbstr2),y0=y1+i,y1=k.indexOf(x,y0);q.push(k.slice(y0)),T.push(q),q=[],x0=s+c,s=e.indexOf(y,x0),g++}}else for(;-1!=s;)q.push(e.slice(x0,s)),T.push(q),q=[],x0=s+c,s=e.indexOf(y,x0),g++;if(m--,-1==s)if(m)if(u){for(f=1,e=e.slice(x0),O+=x0,x0=0;f&&-1==s;)[f,h]=getData(n,o,r),r+=f,s=(e+=h).indexOf(y);-1==s&&(s=e.length),f&&m++}else s=e.length;else x0=s}return{get:{rows:T,row_count:g},offs:[O+x0,g],row_count:g}}function getRowsOffsFT(e,i,t,r,s){let n,o,f,h,l,y,{header:a,linebreak:d,quote:x,col:u,d:b,csv:c,oJson:O}=r,p=d.length,w=x0=s;c&&([f,h]=c,n=e.length,l=1),o=e.indexOf(d,x0);let m,g,k=2,T=0,q=0,E=sbstr2="",j=[],R=[];for(;k;){if(u){let r=b.length;if(O){let s;if(R={},x)for(;-1!=o;){if(T>=i){if(!(T<t)){T++;break}if(E=e.slice(x0,o),g=E.indexOf('"'),-1!=g)for(y0=0,y1=E.indexOf(b),s=0;-1!=y1;)sbstr2=E.slice(y0,y1),y1<g?(R[O[s]]=sbstr2,y0=y1+r,y1=E.indexOf(b,y0)):(z=y0,m=g+r,g=E.indexOf('"',m),-1!=g?(y1=E.indexOf(b,g+r),g=E.indexOf('"',y1+r),-1==g&&(g=E.length)):y1=E.indexOf(b,m)),s++;else for(y0=0,y1=E.indexOf(b),s=0;-1!=y1;)sbstr2=E.slice(y0,y1),R[O[s]]=sbstr2,y0=y1+r,y1=E.indexOf(b,y0),s++;R[O[s]]=E.slice(y0),j.push(R),R={},q++}x0=o+p,o=e.indexOf(d,x0),T++}else for(;-1!=o;){if(!(T<t)){T++;break}if(T>=i){for(E=e.slice(x0,o),y0=0,y1=E.indexOf(b),s=0;-1!=y1;)sbstr2=E.slice(y0,y1),R[O[s]]=sbstr2,y0=y1+r,y1=E.indexOf(b,y0),s++;R[O[s]]=E.slice(y0),j.push(R),R={},q++}x0=o+p,o=e.indexOf(d,x0),T++}}else if(x)for(;-1!=o;){if(T>=i){if(!(T<t)){T++;break}if(E=e.slice(x0,o),g=E.indexOf('"'),-1!=g)for(y0=0,y1=E.indexOf(b);-1!=y1;)sbstr2=E.slice(y0,y1),y1<g?(R.push(sbstr2),y0=y1+r,y1=E.indexOf(b,y0)):(z=y0,m=g+r,g=E.indexOf('"',m),-1!=g?(y1=E.indexOf(b,g+r),g=E.indexOf('"',y1+r),-1==g&&(g=E.length)):y1=E.indexOf(b,m));else for(y0=0,y1=E.indexOf(b);-1!=y1;)sbstr2=E.slice(y0,y1),R.push(sbstr2),y0=y1+r,y1=E.indexOf(b,y0);R.push(E.slice(y0)),j.push(R),R=[],q++}x0=o+p,o=e.indexOf(d,x0),T++}else for(;-1!=o;){if(!(T<t)){T++;break}if(T>=i){for(E=e.slice(x0,o),y0=0,y1=E.indexOf(b);-1!=y1;)sbstr2=E.slice(y0,y1),R.push(sbstr2),y0=y1+r,y1=E.indexOf(b,y0);R.push(E.slice(y0)),j.push(R),R=[],q++}x0=o+p,o=e.indexOf(d,x0),T++}}else for(;-1!=o;){if(!(T<t)){T++;break}T>=i&&(R.push(e.slice(x0,o)),j.push(R),R=[],q++),x0=o+p,o=e.indexOf(d,x0),T++}if(T>=t)break;if(k--,-1==o)if(k)if(c){for(l=1,e=e.slice(x0),w+=x0,x0=0;l&&-1==o;)[l,y]=getData(f,h,n),n+=l,o=(e+=y).indexOf(d);-1==o&&(o=e.length),l&&k++}else o=e.length;else x0=o}return{get:{rows:j,row_count:q},offs:[w+x0,T],row_count:q}}function getRowsOffsF(e,i,t,r){let s,n,o,f,h,l,{header:y,linebreak:a,quote:d,col:x,d:u,csv:b,oJson:c}=t,O=a.length,p=x0=r;b&&([o,f]=b,s=e.length,h=1),n=e.indexOf(a,x0);let w,m,g=2,k=0,T=0,q=sbstr2="",E=[],j=[];for(;g;){if(x){let t=u.length;if(c){let r;if(j={},d)for(;-1!=n;){if(k>=i){if(q=e.slice(x0,n),m=q.indexOf('"'),-1!=m)for(y0=0,y1=q.indexOf(u),r=0;-1!=y1;)sbstr2=q.slice(y0,y1),y1<m?(j[c[r]]=sbstr2,y0=y1+t,y1=q.indexOf(u,y0)):(z=y0,w=m+t,m=q.indexOf('"',w),-1!=m?(y1=q.indexOf(u,m+t),m=q.indexOf('"',y1+t),-1==m&&(m=q.length)):y1=q.indexOf(u,w)),r++;else for(y0=0,y1=q.indexOf(u),r=0;-1!=y1;)sbstr2=q.slice(y0,y1),j[c[r]]=sbstr2,y0=y1+t,y1=q.indexOf(u,y0),r++;j[c[r]]=q.slice(y0),E.push(j),j={},T++}x0=n+O,n=e.indexOf(a,x0),k++}else for(;-1!=n;){if(k>=i){for(q=e.slice(x0,n),y0=0,y1=q.indexOf(u),r=0;-1!=y1;)sbstr2=q.slice(y0,y1),j[c[r]]=sbstr2,y0=y1+t,y1=q.indexOf(u,y0),r++;j[c[r]]=q.slice(y0),E.push(j),j={},T++}x0=n+O,n=e.indexOf(a,x0),k++}}else if(d)for(;-1!=n;){if(k>=i){if(q=e.slice(x0,n),m=q.indexOf('"'),-1!=m)for(y0=0,y1=q.indexOf(u);-1!=y1;)sbstr2=q.slice(y0,y1),y1<m?(j.push(sbstr2),y0=y1+t,y1=q.indexOf(u,y0)):(z=y0,w=m+t,m=q.indexOf('"',w),-1!=m?(y1=q.indexOf(u,m+t),m=q.indexOf('"',y1+t),-1==m&&(m=q.length)):y1=q.indexOf(u,w));else for(y0=0,y1=q.indexOf(u);-1!=y1;)sbstr2=q.slice(y0,y1),j.push(sbstr2),y0=y1+t,y1=q.indexOf(u,y0);j.push(q.slice(y0)),E.push(j),j=[],T++}x0=n+O,n=e.indexOf(a,x0),k++}else for(;-1!=n;){if(k>=i){for(q=e.slice(x0,n),y0=0,y1=q.indexOf(u);-1!=y1;)sbstr2=q.slice(y0,y1),j.push(sbstr2),y0=y1+t,y1=q.indexOf(u,y0);j.push(q.slice(y0)),E.push(j),j=[],T++}x0=n+O,n=e.indexOf(a,x0),k++}}else for(;-1!=n;)k>=i&&(j.push(e.slice(x0,n)),E.push(j),j=[],T++),x0=n+O,n=e.indexOf(a,x0),k++;if(g--,-1==n)if(g)if(b){for(h=1,e=e.slice(x0),p+=x0,x0=0;h&&-1==n;)[h,l]=getData(o,f,s),s+=h,n=(e+=l).indexOf(a);-1==n&&(n=e.length),h&&g++}else n=e.length;else x0=n}return{get:{rows:E,row_count:T},offs:[p+x0,k],row_count:T}}function get(){let e,i=Date.now();return e=getAllRows(this.data,this.info,this.starOffsRow),{time:Date.now()-i+" ms",header:this.option.header?this.header:this.option.header,...e.get}}function chunk(e){let i,t=Date.now();if(!e||!Number.isInteger(e))throw new Error("The 'chunk' parameter must be an integer");if(!(e>=1))throw new Error("The 'chunk' parameter must be greater than or equal to 1");return i=getRowsChunk(this.data,e,this.info,this.offs_n),this.offs_n=i.offs,{time:Date.now()-t+" ms",header:this.option.header?this.header:this.option.header,...i.get}}function rowOffset(e,i){let t,r=Date.now();if(!Number.isInteger(e))throw new Error("The first parameter must be an integer");if(!(e>=0))throw new Error("The first parameter must be greater than or equal to zero");if(null==i)t=getRowsOffsF(this.data,e,this.info,this.starOffsRow);else{if(!Number.isInteger(i))throw new Error("The second parameter must be an integer");if(!(i>0))throw new Error("The second parameter must be greater than or equal to 1");t=getRowsOffsFT(this.data,e,i,this.info,this.starOffsRow)}return t.row_count&&(this.offs_n=t.offs),{time:Date.now()-r+" ms",header:this.option.header?this.header:this.option.header,...t.get}}function setRowOffset(e){if(null!=e){if(!Number.isInteger(e))throw new Error("The 'rowOffs' parameter must be an integer");if(!(e>=0))throw new Error("The 'rowOffs' parameter must be greater than or equal to zero");{let i=this.info[1].length;n=0,x0=0,x1=this.data.indexOf(this.info[1]);let t=this.data.length;for(;-1!=x1;){if(n==e)return t=this.option.header?x1+i:x0,this.offs_n=[t,n],[t,n];x0=x1+i,x1=this.data.indexOf(this.info[1],x0),n++}}}return!1}function resetOption(e){let i,t={header:!0,quote:!1,linebreak:"\r\n",delimiter:",",json:!1,bufferSize:1048576};if(null!=e){if("object"!=typeof e)throw new Error("The second parameter must be an object");if("header"in e){if("boolean"!=typeof e.header)throw new Error("The 'header' key in The second parameter must be 'boolean'");this.option.header=e.header}if("quote"in e){if("boolean"!=typeof e.quote)throw new Error("The 'quote' key in The second parameter must be 'boolean'");this.option.quote=e.quote}if("linebreak"in e){if("string"!=typeof e.linebreak)throw new Error("The 'linebreak' key in The second parameter must be 'string'");this.option.linebreak=e.linebreak}if("delimiter"in e){if("string"!=typeof e.delimiter&&("boolean"!=typeof e.delimiter||e.delimiter))throw new Error("The 'delimiter' key in The second parameter must be 'string' or false 'boolean'");this.option.delimiter=e.delimiter,"boolean"===e.delimiter&&(this.column=!1)}if("json"in e){if("boolean"!=typeof e.json)throw new Error("The 'json' key in The second parameter must be 'boolean'");t.json=e.json}if("bufferSize"in e){if(!Number.isInteger(e.bufferSize))throw new Error("The 'rowOffs' parameter must be an integer");if(!(e.bufferSize>=1024))throw new Error("The 'bufferSize' parameter must be greater than or equal to 1024");t.bufferSize=e.bufferSize}}else this.option=t;i=this.fd?getColumns(this.data,this.option,this.csv):getColumns(this.data,this.option),this.header=i[0],this.starOffsRow=i[1],this.offs_n=[this.starOffsRow,0],this.oJson=!(!this.option.header||!this.option.json)&&this.header,this.info={header:this.option.header,linebreak:this.option.linebreak,quote:this.option.quote,col:this.column,d:this.option.delimiter,csv:this.csv,oJson:this.oJson}}function getInfo(){return{offset:this.offs_n[0],rowOffset:this.offs_n[1],option:this.option}}function offs_nRowwwwwwww(e,i,t){let r,s=0;if(i.header){if(t){let s,[n,o]=t,f=0,h=1;for(r=e.indexOf(i.linebreak);h&&-1==r;)[h,s]=getData(n,o,f),f+=h,r=(e+=s).indexOf(i.linebreak)}else r=e.indexOf(i.linebreak);s=-1==r?r=e.length:r+i.linebreak.length}return[s,0]}function getColumns(e,i,t){let r=!1,s=0;if(i.header){r=[];let n,o=i.delimiter.length;if(t){let r,[s,o]=t,f=0,h=1;for(n=e.indexOf(i.linebreak);h&&-1==n;)[h,r]=getData(s,o,f),f+=h,n=(e+=r).indexOf(i.linebreak)}else n=e.indexOf(i.linebreak);if(-1!=n){let t,f=e.slice(s,n),h=0,l=f.indexOf(i.delimiter);for(;-1!=l;)t=f.slice(h,l),r.push(t),h=l+o,l=f.indexOf(i.delimiter,h);r.push(f.slice(h))}s=-1==n?n=e.length:n+i.linebreak.length}return[r,s]}function parseCsv(e,i){let t,r,s=!0,n={header:!0,quote:!1,linebreak:"\r\n",delimiter:",",json:!1,bufferSize:1048576};if(null==e)throw new Error("The first parameter 'file_path' must be string");if(!fs.existsSync(e))throw new Error(`File "${e}" does not exists`);{r=fs.openSync(e,"r");let[i,s]=getData(r,n.bufferSize,0);t=s}if(null!=i){if("object"!=typeof i)throw new Error("The second parameter must be an object");if("header"in i){if("boolean"!=typeof i.header)throw new Error("The 'header' key in The second parameter must be 'boolean'");n.header=i.header}if("quote"in i){if("boolean"!=typeof i.quote)throw new Error("The 'quote' key in The second parameter must be 'boolean'");n.quote=i.quote}if("linebreak"in i){if("string"!=typeof i.linebreak)throw new Error("The 'linebreak' key in The second parameter must be 'string'");n.linebreak=i.linebreak}if("delimiter"in i){if("string"!=typeof i.delimiter&&("boolean"!=typeof i.delimiter||i.delimiter))throw new Error("The 'delimiter' key in The second parameter must be 'string' or false 'boolean'");n.delimiter=i.delimiter,"boolean"===i.delimiter&&(s=!1)}if("json"in i){if("boolean"!=typeof i.json)throw new Error("The 'json' key in The second parameter must be 'boolean'");n.json=i.json}if("bufferSize"in i){if(!Number.isInteger(i.bufferSize))throw new Error("The 'rowOffs' parameter must be an integer");if(!(i.bufferSize>=1024))throw new Error("The 'bufferSize' parameter must be greater than or equal to 1024");n.bufferSize=i.bufferSize}}return new class{constructor(){let e;this.option=n,this.data=t,this.column=s,this.csv=[r,n.bufferSize],e=getColumns(this.data,this.option,this.csv),this.header=e[0],this.starOffsRow=e[1],this.offs_n=[this.starOffsRow,0],this.oJson=!(!this.option.header||!this.option.json)&&this.header,this.info={header:this.option.header,linebreak:this.option.linebreak,quote:this.option.quote,col:this.column,d:this.option.delimiter,csv:this.csv,oJson:this.oJson}}get=get;chunk=chunk;setRowOffset=setRowOffset;rowOffset=rowOffset;getInfo=getInfo}}function parseText(e,i){let t,r={header:!0,quote:!1,linebreak:"\r\n",delimiter:",",json:!1};if(null==e&&"string"==typeof e)throw new Error("The first parameter must be a file path string");if(t=e,null!=i){if("object"!=typeof i)throw new Error("The second parameter must be an object");if("header"in i){if("boolean"!=typeof i.header)throw new Error("The 'header' key in The second parameter must be 'boolean'");r.header=i.header}if("quote"in i){if("boolean"!=typeof i.quote)throw new Error("The 'quote' key in The second parameter must be 'boolean'");r.quote=i.quote}if("linebreak"in i){if("string"!=typeof i.linebreak)throw new Error("The 'linebreak' key in The second parameter must be 'string'");r.linebreak=i.linebreak}if("delimiter"in i){if("string"!=typeof i.delimiter&&("boolean"!=typeof i.delimiter||i.delimiter))throw new Error("The 'delimiter' key in The second parameter must be 'string' or false 'boolean'");r.delimiter=i.delimiter,"boolean"===i.delimiter&&(this.column=!1)}if("json"in i){if("boolean"!=typeof i.json)throw new Error("The 'json' key in The second parameter must be 'boolean'");r.json=i.json}}return new class{constructor(){let e;this.option=r,this.data=t,this.column=true,this.csv=!1,e=getColumns(this.data,this.option),this.header=e[0],this.starOffsRow=e[1],this.offs_n=[this.starOffsRow,0],this.oJson=!(!this.option.header||!this.option.json)&&this.header,this.info={header:this.option.header,linebreak:this.option.linebreak,quote:this.option.quote,col:this.column,d:this.option.delimiter,oJson:this.oJson}}get=get;chunk=chunk;setRowOffset=setRowOffset;rowOffset=rowOffset;resetOption=resetOption;getInfo=getInfo}}module.exports={parseText:parseText,parseCsv:parseCsv};
|
|
1
|
+
const fs=require("fs");function Err(e){try{throw Error("")}catch(t){console.log("Error:",e);let i=t.stack,s=i.indexOf("\n",i.indexOf("\n")+1);console.log(i.slice(s)),process.exit()}}function getData(e,t,i){let s,r=Buffer.alloc(t);return 0!==(s=fs.readSync(e,r,0,t,i))?[s,String(r)]:[0,""]}function getRowsChunk(e,t,i,s){let r,n,o,f,l,y,h,{header:a,linebreak:d,quote:x,col:u,d:b,csv:c,oJson:O}=i,p=d.length;c?([f,l]=c,r=n=s[0],o=0,[y,h]=getData(f,l,r),r+=y,e=h):(n=0,o=s[0]),x1=e.indexOf(d,o);let m,g,k=2,w=0,T=sbstr2="",E=[],q=[];for(;k;){if(u){let i=b.length;if(O){let s;if(q={},x)for(;-1!=x1;){if(T=e.slice(o,x1),g=T.indexOf('"'),s=0,-1!=g)for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),y1<g?(q[O[s]]=sbstr2,y0=y1+i,y1=T.indexOf(b,y0)):(z=y0,m=g+i,g=T.indexOf('"',m),-1!=g?(y1=T.indexOf(b,g+i),g=T.indexOf('"',y1+i),-1==g&&(g=T.length)):y1=T.indexOf(b,m)),s++;else for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),q[O[s]]=sbstr2,y0=y1+i,y1=T.indexOf(b,y0),s++;if(q[O[s]]=T.slice(y0),E.push(q),q={},w++,w>=t)break;o=x1+p,x1=e.indexOf(d,o)}else for(;-1!=x1;){for(T=e.slice(o,x1),y0=0,y1=T.indexOf(b),s=0;-1!=y1;)sbstr2=T.slice(y0,y1),q[O[s]]=sbstr2,y0=y1+i,y1=T.indexOf(b,y0),s++;if(q[O[s]]=T.slice(y0),E.push(q),q={},w++,w>=t)break;o=x1+p,x1=e.indexOf(d,o)}}else if(x)for(;-1!=x1;){if(T=e.slice(o,x1),g=T.indexOf('"'),-1!=g)for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),y1<g?(q.push(sbstr2),y0=y1+i,y1=T.indexOf(b,y0)):(z=y0,m=g+i,g=T.indexOf('"',m),-1!=g?(y1=T.indexOf(b,g+i),g=T.indexOf('"',y1+i),-1==g&&(g=T.length)):y1=T.indexOf(b,m));else for(y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),q.push(sbstr2),y0=y1+i,y1=T.indexOf(b,y0);if(q.push(T.slice(y0)),E.push(q),q=[],w++,w>=t)break;o=x1+p,x1=e.indexOf(d,o)}else for(;-1!=x1;){for(T=e.slice(o,x1),y0=0,y1=T.indexOf(b);-1!=y1;)sbstr2=T.slice(y0,y1),q.push(sbstr2),y0=y1+i,y1=T.indexOf(b,y0);if(q.push(T.slice(y0)),E.push(q),q=[],w++,w>=t)break;o=x1+p,x1=e.indexOf(d,o)}}else for(;-1!=x1&&(q.push(e.slice(o,x1)),E.push(q),q=[],w++,!(w>=t));)o=x1+p,x1=e.indexOf(d,o);if(w>=t){o=x1+p;break}if(k--,-1==x1)if(k)if(c){for(y=1,e=e.slice(o),n+=o,o=0;y&&-1==x1;)[y,h]=getData(f,l,r),r+=y,e+=h,x1=e.indexOf(d);-1==x1&&(x1=e.length),y&&k++}else x1=e.length;else o=x1}return{get:{rows:E,row_count:w},offs:[n+o,w+s[1]],row_count:w}}function getAllRows(e,t,i){let s,r,n,o,f,l,{header:y,linebreak:h,quote:a,col:d,d:x,csv:u,oJson:b}=t,c=h.length,O=x0=i;u&&([n,o]=u,s=e.length,f=1),r=e.indexOf(h,x0);let p,m,g=2,k=0,w=sbstr2="",T=[],E=[];for(;g;){if(d){let t=x.length;if(b){let i;if(E={},a)for(;-1!=r;){if(w=e.slice(x0,r),m=w.indexOf('"'),-1!=m)for(y0=0,y1=w.indexOf(x),i=0;-1!=y1;)sbstr2=w.slice(y0,y1),y1<m?(E[b[i]]=sbstr2,y0=y1+t,y1=w.indexOf(x,y0)):(z=y0,p=m+t,m=w.indexOf('"',p),-1!=m?(y1=w.indexOf(x,m+t),m=w.indexOf('"',y1+t),-1==m&&(m=w.length)):y1=w.indexOf(x,p)),i++;else for(y0=0,y1=w.indexOf(x),i=0;-1!=y1;)sbstr2=w.slice(y0,y1),E[b[i]]=sbstr2,y0=y1+t,y1=w.indexOf(x,y0),i++;E[b[i]]=w.slice(y0),T.push(E),E={},x0=r+c,r=e.indexOf(h,x0),k++}else for(;-1!=r;){for(w=e.slice(x0,r),y0=0,y1=w.indexOf(x),i=0;-1!=y1;)sbstr2=w.slice(y0,y1),E[b[i]]=sbstr2,y0=y1+t,y1=w.indexOf(x,y0),i++;E[b[i]]=w.slice(y0),T.push(E),E={},x0=r+c,r=e.indexOf(h,x0),k++}}else if(a)for(;-1!=r;){if(w=e.slice(x0,r),m=w.indexOf('"'),-1!=m)for(y0=0,y1=w.indexOf(x);-1!=y1;)sbstr2=w.slice(y0,y1),y1<m?(E.push(sbstr2),y0=y1+t,y1=w.indexOf(x,y0)):(z=y0,p=m+t,m=w.indexOf('"',p),-1!=m?(y1=w.indexOf(x,m+t),m=w.indexOf('"',y1+t),-1==m&&(m=w.length)):y1=w.indexOf(x,p));else for(y0=0,y1=w.indexOf(x);-1!=y1;)sbstr2=w.slice(y0,y1),E.push(sbstr2),y0=y1+t,y1=w.indexOf(x,y0);E.push(w.slice(y0)),T.push(E),E=[],x0=r+c,r=e.indexOf(h,x0),k++}else for(;-1!=r;){for(w=e.slice(x0,r),y0=0,y1=w.indexOf(x);-1!=y1;)sbstr2=w.slice(y0,y1),E.push(sbstr2),y0=y1+t,y1=w.indexOf(x,y0);E.push(w.slice(y0)),T.push(E),E=[],x0=r+c,r=e.indexOf(h,x0),k++}}else for(;-1!=r;)E.push(e.slice(x0,r)),T.push(E),E=[],x0=r+c,r=e.indexOf(h,x0),k++;if(g--,-1==r)if(g)if(u){for(f=1,e=e.slice(x0),O+=x0,x0=0;f&&-1==r;)[f,l]=getData(n,o,s),s+=f,r=(e+=l).indexOf(h);-1==r&&(r=e.length),f&&g++}else r=e.length;else x0=r}return{get:{rows:T,row_count:k},offs:[O+x0,k],row_count:k}}function getRowsOffsFT(e,t,i,s,r){let n,o,f,l,y,h,{header:a,linebreak:d,quote:x,col:u,d:b,csv:c,oJson:O}=s,p=d.length,m=x0=r;c&&([f,l]=c,n=e.length,y=1),o=e.indexOf(d,x0);let g,k,w=2,T=0,E=0,q=sbstr2="",j=[],R=[];for(;w;){if(u){let s=b.length;if(O){let r;if(R={},x)for(;-1!=o;){if(T>=t){if(!(T<i)){T++;break}if(q=e.slice(x0,o),k=q.indexOf('"'),-1!=k)for(y0=0,y1=q.indexOf(b),r=0;-1!=y1;)sbstr2=q.slice(y0,y1),y1<k?(R[O[r]]=sbstr2,y0=y1+s,y1=q.indexOf(b,y0)):(z=y0,g=k+s,k=q.indexOf('"',g),-1!=k?(y1=q.indexOf(b,k+s),k=q.indexOf('"',y1+s),-1==k&&(k=q.length)):y1=q.indexOf(b,g)),r++;else for(y0=0,y1=q.indexOf(b),r=0;-1!=y1;)sbstr2=q.slice(y0,y1),R[O[r]]=sbstr2,y0=y1+s,y1=q.indexOf(b,y0),r++;R[O[r]]=q.slice(y0),j.push(R),R={},E++}x0=o+p,o=e.indexOf(d,x0),T++}else for(;-1!=o;){if(!(T<i)){T++;break}if(T>=t){for(q=e.slice(x0,o),y0=0,y1=q.indexOf(b),r=0;-1!=y1;)sbstr2=q.slice(y0,y1),R[O[r]]=sbstr2,y0=y1+s,y1=q.indexOf(b,y0),r++;R[O[r]]=q.slice(y0),j.push(R),R={},E++}x0=o+p,o=e.indexOf(d,x0),T++}}else if(x)for(;-1!=o;){if(T>=t){if(!(T<i)){T++;break}if(q=e.slice(x0,o),k=q.indexOf('"'),-1!=k)for(y0=0,y1=q.indexOf(b);-1!=y1;)sbstr2=q.slice(y0,y1),y1<k?(R.push(sbstr2),y0=y1+s,y1=q.indexOf(b,y0)):(z=y0,g=k+s,k=q.indexOf('"',g),-1!=k?(y1=q.indexOf(b,k+s),k=q.indexOf('"',y1+s),-1==k&&(k=q.length)):y1=q.indexOf(b,g));else for(y0=0,y1=q.indexOf(b);-1!=y1;)sbstr2=q.slice(y0,y1),R.push(sbstr2),y0=y1+s,y1=q.indexOf(b,y0);R.push(q.slice(y0)),j.push(R),R=[],E++}x0=o+p,o=e.indexOf(d,x0),T++}else for(;-1!=o;){if(!(T<i)){T++;break}if(T>=t){for(q=e.slice(x0,o),y0=0,y1=q.indexOf(b);-1!=y1;)sbstr2=q.slice(y0,y1),R.push(sbstr2),y0=y1+s,y1=q.indexOf(b,y0);R.push(q.slice(y0)),j.push(R),R=[],E++}x0=o+p,o=e.indexOf(d,x0),T++}}else for(;-1!=o;){if(!(T<i)){T++;break}T>=t&&(R.push(e.slice(x0,o)),j.push(R),R=[],E++),x0=o+p,o=e.indexOf(d,x0),T++}if(T>=i)break;if(w--,-1==o)if(w)if(c){for(y=1,e=e.slice(x0),m+=x0,x0=0;y&&-1==o;)[y,h]=getData(f,l,n),n+=y,o=(e+=h).indexOf(d);-1==o&&(o=e.length),y&&w++}else o=e.length;else x0=o}return{get:{rows:j,row_count:E},offs:[m+x0,T],row_count:E}}function getRowsOffsF(e,t,i,s){let r,n,o,f,l,y,{header:h,linebreak:a,quote:d,col:x,d:u,csv:b,oJson:c}=i,O=a.length,p=x0=s;b&&([o,f]=b,r=e.length,l=1),n=e.indexOf(a,x0);let m,g,k=2,w=0,T=0,E=sbstr2="",q=[],j=[];for(;k;){if(x){let i=u.length;if(c){let s;if(j={},d)for(;-1!=n;){if(w>=t){if(E=e.slice(x0,n),g=E.indexOf('"'),-1!=g)for(y0=0,y1=E.indexOf(u),s=0;-1!=y1;)sbstr2=E.slice(y0,y1),y1<g?(j[c[s]]=sbstr2,y0=y1+i,y1=E.indexOf(u,y0)):(z=y0,m=g+i,g=E.indexOf('"',m),-1!=g?(y1=E.indexOf(u,g+i),g=E.indexOf('"',y1+i),-1==g&&(g=E.length)):y1=E.indexOf(u,m)),s++;else for(y0=0,y1=E.indexOf(u),s=0;-1!=y1;)sbstr2=E.slice(y0,y1),j[c[s]]=sbstr2,y0=y1+i,y1=E.indexOf(u,y0),s++;j[c[s]]=E.slice(y0),q.push(j),j={},T++}x0=n+O,n=e.indexOf(a,x0),w++}else for(;-1!=n;){if(w>=t){for(E=e.slice(x0,n),y0=0,y1=E.indexOf(u),s=0;-1!=y1;)sbstr2=E.slice(y0,y1),j[c[s]]=sbstr2,y0=y1+i,y1=E.indexOf(u,y0),s++;j[c[s]]=E.slice(y0),q.push(j),j={},T++}x0=n+O,n=e.indexOf(a,x0),w++}}else if(d)for(;-1!=n;){if(w>=t){if(E=e.slice(x0,n),g=E.indexOf('"'),-1!=g)for(y0=0,y1=E.indexOf(u);-1!=y1;)sbstr2=E.slice(y0,y1),y1<g?(j.push(sbstr2),y0=y1+i,y1=E.indexOf(u,y0)):(z=y0,m=g+i,g=E.indexOf('"',m),-1!=g?(y1=E.indexOf(u,g+i),g=E.indexOf('"',y1+i),-1==g&&(g=E.length)):y1=E.indexOf(u,m));else for(y0=0,y1=E.indexOf(u);-1!=y1;)sbstr2=E.slice(y0,y1),j.push(sbstr2),y0=y1+i,y1=E.indexOf(u,y0);j.push(E.slice(y0)),q.push(j),j=[],T++}x0=n+O,n=e.indexOf(a,x0),w++}else for(;-1!=n;){if(w>=t){for(E=e.slice(x0,n),y0=0,y1=E.indexOf(u);-1!=y1;)sbstr2=E.slice(y0,y1),j.push(sbstr2),y0=y1+i,y1=E.indexOf(u,y0);j.push(E.slice(y0)),q.push(j),j=[],T++}x0=n+O,n=e.indexOf(a,x0),w++}}else for(;-1!=n;)w>=t&&(j.push(e.slice(x0,n)),q.push(j),j=[],T++),x0=n+O,n=e.indexOf(a,x0),w++;if(k--,-1==n)if(k)if(b){for(l=1,e=e.slice(x0),p+=x0,x0=0;l&&-1==n;)[l,y]=getData(o,f,r),r+=l,n=(e+=y).indexOf(a);-1==n&&(n=e.length),l&&k++}else n=e.length;else x0=n}return{get:{rows:q,row_count:T},offs:[p+x0,w],row_count:T}}function get(){let e,t=Date.now();return e=getAllRows(this.data,this.info,this.starOffsRow),{time:Date.now()-t+" ms",header:this.option.header?this.hdr:this.option.header,...e.get}}function chunk(e){let t,i=Date.now();return e&&Number.isInteger(e)?e>=1?t=getRowsChunk(this.data,e,this.info,this.offs_n):Err("The 'chunk' parameter must be greater than or equal to 1"):Err("The 'chunk' parameter must be an integer"),this.offs_n=t.offs,{time:Date.now()-i+" ms",header:this.option.header?this.hdr:this.option.header,...t.get}}function rowOffset(e,t){let i,s=Date.now();return Number.isInteger(e)?e>=0?null==t?i=getRowsOffsF(this.data,e,this.info,this.starOffsRow):Number.isInteger(t)?t>0?i=getRowsOffsFT(this.data,e,t,this.info,this.starOffsRow):Err("The second parameter must be greater than or equal to 1"):Err("The second parameter must be an integer"):Err("The first parameter must be greater than or equal to zero"):Err("The first parameter must be an integer"),i.row_count&&(this.offs_n=i.offs),{time:Date.now()-s+" ms",header:this.option.header?this.hdr:this.option.header,...i.get}}function setRowOffset(e){if(null!=e)if(Number.isInteger(e))if(e>=0){let t=this.info[1].length;n=0,x0=0,x1=this.data.indexOf(this.info[1]);let i=this.data.length;for(;-1!=x1;){if(n==e)return i=this.option.header?x1+t:x0,this.offs_n=[i,n],[i,n];x0=x1+t,x1=this.data.indexOf(this.info[1],x0),n++}}else Err("The 'rowOffs' parameter must be greater than or equal to zero");else Err("The 'rowOffs' parameter must be an integer");return!1}function resetOption(e){let t,i={header:!0,quote:!1,linebreak:"\r\n",delimiter:",",json:!1,bufferSize:1048576};null!=e?"object"==typeof e?("header"in e&&("boolean"==typeof e.header?this.option.header=e.header:Err("The 'header' key in The second parameter must be 'boolean'")),"quote"in e&&("boolean"==typeof e.quote?this.option.quote=e.quote:Err("The 'quote' key in The second parameter must be 'boolean'")),"linebreak"in e&&("string"==typeof e.linebreak?this.option.linebreak=e.linebreak:Err("The 'linebreak' key in The second parameter must be 'string'")),"delimiter"in e&&("string"==typeof e.delimiter||"boolean"==typeof e.delimiter&&!e.delimiter?(this.option.delimiter=e.delimiter,"boolean"===e.delimiter&&(this.column=!1)):Err("The 'delimiter' key in The second parameter must be 'string' or false 'boolean'")),"json"in e&&("boolean"==typeof e.json?i.json=e.json:Err("The 'json' key in The second parameter must be 'boolean'")),"bufferSize"in e&&(Number.isInteger(e.bufferSize)?e.bufferSize>=1024?i.bufferSize=e.bufferSize:Err("The 'bufferSize' parameter must be greater than or equal to 1024"):Err("The 'rowOffs' parameter must be an integer"))):Err("The second parameter must be an object"):this.option=i,t=this.fd?getColumns(this.data,this.option,this.csv):getColumns(this.data,this.option),this.hdr=t[0],this.starOffsRow=t[1],this.offs_n=[this.starOffsRow,0],this.oJson=!(!this.option.header||!this.option.json)&&this.hdr,this.info={header:this.option.header,linebreak:this.option.linebreak,quote:this.option.quote,col:this.column,d:this.option.delimiter,csv:this.csv,oJson:this.oJson}}function getInfo(){return{offset:this.offs_n[0],rowOffset:this.offs_n[1],option:this.option}}function offs_nRowwwwwwww(e,t,i){let s,r=0;if(t.header){if(i){let r,[n,o]=i,f=0,l=1;for(s=e.indexOf(t.linebreak);l&&-1==s;)[l,r]=getData(n,o,f),f+=l,s=(e+=r).indexOf(t.linebreak)}else s=e.indexOf(t.linebreak);r=-1==s?s=e.length:s+t.linebreak.length}return[r,0]}function getColumns(e,t,i){let s=!1,r=0;if(t.header){s=[];let n,o=t.delimiter.length;if(i){let s,[r,o]=i,f=0,l=1;for(n=e.indexOf(t.linebreak);l&&-1==n;)[l,s]=getData(r,o,f),f+=l,n=(e+=s).indexOf(t.linebreak)}else n=e.indexOf(t.linebreak);if(-1!=n){let i,f=e.slice(r,n),l=0,y=f.indexOf(t.delimiter);for(;-1!=y;)i=f.slice(l,y),s.push(i),l=y+o,y=f.indexOf(t.delimiter,l);s.push(f.slice(l))}r=-1==n?n=e.length:n+t.linebreak.length}return[s,r]}function parseCsv(e,t){let i,s,r=!0,n={header:!0,quote:!1,linebreak:"\r\n",delimiter:",",json:!1,bufferSize:1048576};if(null!=e)if(fs.existsSync(e)){s=fs.openSync(e,"r");let[t,r]=getData(s,n.bufferSize,0);i=r}else Err(`File "${e}" does not exists`);else Err("The first parameter 'file_path' must be string");return null!=t&&("object"==typeof t?("header"in t&&("boolean"==typeof t.header?n.header=t.header:Err("The 'header' key in The second parameter must be 'boolean'")),"quote"in t&&("boolean"==typeof t.quote?n.quote=t.quote:Err("The 'quote' key in The second parameter must be 'boolean'")),"linebreak"in t&&("string"==typeof t.linebreak?n.linebreak=t.linebreak:Err("The 'linebreak' key in The second parameter must be 'string'")),"delimiter"in t&&("string"==typeof t.delimiter||"boolean"==typeof t.delimiter&&!t.delimiter?(n.delimiter=t.delimiter,"boolean"===t.delimiter&&(r=!1)):Err("The 'delimiter' key in The second parameter must be 'string' or false 'boolean'")),"json"in t&&("boolean"==typeof t.json?n.json=t.json:Err("The 'json' key in The second parameter must be 'boolean'")),"bufferSize"in t&&(Number.isInteger(t.bufferSize)?t.bufferSize>=1024?n.bufferSize=t.bufferSize:Err("The 'bufferSize' parameter must be greater than or equal to 1024"):Err("The 'rowOffs' parameter must be an integer"))):Err("The second parameter must be an object")),new class{constructor(){let e;this.option=n,this.data=i,this.column=r,this.csv=[s,n.bufferSize],e=getColumns(this.data,this.option,this.csv),this.hdr=e[0],this.starOffsRow=e[1],this.offs_n=[this.starOffsRow,0],this.oJson=!(!this.option.header||!this.option.json)&&this.hdr,this.info={header:this.option.header,linebreak:this.option.linebreak,quote:this.option.quote,col:this.column,d:this.option.delimiter,csv:this.csv,oJson:this.oJson}}get=get;chunk=chunk;setRowOffset=setRowOffset;rowOffset=rowOffset;getInfo=getInfo;header=()=>this.hdr}}function parseText(e,t){let i,s={header:!0,quote:!1,linebreak:"\r\n",delimiter:",",json:!1};return null!=e||"string"!=typeof e?i=e:Err("The first parameter must be a file path string"),null!=t&&("object"==typeof t?("header"in t&&("boolean"==typeof t.header?s.header=t.header:Err("The 'header' key in The second parameter must be 'boolean'")),"quote"in t&&("boolean"==typeof t.quote?s.quote=t.quote:Err("The 'quote' key in The second parameter must be 'boolean'")),"linebreak"in t&&("string"==typeof t.linebreak?s.linebreak=t.linebreak:Err("The 'linebreak' key in The second parameter must be 'string'")),"delimiter"in t&&("string"==typeof t.delimiter||"boolean"==typeof t.delimiter&&!t.delimiter?(s.delimiter=t.delimiter,"boolean"===t.delimiter&&(this.column=!1)):Err("The 'delimiter' key in The second parameter must be 'string' or false 'boolean'")),"json"in t&&("boolean"==typeof t.json?s.json=t.json:Err("The 'json' key in The second parameter must be 'boolean'"))):Err("The second parameter must be an object")),new class{constructor(){let e;this.option=s,this.data=i,this.column=true,this.csv=!1,e=getColumns(this.data,this.option),this.hdr=e[0],this.starOffsRow=e[1],this.offs_n=[this.starOffsRow,0],this.oJson=!(!this.option.header||!this.option.json)&&this.hdr,this.info={header:this.option.header,linebreak:this.option.linebreak,quote:this.option.quote,col:this.column,d:this.option.delimiter,oJson:this.oJson}}get=get;chunk=chunk;setRowOffset=setRowOffset;rowOffset=rowOffset;resetOption=resetOption;getInfo=getInfo;header=()=>this.hdr}}module.exports={parseText:parseText,parseCsv:parseCsv};
|