select-csv 1.1.20 โ 1.1.21
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/LICENSE.txt +21 -0
- package/README.md +132 -426
- package/package.json +37 -34
- package/selectcsv.js +254 -1288
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Housseyn Cheriet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,48 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
========================================
|
|
1
|
+
# select-csv
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
The fastest, simplest, and most powerful CSV parser for Node.js. Optimized for high performance and extreme memory efficiency when handling massive datasets (100M+ rows).
|
|
5
4
|
|
|
6
|
-
-
|
|
7
|
-
- Easy to use
|
|
8
|
-
- Parse CSV files directly (local)
|
|
9
|
-
- Fast mode
|
|
10
|
-
- Stream large files
|
|
11
|
-
- It is a synchronous package
|
|
12
|
-
- Uses chunks
|
|
13
|
-
- Uses row offset (get rows from line x to line x+n)
|
|
14
|
-
- Returns rows (with columns) or lines (without columns)
|
|
15
|
-
- No external dependencies
|
|
16
|
-
- Flexible with lots of options (header, quote, line break, delimiter, bufferSize in CSV file, Rows in an array or json array)
|
|
17
|
-
- One of the only parsers that correctly handles line-breaks and quotations
|
|
5
|
+
`select-csv` converts `.csv` files into arrays, JSON objects, or raw lines. It provides two main functions, `parseCsv` (for local files) and `parseText` (for raw strings), both sharing the same methods and features.
|
|
18
6
|
|
|
19
|
-
|
|
7
|
+
## โจ Key Features
|
|
8
|
+
- **Ultra-Lightweight:** Package size is less than 30 KB.
|
|
9
|
+
- **Fast Mode:** Synchronous execution for maximum speed and zero overhead.
|
|
10
|
+
- **Memory Efficient:** Streams large files using chunks and row offsets instead of loading the entire file into RAM.
|
|
11
|
+
- **Robust Parsing:** Correct handling of complex line-breaks (`\r\n`, `\n`) and nested quotations.
|
|
12
|
+
- **No Dependencies:** Zero external dependencies for maximum security and stability.
|
|
13
|
+
- **Flexible Options:** Highly customizable (headers, quotes, delimiters, buffers).
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
-------
|
|
15
|
+
---
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
can be installed with the following command:
|
|
17
|
+
## ๐ Installation
|
|
26
18
|
|
|
27
|
-
|
|
19
|
+
```bash
|
|
20
|
+
npm install select-csv
|
|
21
|
+
๐ Usage Examples
|
|
22
|
+
Initialization
|
|
23
|
+
JavaScript
|
|
28
24
|
|
|
25
|
+
const { parseCsv, parseText } = require("select-csv");
|
|
26
|
+
let parse;
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
Usage:
|
|
32
|
-
-------
|
|
33
|
-
|
|
34
|
-
Here there are clearly different examples
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
const {parseCsv,parseText} = require("select-csv");
|
|
39
|
-
|
|
40
|
-
var parse;
|
|
41
|
-
|
|
42
|
-
// First create object from .csv file
|
|
28
|
+
// 1. Create object from a local .csv file
|
|
43
29
|
parse = parseCsv('file_path.csv');
|
|
44
30
|
|
|
45
|
-
//
|
|
31
|
+
// 2. Create object from raw text string
|
|
46
32
|
parse = parseText(
|
|
47
33
|
`Index,User Id,First Name,Last Name,Sex
|
|
48
34
|
1,5f10e9D33fC5f2b,Sara,Mcguire,Female
|
|
@@ -56,457 +42,177 @@ parse = parseText(
|
|
|
56
42
|
9,F563CcbFBfEcf5a,Emma,Robinson,Female
|
|
57
43
|
10,f2dceFc00F62542,Pedro,Cordova,Male`
|
|
58
44
|
);
|
|
45
|
+
Get All Rows
|
|
46
|
+
JavaScript
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
* If you want to get just the header :
|
|
64
|
-
```js
|
|
65
|
-
const result = parse.header();
|
|
48
|
+
const result = parse.get();
|
|
66
49
|
/*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* If you want to get all rows :
|
|
73
|
-
```js
|
|
74
|
-
const result = parse.get(); //Return all rows
|
|
75
|
-
/*
|
|
76
|
-
{
|
|
77
|
-
time:'1 ms',
|
|
78
|
-
header:["Index","User Id","First Name","Last Name","Sex"],
|
|
79
|
-
rows:[
|
|
50
|
+
Returns:
|
|
51
|
+
{
|
|
52
|
+
time: '1 ms',
|
|
53
|
+
header: ["Index","User Id","First Name","Last Name","Sex"],
|
|
54
|
+
rows: [
|
|
80
55
|
["1","5f10e9D33fC5f2b","Sara","Mcguire","Female"],
|
|
81
56
|
["2","751cD1cbF77e005","Alisha","Hebert","Male"],
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
["7","FCdfFf08196f633","Collin","Allison","Male"],
|
|
87
|
-
["8","356279dAa0F7CbD","Nicholas","Branch","Male"],
|
|
88
|
-
["9","F563CcbFBfEcf5a","Emma","Robinson","Female"],
|
|
89
|
-
["10","f2dceFc00F62542","Pedro","Cordova","Male"]
|
|
90
|
-
],
|
|
91
|
-
row_count:10
|
|
92
|
-
}
|
|
57
|
+
...
|
|
58
|
+
],
|
|
59
|
+
row_count: 10
|
|
60
|
+
}
|
|
93
61
|
*/
|
|
62
|
+
Parsing in Chunks
|
|
63
|
+
The chunk(c) method allows you to fetch a specific number of rows. The parser saves the current offset automatically.
|
|
94
64
|
|
|
95
|
-
|
|
65
|
+
JavaScript
|
|
96
66
|
|
|
97
|
-
|
|
67
|
+
let result;
|
|
98
68
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
result = parse.chunk(c)
|
|
102
|
-
//The 'c' parameter must be an integer and greater than or equal to 1
|
|
103
|
-
|
|
104
|
-
//Examples:
|
|
105
|
-
result = parse.chunk(2) //Return row 0 and 1
|
|
69
|
+
// Get rows 0 and 1
|
|
70
|
+
result = parse.chunk(2);
|
|
106
71
|
/*
|
|
107
72
|
{
|
|
108
|
-
time:
|
|
109
|
-
header: [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
110
|
-
rows: [
|
|
73
|
+
"time": "0 ms",
|
|
74
|
+
"header": [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
75
|
+
"rows": [
|
|
111
76
|
[ "1", "5f10e9D33fC5f2b", "Sara", "Mcguire", "Female" ],
|
|
112
77
|
[ "2", "751cD1cbF77e005", "Alisha", "Hebert", "Male" ]
|
|
113
78
|
],
|
|
114
|
-
"row_count
|
|
115
|
-
}
|
|
116
|
-
*/
|
|
117
|
-
|
|
118
|
-
result = parse.chunk(3) //Return row 2,3 and 4 (Get rows from last offset saved)
|
|
119
|
-
/*
|
|
120
|
-
{
|
|
121
|
-
time: '0 ms',
|
|
122
|
-
header: [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
123
|
-
rows: [
|
|
124
|
-
[ "3", "DcEFDB2D2e62bF9", "Gwendolyn", "Sheppard", "Male" ],
|
|
125
|
-
[ "4", "C88661E02EEDA9e", "Kristine", "Mccann", "Female" ],
|
|
126
|
-
[ "5", "fafF1aBDebaB2a6", "Bobby", "Pittman", "Female" ]
|
|
127
|
-
],
|
|
128
|
-
"row_count:": 3
|
|
129
|
-
}
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
result = parse.chunk(1) //Return row 5 (Get rows from last offset saved)
|
|
133
|
-
/*
|
|
134
|
-
{
|
|
135
|
-
time: '0 ms',
|
|
136
|
-
header: [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
137
|
-
rows: [
|
|
138
|
-
[ "6", "BdDb6C8Af309202", "Calvin", "Ramsey", "Female" ]
|
|
139
|
-
],
|
|
140
|
-
"row_count:": 1
|
|
79
|
+
"row_count": 2
|
|
141
80
|
}
|
|
142
81
|
*/
|
|
143
82
|
|
|
83
|
+
// Get rows 2, 3, and 4 (continues from last offset)
|
|
84
|
+
result = parse.chunk(3);
|
|
144
85
|
|
|
145
|
-
|
|
86
|
+
// Get row 5
|
|
87
|
+
result = parse.chunk(1);
|
|
88
|
+
Row Offsets (Specific Range)
|
|
89
|
+
Use rowOffset(from, to) to fetch a specific range of rows.
|
|
146
90
|
|
|
147
|
-
|
|
91
|
+
JavaScript
|
|
148
92
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
result = parse.rowOffset(from)
|
|
152
|
-
// The 'from' parameter must be an integer and greater than or equal to 0
|
|
93
|
+
// Get all rows from the 6th row to the last row
|
|
94
|
+
let result = parse.rowOffset(6);
|
|
153
95
|
|
|
154
|
-
//
|
|
155
|
-
result = parse.rowOffset(
|
|
156
|
-
// The 'to' parameter must be an integer and greater than or equal to 1
|
|
157
|
-
|
|
158
|
-
//Examples:
|
|
159
|
-
result = parse.rowOffset(6) //Returns all rows from the sixth row to the last row
|
|
96
|
+
// Get rows from 5th to 8th row
|
|
97
|
+
result = parse.rowOffset(5, 8);
|
|
160
98
|
/*
|
|
161
99
|
{
|
|
162
|
-
time:
|
|
163
|
-
header: [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
164
|
-
rows: [
|
|
165
|
-
[ "7", "FCdfFf08196f633", "Collin", "Allison", "Male" ],
|
|
166
|
-
[ "8", "356279dAa0F7CbD", "Nicholas", "Branch", "Male" ],
|
|
167
|
-
[ "9", "F563CcbFBfEcf5a", "Emma", "Robinson", "Female" ],
|
|
168
|
-
[ "10", "f2dceFc00F62542", "Pedro", "Cordova", "Male" ]
|
|
169
|
-
],
|
|
170
|
-
"row_count:": 4
|
|
171
|
-
}
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
|
-
result = parse.rowOffset(5,8) //Returns all rows from 5th to 8th row
|
|
175
|
-
/*
|
|
176
|
-
{
|
|
177
|
-
time: '1 ms',
|
|
178
|
-
header: [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
179
|
-
rows: [
|
|
100
|
+
"time": "1 ms",
|
|
101
|
+
"header": [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
102
|
+
"rows": [
|
|
180
103
|
[ "6", "BdDb6C8Af309202", "Calvin", "Ramsey", "Female" ],
|
|
181
104
|
[ "7", "FCdfFf08196f633", "Collin", "Allison", "Male" ],
|
|
182
105
|
[ "8", "356279dAa0F7CbD", "Nicholas", "Branch", "Male" ]
|
|
183
106
|
],
|
|
184
|
-
"row_count
|
|
185
|
-
}
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
* If you want to change the row offset :
|
|
193
|
-
|
|
194
|
-
```js
|
|
195
|
-
parse.setRowOffset(offs)
|
|
196
|
-
|
|
197
|
-
// The 'offs' parameter must be an integer and greater than or equal to 0.
|
|
198
|
-
|
|
199
|
-
// If the offset exists, return [offset,row_number].
|
|
200
|
-
result = parse.setRowOffset(5)
|
|
201
|
-
/*
|
|
202
|
-
[236,5]
|
|
203
|
-
*/
|
|
204
|
-
result = parse.chunk(1) // Get rows from last offset saved
|
|
205
|
-
/*
|
|
206
|
-
{
|
|
207
|
-
time: '0 ms',
|
|
208
|
-
header: [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
209
|
-
rows: [
|
|
210
|
-
[ "6", "BdDb6C8Af309202", "Calvin", "Ramsey", "Female" ]
|
|
211
|
-
],
|
|
212
|
-
"row_count:": 1
|
|
213
|
-
}
|
|
214
|
-
*/
|
|
215
|
-
|
|
216
|
-
// If not , returns false and the offset not changed.
|
|
217
|
-
result = parse.setRowOffset(20)
|
|
218
|
-
/*
|
|
219
|
-
false
|
|
220
|
-
*/
|
|
221
|
-
result = parse.chunk(1) // Get rows from last offset saved
|
|
222
|
-
/*
|
|
223
|
-
{
|
|
224
|
-
time: '0 ms',
|
|
225
|
-
header: [ "Index", "User Id", "First Name", "Last Name", "Sex" ],
|
|
226
|
-
rows: [
|
|
227
|
-
[ "7", "FCdfFf08196f633", "Collin", "Allison", "Male" ]
|
|
228
|
-
],
|
|
229
|
-
"row_count:": 1
|
|
107
|
+
"row_count": 3
|
|
230
108
|
}
|
|
231
109
|
*/
|
|
110
|
+
Manual Offset Control
|
|
111
|
+
You can manually set the row pointer using setRowOffset(offs).
|
|
232
112
|
|
|
113
|
+
JavaScript
|
|
233
114
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
* The default object option :
|
|
237
|
-
|
|
238
|
-
```js
|
|
239
|
-
{
|
|
240
|
-
'header': true,
|
|
241
|
-
'quote': false,
|
|
242
|
-
'linebreak': '\r\n',
|
|
243
|
-
'delimiter': ",",
|
|
244
|
-
'json': false,
|
|
245
|
-
'bufferSize':1024*1024
|
|
246
|
-
}
|
|
247
|
-
// delimiter: (String: get rows containing columns, false: get lines without columns)
|
|
248
|
-
//bufferSize: It only works with a CSV file, which is the maximum number of characters that can be read at a time, the minimum value is 1024
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
* If you want to use specific option :
|
|
252
|
-
```js
|
|
253
|
-
var option = {
|
|
254
|
-
'header': false, /* or true */
|
|
255
|
-
'quote': true, /* or false */
|
|
256
|
-
'linebreak': '\n', /* '\n' or '\r' or any other string */
|
|
257
|
-
'delimiter': "," /* ';' or any other string or false */
|
|
258
|
-
'json': false /* or true */
|
|
259
|
-
'bufferSize':2000 /* It only works with a CSV file */
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
var parse;
|
|
263
|
-
// Create object from .csv file
|
|
264
|
-
parse = parseCsv('file_path.csv',option);
|
|
115
|
+
// If offset exists, returns [byte_offset, row_number]
|
|
116
|
+
let status = parse.setRowOffset(5); // [236, 5]
|
|
265
117
|
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
-
`Index,User Id,First Name,Last Name,Sex
|
|
269
|
-
1,5f10e9D33fC5f2b,Sara,Mcguire,Female
|
|
270
|
-
2,751cD1cbF77e005,Alisha,Hebert,Male
|
|
271
|
-
3,DcEFDB2D2e62bF9,Gwendolyn,Sheppard,Male`
|
|
272
|
-
, option);
|
|
118
|
+
// Get row 6 after setting offset
|
|
119
|
+
let nextRow = parse.chunk(1);
|
|
273
120
|
|
|
121
|
+
// Returns false if row number does not exist
|
|
122
|
+
let fail = parse.setRowOffset(20); // false
|
|
123
|
+
โ๏ธ Configuration Options
|
|
124
|
+
The default configuration is:
|
|
274
125
|
|
|
275
|
-
|
|
276
|
-
/*
|
|
277
|
-
{
|
|
278
|
-
time: '0 ms',
|
|
279
|
-
header: false,
|
|
280
|
-
rows: [
|
|
281
|
-
[ "2", "751cD1cbF77e005", "Alisha", "Hebert", "Male" ]
|
|
282
|
-
],
|
|
283
|
-
"row_count:": 1
|
|
284
|
-
}
|
|
285
|
-
*/
|
|
126
|
+
JavaScript
|
|
286
127
|
|
|
287
|
-
option = {
|
|
288
|
-
'header': true,
|
|
289
|
-
'delimiter': false
|
|
290
|
-
}
|
|
291
|
-
// delimiter: (String: get rows containing columns, false: get lines without columns)
|
|
292
|
-
/*
|
|
293
128
|
{
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
129
|
+
'header': true, // Treat first row as header
|
|
130
|
+
'quote': false, // Handle quoted values
|
|
131
|
+
'linebreak': '\r\n', // Custom line break
|
|
132
|
+
'delimiter': ",", // Column separator (set to false for raw lines)
|
|
133
|
+
'json': false, // Return rows as JSON objects (requires header: true)
|
|
134
|
+
'bufferSize': 1048576 // 1MB buffer (for parseCsv only)
|
|
300
135
|
}
|
|
301
|
-
|
|
136
|
+
Custom Options Example:
|
|
137
|
+
JavaScript
|
|
302
138
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
* If you want to reset option after multiple uses of your code :
|
|
306
|
-
```js
|
|
307
|
-
const option = { // Just an exapmle
|
|
139
|
+
let option = {
|
|
308
140
|
'header': false,
|
|
309
141
|
'quote': true,
|
|
310
|
-
'linebreak': '\n'
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
```
|
|
142
|
+
'linebreak': '\n',
|
|
143
|
+
'delimiter': ",",
|
|
144
|
+
'json': false,
|
|
145
|
+
'bufferSize': 2000
|
|
146
|
+
};
|
|
317
147
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const option = {
|
|
322
|
-
'header': true,
|
|
323
|
-
'json': true
|
|
324
|
-
}
|
|
148
|
+
parse = parseCsv('data.csv', option);
|
|
149
|
+
Working with JSON Output:
|
|
150
|
+
If you want the result as an array of objects based on the header:
|
|
325
151
|
|
|
152
|
+
JavaScript
|
|
326
153
|
|
|
327
|
-
const
|
|
154
|
+
const parse = parseCsv('data.csv', { 'header': true, 'json': true });
|
|
155
|
+
const result = parse.get();
|
|
328
156
|
/*
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
{
|
|
334
|
-
Index: '1',
|
|
335
|
-
'User Id': '5f10e9D33fC5f2b',
|
|
336
|
-
'First Name': 'Sara',
|
|
337
|
-
'Last Name': 'Mcguire',
|
|
338
|
-
Sex: 'Female'
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
Index: '2',
|
|
342
|
-
'User Id': '751cD1cbF77e005',
|
|
343
|
-
'First Name': 'Alisha',
|
|
344
|
-
'Last Name': 'Hebert',
|
|
345
|
-
Sex: 'Male'
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
Index: '3',
|
|
349
|
-
'User Id': 'DcEFDB2D2e62bF9',
|
|
350
|
-
'First Name': 'Gwendolyn',
|
|
351
|
-
'Last Name': 'Sheppard',
|
|
352
|
-
Sex: 'Male'
|
|
353
|
-
}
|
|
354
|
-
],
|
|
355
|
-
row_count: 3
|
|
356
|
-
}
|
|
157
|
+
rows: [
|
|
158
|
+
{ "Index": "1", "User Id": "5f10e9D33fC5f2b", "First Name": "Sara", ... },
|
|
159
|
+
...
|
|
160
|
+
]
|
|
357
161
|
*/
|
|
162
|
+
Raw Lines (No Delimiter):
|
|
163
|
+
If delimiter is set to false, the parser returns full lines as strings.
|
|
358
164
|
|
|
165
|
+
JavaScript
|
|
359
166
|
|
|
360
|
-
|
|
167
|
+
parse.resetOption({ 'header': true, 'delimiter': false });
|
|
168
|
+
let result = parse.rowOffset(2);
|
|
169
|
+
// rows: [ ["2,751cD1cbF77e005,Alisha,Hebert,Male"] ]
|
|
170
|
+
๐ Benchmarking Large Files
|
|
171
|
+
Tested with a 100 Million Row Dataset:
|
|
361
172
|
|
|
362
|
-
|
|
363
|
-
```js
|
|
173
|
+
JavaScript
|
|
364
174
|
|
|
365
|
-
const
|
|
366
|
-
/*
|
|
367
|
-
{
|
|
368
|
-
"offset": 275,
|
|
369
|
-
"rowOffset": 7,
|
|
370
|
-
"option": {
|
|
371
|
-
"header": false,
|
|
372
|
-
"quote": false,
|
|
373
|
-
"linebreak": "\n",
|
|
374
|
-
"delimiter": false
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
*/
|
|
175
|
+
const parse = parseCsv('huge-data.csv', {"header": false});
|
|
378
176
|
|
|
379
|
-
|
|
177
|
+
// Fetch 100,000 rows
|
|
178
|
+
let result = parse.chunk(100000); // ~222ms
|
|
380
179
|
|
|
381
|
-
|
|
382
|
-
(
|
|
180
|
+
// Jump to row 30,000,000
|
|
181
|
+
result = parse.rowOffset(30000000, 30000005); // ~3743ms
|
|
383
182
|
|
|
183
|
+
// Jump to row 90,000,000
|
|
184
|
+
result = parse.rowOffset(90000000, 90000004); // ~44126ms
|
|
384
185
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const parse = parseCsv('100-million-data.csv',{"header": false});
|
|
388
|
-
var result;
|
|
389
|
-
result = parse.chunk(100000)
|
|
186
|
+
// Current metadata
|
|
187
|
+
console.log(parse.getInfo());
|
|
390
188
|
/*
|
|
391
189
|
{
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
[ '198801', '1', '103', '100', '000000190', '0', '35843', '34353' ],
|
|
396
|
-
[ '198801', '1', '103', '100', '120991000', '0', '1590', '4154' ],
|
|
397
|
-
[ '198801', '1', '103', '100', '210390900', '0', '4500', '2565' ],
|
|
398
|
-
.
|
|
399
|
-
.
|
|
400
|
-
.
|
|
401
|
-
[ '198801', '1', '103', '100', '391590000', '0', '95000', '7850' ],
|
|
402
|
-
[ '198801', '1', '103', '100', '391620000', '0', '1000', '404' ],
|
|
403
|
-
[ '198801', '1', '103', '100', '391723000', '0', '545', '479' ],
|
|
404
|
-
[ '198801', '1', '103', '100', '391732100', '0', '24', '393' ],
|
|
405
|
-
[ '198801', '1', '103', '100', '391732900', '0', '60', '758' ],
|
|
406
|
-
[ '198801', '1', '103', '100', '391810100', '0', '1935', '1042' ],
|
|
407
|
-
[ '198801', '1', '103', '100', '391910200', '0', '510', '1303' ],
|
|
408
|
-
[ '198801', '1', '103', '100', '391910300', '0', '133', '379' ],
|
|
409
|
-
[ '198801', '1', '103', '100', '391990300', '0', '450', '1668' ],
|
|
410
|
-
[ '198801', '1', '103', '100', '391990500', '0', '942', '1721' ],
|
|
411
|
-
[ '198801', '1', '103', '100', '391990900', '0', '40', '235' ],
|
|
412
|
-
[ '198801', '1', '103', '100', '392030000', '0', '406', '652' ],
|
|
413
|
-
... 99900 more items
|
|
414
|
-
],
|
|
415
|
-
row_count: 100000
|
|
416
|
-
}
|
|
417
|
-
*/
|
|
418
|
-
|
|
419
|
-
result = parse.chunk(3) // Return row 100001,100002 and 100003 (Get rows from last offset saved)
|
|
420
|
-
/*
|
|
421
|
-
{
|
|
422
|
-
time: '1 ms',
|
|
423
|
-
header: false,
|
|
424
|
-
rows: [
|
|
425
|
-
[ '198801', '1', '326', '500', '841330000', '90', '81', '246' ],
|
|
426
|
-
[ '198801', '1', '326', '500', '841510000', '0', '35', '1366' ],
|
|
427
|
-
[ '198801', '1', '326', '500', '841582100', '0', '6', '334' ]
|
|
428
|
-
],
|
|
429
|
-
row_count: 3
|
|
430
|
-
}
|
|
431
|
-
*/
|
|
432
|
-
|
|
433
|
-
const from = 1000*1000*30;
|
|
434
|
-
const to = from + 5;
|
|
435
|
-
result = parse.rowOffset(from,to)
|
|
436
|
-
/*
|
|
437
|
-
{
|
|
438
|
-
time: '3743 ms',
|
|
439
|
-
header: false,
|
|
440
|
-
rows: [
|
|
441
|
-
[
|
|
442
|
-
'199804', '2',
|
|
443
|
-
'213', '502',
|
|
444
|
-
'848130000', '16035',
|
|
445
|
-
'746', '8380'
|
|
446
|
-
],
|
|
447
|
-
[ '199804', '2', '213', '502', '848140000', '168', '152', '1891' ],
|
|
448
|
-
[ '199804', '2', '213', '502', '848180010', '77', '404', '1366' ],
|
|
449
|
-
[ '199804', '2', '213', '502', '848190000', '0', '131', '570' ],
|
|
450
|
-
[ '199804', '2', '213', '502', '848230000', '300', '4', '882' ]
|
|
451
|
-
],
|
|
452
|
-
row_count: 5
|
|
190
|
+
offset: 3599945660,
|
|
191
|
+
rowOffset: 90000008,
|
|
192
|
+
option: { ... }
|
|
453
193
|
}
|
|
454
194
|
*/
|
|
195
|
+
๐งช Advanced Methods
|
|
196
|
+
getInfo()
|
|
197
|
+
Returns current byte offset, row offset, and active options.
|
|
455
198
|
|
|
456
|
-
|
|
457
|
-
const to = from + 4;
|
|
458
|
-
result = parse.rowOffset(from,to)
|
|
459
|
-
/*
|
|
460
|
-
{
|
|
461
|
-
time: '44126 ms',
|
|
462
|
-
header: false,
|
|
463
|
-
rows: [
|
|
464
|
-
[ '201412', '1', '125', '400', '283525000', '0', '160000', '6492' ],
|
|
465
|
-
[ '201412', '1', '125', '400', '390740100', '0', '17500', '5579' ],
|
|
466
|
-
[ '201412', '1', '125', '400', '390950000', '0', '36000', '21423' ],
|
|
467
|
-
[ '201412', '1', '125', '400', '392329000', '0', '520', '1413' ]
|
|
468
|
-
],
|
|
469
|
-
row_count: 4
|
|
470
|
-
}
|
|
471
|
-
*/
|
|
199
|
+
JavaScript
|
|
472
200
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
time: '29 ms',
|
|
477
|
-
header: false,
|
|
478
|
-
rows: [
|
|
479
|
-
[ '201412', '1', '125', '400', '400932000', '0', '18', '526' ],
|
|
480
|
-
[ '201412', '1', '125', '400', '401110000', '173', '1735', '1197' ],
|
|
481
|
-
[ '201412', '1', '125', '400', '401120000', '133', '1707', '1099' ]
|
|
482
|
-
],
|
|
483
|
-
row_count: 3
|
|
484
|
-
}
|
|
485
|
-
*/
|
|
201
|
+
const info = parse.getInfo();
|
|
202
|
+
resetOption(newOptions)
|
|
203
|
+
Clears internal state and re-initializes the parser with new settings.
|
|
486
204
|
|
|
487
|
-
|
|
488
|
-
/*
|
|
489
|
-
{
|
|
490
|
-
offset: 3599945660,
|
|
491
|
-
rowOffset: 90000008,
|
|
492
|
-
option: {
|
|
493
|
-
header: false,
|
|
494
|
-
quote: false,
|
|
495
|
-
linebreak: '\r\n',
|
|
496
|
-
delimiter: ',',
|
|
497
|
-
bufferSize: 1048576
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
*/
|
|
501
|
-
```
|
|
205
|
+
JavaScript
|
|
502
206
|
|
|
503
|
-
|
|
207
|
+
parse.resetOption({ 'header': false, 'quote': true });
|
|
208
|
+
header()
|
|
209
|
+
Returns the detected CSV header array.
|
|
504
210
|
|
|
505
|
-
|
|
211
|
+
JavaScript
|
|
506
212
|
|
|
507
|
-
|
|
213
|
+
const headers = parse.header();
|
|
214
|
+
๐ค Contributing
|
|
215
|
+
Found a bug or have a suggestion? Open an issue at GitHub Issues.
|
|
508
216
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
I can't start thinking of introducing it until I understand how it helps you ๐
|
|
512
|
-
* **Reporting a bug:** If you could provide a runnable code snippet that reproduces the bug, it would be very helpful!
|
|
217
|
+
๐ License
|
|
218
|
+
This project is licensed under the MIT License.
|