select-csv 1.1.8 → 1.1.10
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/README.md +7 -7
- package/package.json +1 -1
- package/selectcsv.js +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ parse = parseText(
|
|
|
65
65
|
const result = parse.get(); //Return all rows
|
|
66
66
|
/*
|
|
67
67
|
{
|
|
68
|
-
time:1,
|
|
68
|
+
time:'1 ms',
|
|
69
69
|
header:["Index","User Id","First Name","Last Name","Sex"],
|
|
70
70
|
rows:[
|
|
71
71
|
["1","5f10e9D33fC5f2b","Sara","Mcguire","Female"],
|
|
@@ -318,7 +318,7 @@ const option = {
|
|
|
318
318
|
const result = parse.chunk(3)
|
|
319
319
|
/*
|
|
320
320
|
{
|
|
321
|
-
time: 0,
|
|
321
|
+
time: '0 ms',
|
|
322
322
|
header: [ 'Index', 'User Id', 'First Name', 'Last Name', 'Sex' ],
|
|
323
323
|
rows: [
|
|
324
324
|
{
|
|
@@ -380,7 +380,7 @@ var result;
|
|
|
380
380
|
result = parse.chunk(100000)
|
|
381
381
|
/*
|
|
382
382
|
{
|
|
383
|
-
time: 222,
|
|
383
|
+
time: '222 ms',
|
|
384
384
|
header: false,
|
|
385
385
|
rows: [
|
|
386
386
|
[ '198801', '1', '103', '100', '000000190', '0', '35843', '34353' ],
|
|
@@ -410,7 +410,7 @@ result = parse.chunk(100000)
|
|
|
410
410
|
result = parse.chunk(3) // Return row 100001,100002 and 100003 (Get rows from last offset saved)
|
|
411
411
|
/*
|
|
412
412
|
{
|
|
413
|
-
time: 1,
|
|
413
|
+
time: '1 ms',
|
|
414
414
|
header: false,
|
|
415
415
|
rows: [
|
|
416
416
|
[ '198801', '1', '326', '500', '841330000', '90', '81', '246' ],
|
|
@@ -426,7 +426,7 @@ const to = from + 5;
|
|
|
426
426
|
result = parse.rowOffset(from,to)
|
|
427
427
|
/*
|
|
428
428
|
{
|
|
429
|
-
time: 3743,
|
|
429
|
+
time: '3743 ms',
|
|
430
430
|
header: false,
|
|
431
431
|
rows: [
|
|
432
432
|
[
|
|
@@ -449,7 +449,7 @@ const to = from + 4;
|
|
|
449
449
|
result = parse.rowOffset(from,to)
|
|
450
450
|
/*
|
|
451
451
|
{
|
|
452
|
-
time: 44126,
|
|
452
|
+
time: '44126 ms',
|
|
453
453
|
header: false,
|
|
454
454
|
rows: [
|
|
455
455
|
[ '201412', '1', '125', '400', '283525000', '0', '160000', '6492' ],
|
|
@@ -464,7 +464,7 @@ result = parse.rowOffset(from,to)
|
|
|
464
464
|
result = parse.chunk(3) // Get rows from last offset saved ( row to,to+1 and to+2 )
|
|
465
465
|
/*
|
|
466
466
|
{
|
|
467
|
-
time: 29,
|
|
467
|
+
time: '29 ms',
|
|
468
468
|
header: false,
|
|
469
469
|
rows: [
|
|
470
470
|
[ '201412', '1', '125', '400', '400932000', '0', '18', '526' ],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "select-csv",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
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,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,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,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 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};
|