token-goat 2.9.12 → 2.9.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.
Files changed (45) hide show
  1. package/README.md +20 -1
  2. package/dist/token-goat-chunk-2ESBO4IN.mjs +209 -0
  3. package/dist/token-goat-chunk-3BTK54F3.mjs +1733 -0
  4. package/dist/{token-goat-chunk-6NIGPPN6.mjs → token-goat-chunk-3XQPEJMV.mjs} +1 -1
  5. package/dist/token-goat-chunk-4SDX3QP3.mjs +122 -0
  6. package/dist/token-goat-chunk-7OGKZ7AP.mjs +142 -0
  7. package/dist/token-goat-chunk-AH6QILZM.mjs +26 -0
  8. package/dist/token-goat-chunk-AMYCQJX4.mjs +1548 -0
  9. package/dist/{token-goat-chunk-OTW7LC4Y.mjs → token-goat-chunk-ASVVF4JV.mjs} +13 -10
  10. package/dist/{token-goat-chunk-GCXX67HM.mjs → token-goat-chunk-DAMXYVIW.mjs} +12477 -12156
  11. package/dist/token-goat-chunk-DBNY4RLN.mjs +308 -0
  12. package/dist/token-goat-chunk-EG3663UT.mjs +226 -0
  13. package/dist/token-goat-chunk-EZNVAIR3.mjs +21 -0
  14. package/dist/token-goat-chunk-GMOUBOX4.mjs +386 -0
  15. package/dist/{token-goat-chunk-6F5TLJC7.mjs → token-goat-chunk-HF6H7RNK.mjs} +1 -1
  16. package/dist/{token-goat-chunk-GM6QZWCF.mjs → token-goat-chunk-IT6O3PNN.mjs} +2660 -6877
  17. package/dist/token-goat-chunk-NEI4NC54.mjs +424 -0
  18. package/dist/token-goat-chunk-O5WAMISC.mjs +167 -0
  19. package/dist/{token-goat-chunk-LHLQFGWQ.mjs → token-goat-chunk-OMNQUUIT.mjs} +9 -27
  20. package/dist/{token-goat-chunk-SF2CKCFQ.mjs → token-goat-chunk-PGGDW7DZ.mjs} +30 -13
  21. package/dist/token-goat-chunk-POBYR64E.mjs +1632 -0
  22. package/dist/token-goat-chunk-PRJVGIC5.mjs +58 -0
  23. package/dist/{token-goat-chunk-4CK445AW.mjs → token-goat-chunk-RUDOKYPJ.mjs} +10074 -9765
  24. package/dist/token-goat-chunk-SAQ5PG4L.mjs +2634 -0
  25. package/dist/token-goat-chunk-T2IWWTHB.mjs +3155 -0
  26. package/dist/{token-goat-chunk-TOGYS5A7.mjs → token-goat-chunk-VZYD4OZB.mjs} +1469 -5752
  27. package/dist/token-goat-chunk-XEH6KBWW.mjs +23 -0
  28. package/dist/token-goat-chunk-XQF5J25J.mjs +33 -0
  29. package/dist/token-goat-chunk-XTQAOTSO.mjs +89 -0
  30. package/dist/{token-goat-chunk-THLHC6QJ.mjs → token-goat-chunk-XVZ4MNQC.mjs} +614 -603
  31. package/dist/token-goat-chunk-Y4AFKTHK.mjs +22 -0
  32. package/dist/token-goat-chunk-YHGTGG6K.mjs +396 -0
  33. package/dist/{token-goat-chunk-SBYRP3X4.mjs → token-goat-chunk-YTQHZJXW.mjs} +61 -27
  34. package/dist/token-goat-chunk-Z6UXPYJA.mjs +62 -0
  35. package/dist/token-goat-chunk-ZD4EM4LR.mjs +30 -0
  36. package/dist/token-goat-chunk-ZFM4PWXL.mjs +585 -0
  37. package/dist/{token-goat-chunk-A6QTLAWO.mjs → token-goat-chunk-ZYNNQ36L.mjs} +128 -328
  38. package/dist/token-goat-hook.mjs +12 -6
  39. package/dist/token-goat.core.mjs +22 -7
  40. package/docs/cli.md +12 -8
  41. package/docs/security.md +1 -1
  42. package/package.json +4 -2
  43. package/dist/token-goat-chunk-HKFOH6JH.mjs +0 -28
  44. package/dist/token-goat-chunk-LOCOX2ML.mjs +0 -3564
  45. package/dist/token-goat-chunk-VRWX6QYW.mjs +0 -24
@@ -0,0 +1,1733 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ init_define_import_meta_env
5
+ } from "./token-goat-chunk-A37V4PBF.mjs";
6
+
7
+ // node_modules/csv-parse/lib/sync.js
8
+ init_define_import_meta_env();
9
+
10
+ // node_modules/csv-parse/lib/api/index.js
11
+ init_define_import_meta_env();
12
+
13
+ // node_modules/csv-parse/lib/api/normalize_columns_array.js
14
+ init_define_import_meta_env();
15
+
16
+ // node_modules/csv-parse/lib/api/CsvError.js
17
+ init_define_import_meta_env();
18
+ var CsvError = class _CsvError extends Error {
19
+ constructor(code, message, options, ...contexts) {
20
+ if (Array.isArray(message)) message = message.join(" ").trim();
21
+ super(message);
22
+ if (Error.captureStackTrace !== void 0) {
23
+ Error.captureStackTrace(this, _CsvError);
24
+ }
25
+ this.code = code;
26
+ for (const context of contexts) {
27
+ for (const key in context) {
28
+ const value = context[key];
29
+ this[key] = Buffer.isBuffer(value) ? value.toString(options.encoding) : value == null ? value : JSON.parse(JSON.stringify(value));
30
+ }
31
+ }
32
+ }
33
+ };
34
+
35
+ // node_modules/csv-parse/lib/utils/is_object.js
36
+ init_define_import_meta_env();
37
+ var is_object = function(obj) {
38
+ return typeof obj === "object" && obj !== null && !Array.isArray(obj);
39
+ };
40
+
41
+ // node_modules/csv-parse/lib/api/normalize_columns_array.js
42
+ var normalize_columns_array = function(columns) {
43
+ const normalizedColumns = [];
44
+ for (let i = 0, l = columns.length; i < l; i++) {
45
+ const column = columns[i];
46
+ if (column === void 0 || column === null || column === false) {
47
+ normalizedColumns[i] = { disabled: true };
48
+ } else if (typeof column === "string" || typeof column === "number") {
49
+ normalizedColumns[i] = { name: `${column}` };
50
+ } else if (is_object(column)) {
51
+ if (typeof column.name !== "string") {
52
+ throw new CsvError("CSV_OPTION_COLUMNS_MISSING_NAME", [
53
+ "Option columns missing name:",
54
+ `property "name" is required at position ${i}`,
55
+ "when column is an object literal"
56
+ ]);
57
+ }
58
+ normalizedColumns[i] = column;
59
+ } else {
60
+ throw new CsvError("CSV_INVALID_COLUMN_DEFINITION", [
61
+ "Invalid column definition:",
62
+ "expect a string or a literal object,",
63
+ `got ${JSON.stringify(column)} at position ${i}`
64
+ ]);
65
+ }
66
+ }
67
+ return normalizedColumns;
68
+ };
69
+
70
+ // node_modules/csv-parse/lib/api/init_state.js
71
+ init_define_import_meta_env();
72
+
73
+ // node_modules/csv-parse/lib/utils/ResizeableBuffer.js
74
+ init_define_import_meta_env();
75
+ var ResizeableBuffer = class {
76
+ constructor(size = 100) {
77
+ this.size = size;
78
+ this.length = 0;
79
+ this.buf = Buffer.allocUnsafe(size);
80
+ }
81
+ prepend(val) {
82
+ if (Buffer.isBuffer(val)) {
83
+ const length = this.length + val.length;
84
+ if (length >= this.size) {
85
+ this.resize();
86
+ if (length >= this.size) {
87
+ throw Error("INVALID_BUFFER_STATE");
88
+ }
89
+ }
90
+ const buf = this.buf;
91
+ this.buf = Buffer.allocUnsafe(this.size);
92
+ val.copy(this.buf, 0);
93
+ buf.copy(this.buf, val.length);
94
+ this.length += val.length;
95
+ } else {
96
+ const length = this.length++;
97
+ if (length === this.size) {
98
+ this.resize();
99
+ }
100
+ const buf = this.clone();
101
+ this.buf[0] = val;
102
+ buf.copy(this.buf, 1, 0, length);
103
+ }
104
+ }
105
+ append(val) {
106
+ const length = this.length++;
107
+ if (length === this.size) {
108
+ this.resize();
109
+ }
110
+ this.buf[length] = val;
111
+ }
112
+ clone() {
113
+ return Buffer.from(this.buf.slice(0, this.length));
114
+ }
115
+ resize() {
116
+ const length = this.length;
117
+ this.size = this.size * 2;
118
+ const buf = Buffer.allocUnsafe(this.size);
119
+ this.buf.copy(buf, 0, 0, length);
120
+ this.buf = buf;
121
+ }
122
+ toString(encoding) {
123
+ if (encoding) {
124
+ return this.buf.toString(encoding, 0, this.length);
125
+ } else {
126
+ return Uint8Array.prototype.slice.call(this.buf.slice(0, this.length));
127
+ }
128
+ }
129
+ toJSON() {
130
+ return this.toString("utf8");
131
+ }
132
+ reset() {
133
+ this.length = 0;
134
+ }
135
+ };
136
+ var ResizeableBuffer_default = ResizeableBuffer;
137
+
138
+ // node_modules/csv-parse/lib/api/init_state.js
139
+ var init_state = function(options) {
140
+ const timchars = [
141
+ // Basic Latin
142
+ 32,
143
+ // [Space](https://www.fileformat.info/info/unicode/char/0020/index.htm)
144
+ 9,
145
+ // [CHARACTER TABULATION (HT)](https://www.fileformat.info/info/unicode/char/0009/index.htm)
146
+ 10,
147
+ // [LINE FEED (LF)](https://www.fileformat.info/info/unicode/char/000a/index.htm)
148
+ 13,
149
+ // [CARRIAGE RETURN (CR)](https://www.fileformat.info/info/unicode/char/000d/index.htm)
150
+ 12,
151
+ // [FORM FEED (FF)](https://www.fileformat.info/info/unicode/char/000c/index.htm)
152
+ 11,
153
+ // [LINE TABULATION (VT)](https://www.fileformat.info/info/unicode/char/000b/index.htm)
154
+ // Latin-1 Supplement
155
+ 160,
156
+ // [NO-BREAK SPACE (NBSP)](https://www.fileformat.info/info/unicode/char/00a0/index.htm)
157
+ // Ogham
158
+ 5760,
159
+ // [OGHAM SPACE MARK](https://www.fileformat.info/info/unicode/char/1680/index.htm)
160
+ // General Punctuation
161
+ 8192,
162
+ // [EN QUAD](https://www.fileformat.info/info/unicode/char/2000/index.htm)
163
+ 8193,
164
+ // [EM QUAD](https://www.fileformat.info/info/unicode/char/2001/index.htm)
165
+ 8194,
166
+ // [EN SPACE](https://www.fileformat.info/info/unicode/char/2002/index.htm)
167
+ 8195,
168
+ // [EM SPACE](https://www.fileformat.info/info/unicode/char/2003/index.htm)
169
+ 8196,
170
+ // [THREE-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2004/index.htm)
171
+ 8197,
172
+ // [FOUR-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2005/index.htm)
173
+ 8198,
174
+ // [SIX-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2006/index.htm)
175
+ 8199,
176
+ // [FIGURE SPACE](https://www.fileformat.info/info/unicode/char/2007/index.htm)
177
+ 8200,
178
+ // [PUNCTUATION SPACE](https://www.fileformat.info/info/unicode/char/2008/index.htm)
179
+ 8201,
180
+ // [THIN SPACE](https://www.fileformat.info/info/unicode/char/2009/index.htm)
181
+ 8202,
182
+ // [HAIR SPACE](https://www.fileformat.info/info/unicode/char/200a/index.htm)
183
+ 8232,
184
+ // [LINE SEPARATOR](https://www.fileformat.info/info/unicode/char/2028/index.htm)
185
+ 8233,
186
+ // [PARAGRAPH SEPARATOR](https://www.fileformat.info/info/unicode/char/2029/index.htm)
187
+ 8239,
188
+ // [NARROW NO-BREAK SPACE (NNBSP)](https://www.fileformat.info/info/unicode/char/202f/index.htm)
189
+ 8287,
190
+ // [MEDIUM MATHEMATICAL SPACE (MMSP)](https://www.fileformat.info/info/unicode/char/205f/index.htm)
191
+ 12288,
192
+ // [IDEOGRAPHIC SPACE](https://www.fileformat.info/info/unicode/char/3000/index.htm)
193
+ 65279
194
+ // [ZERO WIDTH NO-BREAK SPACE (BOM)](https://www.fileformat.info/info/unicode/char/feff/index.htm)
195
+ ].reduce((acc, codepoint) => {
196
+ const encoded = Buffer.from(
197
+ String.fromCharCode(codepoint),
198
+ options.encoding
199
+ );
200
+ if (codepoint !== 63 && encoded.length === 1 && encoded[0] === 63) {
201
+ return acc;
202
+ }
203
+ acc.push(encoded);
204
+ return acc;
205
+ }, []);
206
+ const timcharFirstBytes = new Uint8Array(256);
207
+ for (const t of timchars) timcharFirstBytes[t[0]] = 1;
208
+ return {
209
+ bomSkipped: false,
210
+ bufBytesStart: 0,
211
+ castField: options.cast_function,
212
+ commenting: false,
213
+ delimiterBufPrevious: void 0,
214
+ delimiterDiscovered: false,
215
+ // Current error encountered by a record
216
+ error: void 0,
217
+ enabled: options.from_line === 1,
218
+ escaping: false,
219
+ escapeIsQuote: Buffer.isBuffer(options.escape) && Buffer.isBuffer(options.quote) && Buffer.compare(options.escape, options.quote) === 0,
220
+ // columns can be `false`, `true`, `Array`
221
+ expectedRecordLength: Array.isArray(options.columns) ? options.columns.length : void 0,
222
+ field: new ResizeableBuffer_default(20),
223
+ firstLineToHeaders: options.cast_first_line_to_header,
224
+ needMoreDataSize: Math.max(
225
+ // Skip if the remaining buffer smaller than comment
226
+ options.comment !== null ? options.comment.length : 0,
227
+ ...options.delimiter ? options.delimiter.map((delimiter) => delimiter.length) : [],
228
+ // Auto discovery of delimiter is limited to 1 character
229
+ options.delimiter_auto ? 1 : 0,
230
+ // Skip if the remaining buffer can be escape sequence
231
+ options.quote !== null ? options.quote.length : 0,
232
+ ...timchars.map((t) => t.length)
233
+ ),
234
+ previousBuf: void 0,
235
+ quoting: false,
236
+ stop: false,
237
+ rawBuffer: new ResizeableBuffer_default(100),
238
+ record: [],
239
+ recordHasError: false,
240
+ record_length: 0,
241
+ recordDelimiterMaxLength: options.record_delimiter.length === 0 ? 0 : Math.max(...options.record_delimiter.map((v) => v.length)),
242
+ trimChars: [
243
+ Buffer.from(" ", options.encoding)[0],
244
+ Buffer.from(" ", options.encoding)[0]
245
+ ],
246
+ wasQuoting: false,
247
+ wasRowDelimiter: false,
248
+ timchars,
249
+ timcharFirstBytes
250
+ };
251
+ };
252
+
253
+ // node_modules/csv-parse/lib/api/normalize_options.js
254
+ init_define_import_meta_env();
255
+
256
+ // node_modules/csv-parse/lib/utils/underscore.js
257
+ init_define_import_meta_env();
258
+ var underscore = function(str) {
259
+ return str.replace(/([A-Z])/g, function(_, match) {
260
+ return "_" + match.toLowerCase();
261
+ });
262
+ };
263
+
264
+ // node_modules/csv-parse/lib/api/normalize_options.js
265
+ var normalize_options = function(opts) {
266
+ const options = {};
267
+ for (const opt in opts) {
268
+ options[underscore(opt)] = opts[opt];
269
+ }
270
+ if (options.encoding === void 0 || options.encoding === true) {
271
+ options.encoding = "utf8";
272
+ } else if (options.encoding === null || options.encoding === false) {
273
+ options.encoding = null;
274
+ } else if (typeof options.encoding !== "string" && options.encoding !== null) {
275
+ throw new CsvError(
276
+ "CSV_INVALID_OPTION_ENCODING",
277
+ [
278
+ "Invalid option encoding:",
279
+ "encoding must be a string or null to return a buffer,",
280
+ `got ${JSON.stringify(options.encoding)}`
281
+ ],
282
+ options
283
+ );
284
+ }
285
+ if (options.bom === void 0 || options.bom === null || options.bom === false) {
286
+ options.bom = false;
287
+ } else if (options.bom !== true) {
288
+ throw new CsvError(
289
+ "CSV_INVALID_OPTION_BOM",
290
+ [
291
+ "Invalid option bom:",
292
+ "bom must be true,",
293
+ `got ${JSON.stringify(options.bom)}`
294
+ ],
295
+ options
296
+ );
297
+ }
298
+ options.cast_function = null;
299
+ if (options.cast === void 0 || options.cast === null || options.cast === false || options.cast === "") {
300
+ options.cast = void 0;
301
+ } else if (typeof options.cast === "function") {
302
+ options.cast_function = options.cast;
303
+ options.cast = true;
304
+ } else if (options.cast !== true) {
305
+ throw new CsvError(
306
+ "CSV_INVALID_OPTION_CAST",
307
+ [
308
+ "Invalid option cast:",
309
+ "cast must be true or a function,",
310
+ `got ${JSON.stringify(options.cast)}`
311
+ ],
312
+ options
313
+ );
314
+ }
315
+ if (options.cast_date === void 0 || options.cast_date === null || options.cast_date === false || options.cast_date === "") {
316
+ options.cast_date = false;
317
+ } else if (options.cast_date === true) {
318
+ options.cast_date = function(value) {
319
+ const date = Date.parse(value);
320
+ return !isNaN(date) ? new Date(date) : value;
321
+ };
322
+ } else if (typeof options.cast_date !== "function") {
323
+ throw new CsvError(
324
+ "CSV_INVALID_OPTION_CAST_DATE",
325
+ [
326
+ "Invalid option cast_date:",
327
+ "cast_date must be true or a function,",
328
+ `got ${JSON.stringify(options.cast_date)}`
329
+ ],
330
+ options
331
+ );
332
+ }
333
+ options.cast_first_line_to_header = void 0;
334
+ if (options.columns === true) {
335
+ options.cast_first_line_to_header = void 0;
336
+ } else if (typeof options.columns === "function") {
337
+ options.cast_first_line_to_header = options.columns;
338
+ options.columns = true;
339
+ } else if (Array.isArray(options.columns)) {
340
+ options.columns = normalize_columns_array(options.columns);
341
+ } else if (options.columns === void 0 || options.columns === null || options.columns === false) {
342
+ options.columns = false;
343
+ } else {
344
+ throw new CsvError(
345
+ "CSV_INVALID_OPTION_COLUMNS",
346
+ [
347
+ "Invalid option columns:",
348
+ "expect an array, a function or true,",
349
+ `got ${JSON.stringify(options.columns)}`
350
+ ],
351
+ options
352
+ );
353
+ }
354
+ if (options.group_columns_by_name === void 0 || options.group_columns_by_name === null || options.group_columns_by_name === false) {
355
+ options.group_columns_by_name = false;
356
+ } else if (options.group_columns_by_name !== true) {
357
+ throw new CsvError(
358
+ "CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
359
+ [
360
+ "Invalid option group_columns_by_name:",
361
+ "expect an boolean,",
362
+ `got ${JSON.stringify(options.group_columns_by_name)}`
363
+ ],
364
+ options
365
+ );
366
+ } else if (options.columns === false) {
367
+ throw new CsvError(
368
+ "CSV_INVALID_OPTION_GROUP_COLUMNS_BY_NAME",
369
+ [
370
+ "Invalid option group_columns_by_name:",
371
+ "the `columns` mode must be activated."
372
+ ],
373
+ options
374
+ );
375
+ }
376
+ if (options.comment === void 0 || options.comment === null || options.comment === false || options.comment === "") {
377
+ options.comment = null;
378
+ } else {
379
+ if (typeof options.comment === "string") {
380
+ options.comment = Buffer.from(options.comment, options.encoding);
381
+ }
382
+ if (!Buffer.isBuffer(options.comment)) {
383
+ throw new CsvError(
384
+ "CSV_INVALID_OPTION_COMMENT",
385
+ [
386
+ "Invalid option comment:",
387
+ "comment must be a buffer or a string,",
388
+ `got ${JSON.stringify(options.comment)}`
389
+ ],
390
+ options
391
+ );
392
+ }
393
+ }
394
+ if (options.comment_no_infix === void 0 || options.comment_no_infix === null || options.comment_no_infix === false) {
395
+ options.comment_no_infix = false;
396
+ } else if (options.comment_no_infix !== true) {
397
+ throw new CsvError(
398
+ "CSV_INVALID_OPTION_COMMENT",
399
+ [
400
+ "Invalid option comment_no_infix:",
401
+ "value must be a boolean,",
402
+ `got ${JSON.stringify(options.comment_no_infix)}`
403
+ ],
404
+ options
405
+ );
406
+ }
407
+ if (options.delimiter_auto === void 0 || options.delimiter_auto === null || options.delimiter_auto === false) {
408
+ options.delimiter_auto = false;
409
+ } else if (options.delimiter_auto === true) {
410
+ options.delimiter_auto = {};
411
+ } else if (!is_object(options.delimiter_auto)) {
412
+ throw new CsvError(
413
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
414
+ [
415
+ "Invalid option delimiter_auto:",
416
+ "delimiter_auto must be a boolean or a configuration object,",
417
+ `got ${JSON.stringify(options.delimiter_auto)}`
418
+ ],
419
+ options
420
+ );
421
+ }
422
+ if (options.delimiter_auto) {
423
+ if (options.delimiter_auto.preferred === void 0)
424
+ options.delimiter_auto.preferred = {
425
+ [",".charCodeAt(0)]: 1.8,
426
+ [" ".charCodeAt(0)]: 1.8,
427
+ [";".charCodeAt(0)]: 1.6,
428
+ [" ".charCodeAt(0)]: 1.6,
429
+ [":".charCodeAt(0)]: 1.5,
430
+ [".".charCodeAt(0)]: 1.4,
431
+ ["/".charCodeAt(0)]: 1.4
432
+ };
433
+ else if (!is_object(options.delimiter_auto.preferred)) {
434
+ throw new CsvError(
435
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
436
+ [
437
+ "Invalid option delimiter_auto:",
438
+ "preferred must be an object,",
439
+ `got ${JSON.stringify(options.delimiter_auto.preferred)}`
440
+ ],
441
+ options
442
+ );
443
+ }
444
+ if (options.delimiter_auto.score === void 0)
445
+ options.delimiter_auto.score = (info, options2) => {
446
+ return (info.total - info.std) * (options2.preferred[info.char_code] || 1);
447
+ };
448
+ else if (typeof options.delimiter_auto.score !== "function") {
449
+ throw new CsvError(
450
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
451
+ [
452
+ "Invalid option delimiter_auto:",
453
+ "score must be a function,",
454
+ `got ${JSON.stringify(options.delimiter_auto.score)}`
455
+ ],
456
+ options
457
+ );
458
+ }
459
+ if (options.delimiter_auto.size === void 0)
460
+ options.delimiter_auto.size = 2048;
461
+ else if (typeof options.delimiter_auto.size !== "number") {
462
+ throw new CsvError(
463
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
464
+ [
465
+ "Invalid option delimiter_auto:",
466
+ "size must be a number,",
467
+ `got ${JSON.stringify(options.delimiter_auto.size)}`
468
+ ],
469
+ options
470
+ );
471
+ }
472
+ }
473
+ const delimiter_json = JSON.stringify(options.delimiter);
474
+ if (options.delimiter_auto !== false) {
475
+ options.delimiter = [];
476
+ }
477
+ if (!Array.isArray(options.delimiter)) {
478
+ if (options.delimiter === void 0 || options.delimiter === null || options.delimiter === false) {
479
+ options.delimiter = Buffer.from(",", options.encoding);
480
+ }
481
+ options.delimiter = [options.delimiter];
482
+ }
483
+ options.delimiter = options.delimiter.map(function(delimiter) {
484
+ if (typeof delimiter === "string") {
485
+ delimiter = Buffer.from(delimiter, options.encoding);
486
+ }
487
+ if (!Buffer.isBuffer(delimiter) || delimiter.length === 0) {
488
+ throw new CsvError(
489
+ "CSV_INVALID_OPTION_DELIMITER",
490
+ [
491
+ "Invalid option delimiter:",
492
+ "delimiter must be a non empty string or buffer or array of string|buffer,",
493
+ `got ${delimiter_json}`
494
+ ],
495
+ options
496
+ );
497
+ }
498
+ return delimiter;
499
+ });
500
+ if (options.escape === void 0 || options.escape === true) {
501
+ options.escape = Buffer.from('"', options.encoding);
502
+ } else if (typeof options.escape === "string") {
503
+ options.escape = Buffer.from(options.escape, options.encoding);
504
+ } else if (options.escape === null || options.escape === false) {
505
+ options.escape = null;
506
+ }
507
+ if (options.escape !== null) {
508
+ if (!Buffer.isBuffer(options.escape)) {
509
+ throw new Error(
510
+ `Invalid Option: escape must be a buffer, a string or a boolean, got ${JSON.stringify(options.escape)}`
511
+ );
512
+ }
513
+ }
514
+ if (options.from === void 0 || options.from === null) {
515
+ options.from = 1;
516
+ } else {
517
+ if (typeof options.from === "string" && /\d+/.test(options.from)) {
518
+ options.from = parseInt(options.from);
519
+ }
520
+ if (Number.isInteger(options.from)) {
521
+ if (options.from < 0) {
522
+ throw new Error(
523
+ `Invalid Option: from must be a positive integer, got ${JSON.stringify(opts.from)}`
524
+ );
525
+ }
526
+ } else {
527
+ throw new Error(
528
+ `Invalid Option: from must be an integer, got ${JSON.stringify(options.from)}`
529
+ );
530
+ }
531
+ }
532
+ if (options.from_line === void 0 || options.from_line === null) {
533
+ options.from_line = 1;
534
+ } else {
535
+ if (typeof options.from_line === "string" && /\d+/.test(options.from_line)) {
536
+ options.from_line = parseInt(options.from_line);
537
+ }
538
+ if (Number.isInteger(options.from_line)) {
539
+ if (options.from_line <= 0) {
540
+ throw new Error(
541
+ `Invalid Option: from_line must be a positive integer greater than 0, got ${JSON.stringify(opts.from_line)}`
542
+ );
543
+ }
544
+ } else {
545
+ throw new Error(
546
+ `Invalid Option: from_line must be an integer, got ${JSON.stringify(opts.from_line)}`
547
+ );
548
+ }
549
+ }
550
+ if (options.ignore_last_delimiters === void 0 || options.ignore_last_delimiters === null) {
551
+ options.ignore_last_delimiters = false;
552
+ } else if (typeof options.ignore_last_delimiters === "number") {
553
+ options.ignore_last_delimiters = Math.floor(options.ignore_last_delimiters);
554
+ if (options.ignore_last_delimiters === 0) {
555
+ options.ignore_last_delimiters = false;
556
+ }
557
+ } else if (typeof options.ignore_last_delimiters !== "boolean") {
558
+ throw new CsvError(
559
+ "CSV_INVALID_OPTION_IGNORE_LAST_DELIMITERS",
560
+ [
561
+ "Invalid option `ignore_last_delimiters`:",
562
+ "the value must be a boolean value or an integer,",
563
+ `got ${JSON.stringify(options.ignore_last_delimiters)}`
564
+ ],
565
+ options
566
+ );
567
+ }
568
+ if (options.ignore_last_delimiters === true && options.columns === false) {
569
+ throw new CsvError(
570
+ "CSV_IGNORE_LAST_DELIMITERS_REQUIRES_COLUMNS",
571
+ [
572
+ "The option `ignore_last_delimiters`",
573
+ "requires the activation of the `columns` option"
574
+ ],
575
+ options
576
+ );
577
+ }
578
+ if (options.info === void 0 || options.info === null || options.info === false) {
579
+ options.info = false;
580
+ } else if (options.info !== true) {
581
+ throw new Error(
582
+ `Invalid Option: info must be true, got ${JSON.stringify(options.info)}`
583
+ );
584
+ }
585
+ if (options.max_record_size === void 0 || options.max_record_size === null || options.max_record_size === false) {
586
+ options.max_record_size = 0;
587
+ } else if (Number.isInteger(options.max_record_size) && options.max_record_size >= 0) {
588
+ } else if (typeof options.max_record_size === "string" && /\d+/.test(options.max_record_size)) {
589
+ options.max_record_size = parseInt(options.max_record_size);
590
+ } else {
591
+ throw new Error(
592
+ `Invalid Option: max_record_size must be a positive integer, got ${JSON.stringify(options.max_record_size)}`
593
+ );
594
+ }
595
+ if (options.objname === void 0 || options.objname === null || options.objname === false) {
596
+ options.objname = void 0;
597
+ } else if (Buffer.isBuffer(options.objname)) {
598
+ if (options.objname.length === 0) {
599
+ throw new Error(`Invalid Option: objname must be a non empty buffer`);
600
+ }
601
+ if (options.encoding === null) {
602
+ } else {
603
+ options.objname = options.objname.toString(options.encoding);
604
+ }
605
+ } else if (typeof options.objname === "string") {
606
+ if (options.objname.length === 0) {
607
+ throw new Error(`Invalid Option: objname must be a non empty string`);
608
+ }
609
+ } else if (typeof options.objname === "number") {
610
+ } else {
611
+ throw new Error(
612
+ `Invalid Option: objname must be a string or a buffer, got ${options.objname}`
613
+ );
614
+ }
615
+ if (options.objname !== void 0) {
616
+ if (typeof options.objname === "number") {
617
+ if (options.columns !== false) {
618
+ throw Error(
619
+ "Invalid Option: objname index cannot be combined with columns or be defined as a field"
620
+ );
621
+ }
622
+ } else {
623
+ if (options.columns === false) {
624
+ throw Error(
625
+ "Invalid Option: objname field must be combined with columns or be defined as an index"
626
+ );
627
+ }
628
+ }
629
+ }
630
+ if (options.on_record === void 0 || options.on_record === null) {
631
+ options.on_record = void 0;
632
+ } else if (typeof options.on_record !== "function") {
633
+ throw new CsvError(
634
+ "CSV_INVALID_OPTION_ON_RECORD",
635
+ [
636
+ "Invalid option `on_record`:",
637
+ "expect a function,",
638
+ `got ${JSON.stringify(options.on_record)}`
639
+ ],
640
+ options
641
+ );
642
+ }
643
+ if (options.on_skip !== void 0 && options.on_skip !== null && typeof options.on_skip !== "function") {
644
+ throw new Error(
645
+ `Invalid Option: on_skip must be a function, got ${JSON.stringify(options.on_skip)}`
646
+ );
647
+ }
648
+ if (options.quote === null || options.quote === false || options.quote === "") {
649
+ options.quote = null;
650
+ } else {
651
+ if (options.quote === void 0 || options.quote === true) {
652
+ options.quote = Buffer.from('"', options.encoding);
653
+ } else if (typeof options.quote === "string") {
654
+ options.quote = Buffer.from(options.quote, options.encoding);
655
+ }
656
+ if (!Buffer.isBuffer(options.quote)) {
657
+ throw new Error(
658
+ `Invalid Option: quote must be a buffer or a string, got ${JSON.stringify(options.quote)}`
659
+ );
660
+ }
661
+ }
662
+ if (options.raw === void 0 || options.raw === null || options.raw === false) {
663
+ options.raw = false;
664
+ } else if (options.raw !== true) {
665
+ throw new Error(
666
+ `Invalid Option: raw must be true, got ${JSON.stringify(options.raw)}`
667
+ );
668
+ }
669
+ if (options.record_delimiter === void 0) {
670
+ options.record_delimiter = [];
671
+ } else if (typeof options.record_delimiter === "string" || Buffer.isBuffer(options.record_delimiter)) {
672
+ if (options.record_delimiter.length === 0) {
673
+ throw new CsvError(
674
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
675
+ [
676
+ "Invalid option `record_delimiter`:",
677
+ "value must be a non empty string or buffer,",
678
+ `got ${JSON.stringify(options.record_delimiter)}`
679
+ ],
680
+ options
681
+ );
682
+ }
683
+ options.record_delimiter = [options.record_delimiter];
684
+ } else if (!Array.isArray(options.record_delimiter)) {
685
+ throw new CsvError(
686
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
687
+ [
688
+ "Invalid option `record_delimiter`:",
689
+ "value must be a string, a buffer or array of string|buffer,",
690
+ `got ${JSON.stringify(options.record_delimiter)}`
691
+ ],
692
+ options
693
+ );
694
+ }
695
+ options.record_delimiter = options.record_delimiter.map(function(rd, i) {
696
+ if (typeof rd !== "string" && !Buffer.isBuffer(rd)) {
697
+ throw new CsvError(
698
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
699
+ [
700
+ "Invalid option `record_delimiter`:",
701
+ "value must be a string, a buffer or array of string|buffer",
702
+ `at index ${i},`,
703
+ `got ${JSON.stringify(rd)}`
704
+ ],
705
+ options
706
+ );
707
+ } else if (rd.length === 0) {
708
+ throw new CsvError(
709
+ "CSV_INVALID_OPTION_RECORD_DELIMITER",
710
+ [
711
+ "Invalid option `record_delimiter`:",
712
+ "value must be a non empty string or buffer",
713
+ `at index ${i},`,
714
+ `got ${JSON.stringify(rd)}`
715
+ ],
716
+ options
717
+ );
718
+ }
719
+ if (typeof rd === "string") {
720
+ rd = Buffer.from(rd, options.encoding);
721
+ }
722
+ return rd;
723
+ });
724
+ if (typeof options.relax_column_count === "boolean") {
725
+ } else if (options.relax_column_count === void 0 || options.relax_column_count === null) {
726
+ options.relax_column_count = false;
727
+ } else {
728
+ throw new Error(
729
+ `Invalid Option: relax_column_count must be a boolean, got ${JSON.stringify(options.relax_column_count)}`
730
+ );
731
+ }
732
+ if (typeof options.relax_column_count_less === "boolean") {
733
+ } else if (options.relax_column_count_less === void 0 || options.relax_column_count_less === null) {
734
+ options.relax_column_count_less = false;
735
+ } else {
736
+ throw new Error(
737
+ `Invalid Option: relax_column_count_less must be a boolean, got ${JSON.stringify(options.relax_column_count_less)}`
738
+ );
739
+ }
740
+ if (typeof options.relax_column_count_more === "boolean") {
741
+ } else if (options.relax_column_count_more === void 0 || options.relax_column_count_more === null) {
742
+ options.relax_column_count_more = false;
743
+ } else {
744
+ throw new Error(
745
+ `Invalid Option: relax_column_count_more must be a boolean, got ${JSON.stringify(options.relax_column_count_more)}`
746
+ );
747
+ }
748
+ if (typeof options.relax_quotes === "boolean") {
749
+ } else if (options.relax_quotes === void 0 || options.relax_quotes === null) {
750
+ options.relax_quotes = false;
751
+ } else {
752
+ throw new Error(
753
+ `Invalid Option: relax_quotes must be a boolean, got ${JSON.stringify(options.relax_quotes)}`
754
+ );
755
+ }
756
+ if (typeof options.skip_empty_lines === "boolean") {
757
+ } else if (options.skip_empty_lines === void 0 || options.skip_empty_lines === null) {
758
+ options.skip_empty_lines = false;
759
+ } else {
760
+ throw new Error(
761
+ `Invalid Option: skip_empty_lines must be a boolean, got ${JSON.stringify(options.skip_empty_lines)}`
762
+ );
763
+ }
764
+ if (typeof options.skip_records_with_empty_values === "boolean") {
765
+ } else if (options.skip_records_with_empty_values === void 0 || options.skip_records_with_empty_values === null) {
766
+ options.skip_records_with_empty_values = false;
767
+ } else {
768
+ throw new Error(
769
+ `Invalid Option: skip_records_with_empty_values must be a boolean, got ${JSON.stringify(options.skip_records_with_empty_values)}`
770
+ );
771
+ }
772
+ if (typeof options.skip_records_with_error === "boolean") {
773
+ } else if (options.skip_records_with_error === void 0 || options.skip_records_with_error === null) {
774
+ options.skip_records_with_error = false;
775
+ } else {
776
+ throw new Error(
777
+ `Invalid Option: skip_records_with_error must be a boolean, got ${JSON.stringify(options.skip_records_with_error)}`
778
+ );
779
+ }
780
+ if (options.rtrim === void 0 || options.rtrim === null || options.rtrim === false) {
781
+ options.rtrim = false;
782
+ } else if (options.rtrim !== true) {
783
+ throw new Error(
784
+ `Invalid Option: rtrim must be a boolean, got ${JSON.stringify(options.rtrim)}`
785
+ );
786
+ }
787
+ if (options.ltrim === void 0 || options.ltrim === null || options.ltrim === false) {
788
+ options.ltrim = false;
789
+ } else if (options.ltrim !== true) {
790
+ throw new Error(
791
+ `Invalid Option: ltrim must be a boolean, got ${JSON.stringify(options.ltrim)}`
792
+ );
793
+ }
794
+ if (options.trim === void 0 || options.trim === null || options.trim === false) {
795
+ options.trim = false;
796
+ } else if (options.trim !== true) {
797
+ throw new Error(
798
+ `Invalid Option: trim must be a boolean, got ${JSON.stringify(options.trim)}`
799
+ );
800
+ }
801
+ if (options.trim === true && opts.ltrim !== false) {
802
+ options.ltrim = true;
803
+ } else if (options.ltrim !== true) {
804
+ options.ltrim = false;
805
+ }
806
+ if (options.trim === true && opts.rtrim !== false) {
807
+ options.rtrim = true;
808
+ } else if (options.rtrim !== true) {
809
+ options.rtrim = false;
810
+ }
811
+ if (options.to === void 0 || options.to === null) {
812
+ options.to = -1;
813
+ } else if (options.to !== -1) {
814
+ if (typeof options.to === "string" && /\d+/.test(options.to)) {
815
+ options.to = parseInt(options.to);
816
+ }
817
+ if (Number.isInteger(options.to)) {
818
+ if (options.to <= 0) {
819
+ throw new Error(
820
+ `Invalid Option: to must be a positive integer greater than 0, got ${JSON.stringify(opts.to)}`
821
+ );
822
+ }
823
+ } else {
824
+ throw new Error(
825
+ `Invalid Option: to must be an integer, got ${JSON.stringify(opts.to)}`
826
+ );
827
+ }
828
+ }
829
+ if (options.to_line === void 0 || options.to_line === null) {
830
+ options.to_line = -1;
831
+ } else if (options.to_line !== -1) {
832
+ if (typeof options.to_line === "string" && /\d+/.test(options.to_line)) {
833
+ options.to_line = parseInt(options.to_line);
834
+ }
835
+ if (Number.isInteger(options.to_line)) {
836
+ if (options.to_line <= 0) {
837
+ throw new Error(
838
+ `Invalid Option: to_line must be a positive integer greater than 0, got ${JSON.stringify(opts.to_line)}`
839
+ );
840
+ }
841
+ } else {
842
+ throw new Error(
843
+ `Invalid Option: to_line must be an integer, got ${JSON.stringify(opts.to_line)}`
844
+ );
845
+ }
846
+ }
847
+ return options;
848
+ };
849
+
850
+ // node_modules/csv-parse/lib/utils/delimiter_discover.js
851
+ init_define_import_meta_env();
852
+ var delimiter_discover = function(records, options) {
853
+ if (!options) {
854
+ ({ delimiter_auto: options } = normalize_options({ delimiter_auto: true }));
855
+ }
856
+ if (typeof records === "string") {
857
+ records = Buffer.from(records);
858
+ }
859
+ if (Buffer.isBuffer(records)) {
860
+ records = ((data) => {
861
+ const records2 = [];
862
+ const parser = transform({ delimiter: [] });
863
+ const push = (record) => records2.push(record);
864
+ const close = () => {
865
+ };
866
+ const error = parser.parse(data, true, push, close);
867
+ if (error !== void 0) throw error;
868
+ return records2;
869
+ })(records);
870
+ }
871
+ const info = Array(127).fill().map(() => ({ lines: [] }));
872
+ records.map(([record], line) => {
873
+ for (let i = 0, l = record.length; i < l; i++) {
874
+ const code = record.charCodeAt(i);
875
+ if (info[code].lines[line] === void 0) info[code].lines[line] = 0;
876
+ info[code].lines[line]++;
877
+ }
878
+ });
879
+ info.map((info2, i) => {
880
+ info2.char_code = i;
881
+ info2.std = std(info2.lines);
882
+ info2.total = info2.lines.reduce((acc, val) => acc + val, 0);
883
+ info2.preferred = !!options.preferred[i];
884
+ info2.score = options.score(info2, options);
885
+ });
886
+ const result = info.reduce(
887
+ (acc, info2) => acc.score > info2.score ? acc : info2,
888
+ {}
889
+ );
890
+ return String.fromCharCode(result.char_code);
891
+ };
892
+ var std = function(array) {
893
+ const n = array.length;
894
+ if (n === 0) return 0;
895
+ const mean = array.reduce((a, b) => a + b) / n;
896
+ return Math.sqrt(
897
+ array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n
898
+ );
899
+ };
900
+
901
+ // node_modules/csv-parse/lib/api/index.js
902
+ var isRecordEmpty = function(record) {
903
+ return record.every(
904
+ (field) => field == null || field.toString && field.toString().trim() === ""
905
+ );
906
+ };
907
+ var cr = 13;
908
+ var nl = 10;
909
+ var boms = {
910
+ // Note, the following are equals:
911
+ // Buffer.from("\ufeff")
912
+ // Buffer.from([239, 187, 191])
913
+ // Buffer.from('EFBBBF', 'hex')
914
+ utf8: Buffer.from([239, 187, 191]),
915
+ // Note, the following are equals:
916
+ // Buffer.from "\ufeff", 'utf16le
917
+ // Buffer.from([255, 254])
918
+ utf16le: Buffer.from([255, 254])
919
+ };
920
+ var transform = function(original_options = {}) {
921
+ const info = {
922
+ bytes: 0,
923
+ bytes_records: 0,
924
+ comment_lines: 0,
925
+ empty_lines: 0,
926
+ invalid_field_length: 0,
927
+ lines: 1,
928
+ records: 0
929
+ };
930
+ const options = normalize_options(original_options);
931
+ return {
932
+ info,
933
+ original_options,
934
+ options,
935
+ state: init_state(options),
936
+ __needMoreData: function(i, bufLen, end) {
937
+ if (end) return false;
938
+ const { encoding, escape, quote } = this.options;
939
+ const { quoting, needMoreDataSize, recordDelimiterMaxLength } = this.state;
940
+ const numOfCharLeft = bufLen - i - 1;
941
+ const requiredLength = Math.max(
942
+ needMoreDataSize,
943
+ // Skip if the remaining buffer smaller than record delimiter
944
+ // If "record_delimiter" is yet to be discovered:
945
+ // 1. It is equals to `[]` and "recordDelimiterMaxLength" equals `0`
946
+ // 2. We set the length to windows line ending in the current encoding
947
+ // Note, that encoding is known from user or bom discovery at that point
948
+ // recordDelimiterMaxLength,
949
+ recordDelimiterMaxLength === 0 ? Buffer.from("\r\n", encoding).length : recordDelimiterMaxLength,
950
+ // Skip if remaining buffer can be an escaped quote
951
+ quoting ? (escape === null ? 0 : escape.length) + quote.length : 0,
952
+ // Skip if remaining buffer can be record delimiter following the closing quote
953
+ quoting ? quote.length + recordDelimiterMaxLength : 0
954
+ );
955
+ return numOfCharLeft < requiredLength;
956
+ },
957
+ // Central parser implementation
958
+ parse: function(nextBuf, end, push, close) {
959
+ const {
960
+ bom,
961
+ comment_no_infix,
962
+ delimiter_auto,
963
+ encoding,
964
+ from_line,
965
+ ltrim,
966
+ max_record_size,
967
+ raw,
968
+ relax_quotes,
969
+ rtrim,
970
+ skip_empty_lines,
971
+ to,
972
+ to_line
973
+ } = this.options;
974
+ let { comment, escape, quote, record_delimiter } = this.options;
975
+ const {
976
+ bomSkipped,
977
+ delimiterDiscovered,
978
+ delimiterBufPrevious,
979
+ rawBuffer,
980
+ escapeIsQuote
981
+ } = this.state;
982
+ if (!delimiterDiscovered && delimiter_auto) {
983
+ let delimiterBuf;
984
+ if (delimiterBufPrevious === void 0) {
985
+ delimiterBuf = nextBuf;
986
+ } else if (delimiterBufPrevious !== void 0 && nextBuf === void 0) {
987
+ delimiterBuf = delimiterBufPrevious;
988
+ } else {
989
+ delimiterBuf = Buffer.concat([delimiterBufPrevious, nextBuf]);
990
+ }
991
+ nextBuf = void 0;
992
+ if (end || delimiterBuf.length > delimiter_auto.size) {
993
+ this.options.delimiter = [
994
+ Buffer.from(
995
+ delimiter_discover(delimiterBuf, this.options.delimiter_auto)
996
+ )
997
+ ];
998
+ this.state.previousBuf = delimiterBuf;
999
+ this.state.delimiterBufPrevious = void 0;
1000
+ this.state.delimiterDiscovered = true;
1001
+ } else {
1002
+ this.state.delimiterBufPrevious = delimiterBuf;
1003
+ return;
1004
+ }
1005
+ }
1006
+ const { previousBuf } = this.state;
1007
+ let buf;
1008
+ if (previousBuf === void 0) {
1009
+ if (nextBuf === void 0) {
1010
+ close();
1011
+ return;
1012
+ } else {
1013
+ buf = nextBuf;
1014
+ }
1015
+ } else if (previousBuf !== void 0 && nextBuf === void 0) {
1016
+ buf = previousBuf;
1017
+ } else {
1018
+ buf = Buffer.concat([previousBuf, nextBuf]);
1019
+ }
1020
+ if (bomSkipped === false) {
1021
+ if (bom === false) {
1022
+ this.state.bomSkipped = true;
1023
+ } else if (buf.length < 3) {
1024
+ if (end === false) {
1025
+ this.state.previousBuf = buf;
1026
+ return;
1027
+ }
1028
+ } else {
1029
+ for (const encoding2 in boms) {
1030
+ if (boms[encoding2].compare(buf, 0, boms[encoding2].length) === 0) {
1031
+ const bomLength = boms[encoding2].length;
1032
+ this.state.bufBytesStart += bomLength;
1033
+ buf = buf.slice(bomLength);
1034
+ const options2 = normalize_options({
1035
+ ...this.original_options,
1036
+ encoding: encoding2
1037
+ });
1038
+ for (const key in options2) {
1039
+ this.options[key] = options2[key];
1040
+ }
1041
+ ({ comment, escape, quote } = this.options);
1042
+ break;
1043
+ }
1044
+ }
1045
+ this.state.bomSkipped = true;
1046
+ }
1047
+ }
1048
+ const bufLen = buf.length;
1049
+ let pos;
1050
+ for (pos = 0; pos < bufLen; pos++) {
1051
+ if (this.__needMoreData(pos, bufLen, end)) {
1052
+ break;
1053
+ }
1054
+ if (this.state.wasRowDelimiter === true) {
1055
+ this.info.lines++;
1056
+ this.state.wasRowDelimiter = false;
1057
+ }
1058
+ if (to_line !== -1 && this.info.lines > to_line) {
1059
+ this.state.stop = true;
1060
+ close();
1061
+ return;
1062
+ }
1063
+ if (this.state.quoting === false && record_delimiter.length === 0) {
1064
+ const record_delimiterCount = this.__autoDiscoverRecordDelimiter(
1065
+ buf,
1066
+ pos
1067
+ );
1068
+ if (record_delimiterCount) {
1069
+ record_delimiter = this.options.record_delimiter;
1070
+ }
1071
+ }
1072
+ const chr = buf[pos];
1073
+ if (raw === true) {
1074
+ rawBuffer.append(chr);
1075
+ }
1076
+ if ((chr === cr || chr === nl) && this.state.wasRowDelimiter === false) {
1077
+ this.state.wasRowDelimiter = true;
1078
+ }
1079
+ if (this.state.escaping === true) {
1080
+ this.state.escaping = false;
1081
+ } else {
1082
+ if (escape !== null && this.state.quoting === true && this.__isEscape(buf, pos, chr) && pos + escape.length < bufLen) {
1083
+ if (escapeIsQuote) {
1084
+ if (this.__isQuote(buf, pos + escape.length)) {
1085
+ this.state.escaping = true;
1086
+ pos += escape.length - 1;
1087
+ continue;
1088
+ }
1089
+ } else {
1090
+ this.state.escaping = true;
1091
+ pos += escape.length - 1;
1092
+ continue;
1093
+ }
1094
+ }
1095
+ if (this.state.commenting === false && this.__isQuote(buf, pos)) {
1096
+ if (this.state.quoting === true) {
1097
+ const nextChr = buf[pos + quote.length];
1098
+ const isNextChrTrimable = rtrim && this.__isCharTrimable(buf, pos + quote.length);
1099
+ const isNextChrComment = comment !== null && this.__compareBytes(comment, buf, pos + quote.length, nextChr);
1100
+ const isNextChrDelimiter = this.__isDelimiter(
1101
+ buf,
1102
+ pos + quote.length,
1103
+ nextChr
1104
+ );
1105
+ const isNextChrRecordDelimiter = record_delimiter.length === 0 ? this.__autoDiscoverRecordDelimiter(buf, pos + quote.length) : this.__isRecordDelimiter(nextChr, buf, pos + quote.length);
1106
+ if (escape !== null && this.__isEscape(buf, pos, chr) && this.__isQuote(buf, pos + escape.length)) {
1107
+ pos += escape.length - 1;
1108
+ } else if (!nextChr || isNextChrDelimiter || isNextChrRecordDelimiter || isNextChrComment || isNextChrTrimable) {
1109
+ this.state.quoting = false;
1110
+ this.state.wasQuoting = true;
1111
+ pos += quote.length - 1;
1112
+ continue;
1113
+ } else if (relax_quotes === false) {
1114
+ const err = this.__error(
1115
+ new CsvError(
1116
+ "CSV_INVALID_CLOSING_QUOTE",
1117
+ [
1118
+ "Invalid Closing Quote:",
1119
+ `got "${String.fromCharCode(nextChr)}"`,
1120
+ `at line ${this.info.lines}`,
1121
+ "instead of delimiter, record delimiter, trimable character",
1122
+ "(if activated) or comment"
1123
+ ],
1124
+ this.options,
1125
+ this.__infoField()
1126
+ )
1127
+ );
1128
+ if (err !== void 0) return err;
1129
+ } else {
1130
+ this.state.quoting = false;
1131
+ this.state.wasQuoting = true;
1132
+ this.state.field.prepend(quote);
1133
+ pos += quote.length - 1;
1134
+ }
1135
+ } else {
1136
+ if (this.state.field.length !== 0) {
1137
+ if (relax_quotes === false) {
1138
+ const info2 = this.__infoField();
1139
+ const bom2 = Object.keys(boms).map(
1140
+ (b) => boms[b].equals(this.state.field.toString()) ? b : false
1141
+ ).filter(Boolean)[0];
1142
+ const err = this.__error(
1143
+ new CsvError(
1144
+ "INVALID_OPENING_QUOTE",
1145
+ [
1146
+ "Invalid Opening Quote:",
1147
+ `a quote is found on field ${JSON.stringify(info2.column)} at line ${info2.lines}, value is ${JSON.stringify(this.state.field.toString(encoding))}`,
1148
+ bom2 ? `(${bom2} bom)` : void 0
1149
+ ],
1150
+ this.options,
1151
+ info2,
1152
+ {
1153
+ field: this.state.field
1154
+ }
1155
+ )
1156
+ );
1157
+ if (err !== void 0) return err;
1158
+ }
1159
+ } else {
1160
+ this.state.quoting = true;
1161
+ pos += quote.length - 1;
1162
+ continue;
1163
+ }
1164
+ }
1165
+ }
1166
+ if (this.state.quoting === false) {
1167
+ const recordDelimiterLength = this.__isRecordDelimiter(
1168
+ chr,
1169
+ buf,
1170
+ pos
1171
+ );
1172
+ if (recordDelimiterLength !== 0) {
1173
+ const skipCommentLine = this.state.commenting && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0;
1174
+ if (skipCommentLine) {
1175
+ this.info.comment_lines++;
1176
+ } else {
1177
+ if (this.state.enabled === false && this.info.lines + (this.state.wasRowDelimiter === true ? 1 : 0) >= from_line) {
1178
+ this.state.enabled = true;
1179
+ this.__resetField();
1180
+ this.__resetRecord();
1181
+ pos += recordDelimiterLength - 1;
1182
+ continue;
1183
+ }
1184
+ if (skip_empty_lines === true && this.state.wasQuoting === false && this.state.record.length === 0 && this.state.field.length === 0) {
1185
+ this.info.empty_lines++;
1186
+ pos += recordDelimiterLength - 1;
1187
+ continue;
1188
+ }
1189
+ this.info.bytes = this.state.bufBytesStart + pos;
1190
+ const errField = this.__onField();
1191
+ if (errField !== void 0) return errField;
1192
+ this.info.bytes = this.state.bufBytesStart + pos + recordDelimiterLength;
1193
+ const errRecord = this.__onRecord(push);
1194
+ if (errRecord !== void 0) return errRecord;
1195
+ if (to !== -1 && this.info.records >= to) {
1196
+ this.state.stop = true;
1197
+ close();
1198
+ return;
1199
+ }
1200
+ }
1201
+ this.state.commenting = false;
1202
+ pos += recordDelimiterLength - 1;
1203
+ continue;
1204
+ }
1205
+ if (this.state.commenting) {
1206
+ continue;
1207
+ }
1208
+ if (comment !== null && (comment_no_infix === false || this.state.record.length === 0 && this.state.field.length === 0)) {
1209
+ const commentCount = this.__compareBytes(comment, buf, pos, chr);
1210
+ if (commentCount !== 0) {
1211
+ this.state.commenting = true;
1212
+ continue;
1213
+ }
1214
+ }
1215
+ const delimiterLength = this.__isDelimiter(buf, pos, chr);
1216
+ if (delimiterLength !== 0) {
1217
+ this.info.bytes = this.state.bufBytesStart + pos;
1218
+ const errField = this.__onField();
1219
+ if (errField !== void 0) return errField;
1220
+ pos += delimiterLength - 1;
1221
+ continue;
1222
+ }
1223
+ }
1224
+ }
1225
+ if (this.state.commenting === false) {
1226
+ if (max_record_size !== 0 && this.state.record_length + this.state.field.length > max_record_size) {
1227
+ return this.__error(
1228
+ new CsvError(
1229
+ "CSV_MAX_RECORD_SIZE",
1230
+ [
1231
+ "Max Record Size:",
1232
+ "record exceed the maximum number of tolerated bytes",
1233
+ `of ${max_record_size}`,
1234
+ `at line ${this.info.lines}`
1235
+ ],
1236
+ this.options,
1237
+ this.__infoField()
1238
+ )
1239
+ );
1240
+ }
1241
+ }
1242
+ const lappend = ltrim === false || this.state.quoting === true || this.state.field.length !== 0 || !this.__isCharTrimable(buf, pos);
1243
+ const rappend = rtrim === false || this.state.wasQuoting === false;
1244
+ if (lappend === true && rappend === true) {
1245
+ this.state.field.append(chr);
1246
+ } else if (rtrim === true && !this.__isCharTrimable(buf, pos)) {
1247
+ return this.__error(
1248
+ new CsvError(
1249
+ "CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE",
1250
+ [
1251
+ "Invalid Closing Quote:",
1252
+ "found non trimable byte after quote",
1253
+ `at line ${this.info.lines}`
1254
+ ],
1255
+ this.options,
1256
+ this.__infoField()
1257
+ )
1258
+ );
1259
+ } else {
1260
+ if (lappend === false) {
1261
+ pos += this.__isCharTrimable(buf, pos) - 1;
1262
+ }
1263
+ continue;
1264
+ }
1265
+ }
1266
+ if (end === true) {
1267
+ if (this.state.quoting === true) {
1268
+ const err = this.__error(
1269
+ new CsvError(
1270
+ "CSV_QUOTE_NOT_CLOSED",
1271
+ [
1272
+ "Quote Not Closed:",
1273
+ `the parsing is finished with an opening quote at line ${this.info.lines}`
1274
+ ],
1275
+ this.options,
1276
+ this.__infoField()
1277
+ )
1278
+ );
1279
+ if (err !== void 0) return err;
1280
+ } else {
1281
+ if (this.state.wasQuoting === true || this.state.record.length !== 0 || this.state.field.length !== 0) {
1282
+ this.info.bytes = this.state.bufBytesStart + pos;
1283
+ const errField = this.__onField();
1284
+ if (errField !== void 0) return errField;
1285
+ const errRecord = this.__onRecord(push);
1286
+ if (errRecord !== void 0) return errRecord;
1287
+ } else if (this.state.wasRowDelimiter === true) {
1288
+ this.info.empty_lines++;
1289
+ } else if (this.state.commenting === true) {
1290
+ this.info.comment_lines++;
1291
+ }
1292
+ }
1293
+ } else {
1294
+ this.state.bufBytesStart += pos;
1295
+ this.state.previousBuf = buf.slice(pos);
1296
+ }
1297
+ if (this.state.wasRowDelimiter === true) {
1298
+ this.info.lines++;
1299
+ this.state.wasRowDelimiter = false;
1300
+ }
1301
+ },
1302
+ __onRecord: function(push) {
1303
+ const {
1304
+ columns,
1305
+ group_columns_by_name,
1306
+ encoding,
1307
+ info: info2,
1308
+ from,
1309
+ relax_column_count,
1310
+ relax_column_count_less,
1311
+ relax_column_count_more,
1312
+ raw,
1313
+ skip_records_with_empty_values
1314
+ } = this.options;
1315
+ const { enabled, record } = this.state;
1316
+ if (enabled === false) {
1317
+ return this.__resetRecord();
1318
+ }
1319
+ const recordLength = record.length;
1320
+ if (columns === true) {
1321
+ if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
1322
+ this.__resetRecord();
1323
+ return;
1324
+ }
1325
+ return this.__firstLineToColumns(record);
1326
+ }
1327
+ if (columns === false && this.info.records === 0) {
1328
+ this.state.expectedRecordLength = recordLength;
1329
+ }
1330
+ if (recordLength !== this.state.expectedRecordLength) {
1331
+ const err = columns === false ? new CsvError(
1332
+ "CSV_RECORD_INCONSISTENT_FIELDS_LENGTH",
1333
+ [
1334
+ "Invalid Record Length:",
1335
+ `expect ${this.state.expectedRecordLength},`,
1336
+ `got ${recordLength} on line ${this.info.lines}`
1337
+ ],
1338
+ this.options,
1339
+ this.__infoField(),
1340
+ {
1341
+ record
1342
+ }
1343
+ ) : new CsvError(
1344
+ "CSV_RECORD_INCONSISTENT_COLUMNS",
1345
+ [
1346
+ "Invalid Record Length:",
1347
+ `columns length is ${columns.length},`,
1348
+ // rename columns
1349
+ `got ${recordLength} on line ${this.info.lines}`
1350
+ ],
1351
+ this.options,
1352
+ this.__infoField(),
1353
+ {
1354
+ record
1355
+ }
1356
+ );
1357
+ if (relax_column_count === true || relax_column_count_less === true && recordLength < this.state.expectedRecordLength || relax_column_count_more === true && recordLength > this.state.expectedRecordLength) {
1358
+ this.info.invalid_field_length++;
1359
+ this.state.error = err;
1360
+ } else {
1361
+ const finalErr = this.__error(err);
1362
+ if (finalErr) return finalErr;
1363
+ }
1364
+ }
1365
+ if (skip_records_with_empty_values === true && isRecordEmpty(record)) {
1366
+ this.__resetRecord();
1367
+ return;
1368
+ }
1369
+ if (this.state.recordHasError === true) {
1370
+ this.__resetRecord();
1371
+ this.state.recordHasError = false;
1372
+ return;
1373
+ }
1374
+ this.info.records++;
1375
+ if (from === 1 || this.info.records >= from) {
1376
+ const { objname } = this.options;
1377
+ if (columns !== false) {
1378
+ const obj = {};
1379
+ for (let i = 0, l = record.length; i < l; i++) {
1380
+ if (columns[i] === void 0 || columns[i].disabled) continue;
1381
+ if (group_columns_by_name === true && Object.hasOwn(obj, columns[i].name)) {
1382
+ if (Array.isArray(obj[columns[i].name])) {
1383
+ obj[columns[i].name] = obj[columns[i].name].concat(record[i]);
1384
+ } else {
1385
+ obj[columns[i].name] = [obj[columns[i].name], record[i]];
1386
+ }
1387
+ } else {
1388
+ Object.defineProperty(obj, columns[i].name, {
1389
+ value: record[i],
1390
+ enumerable: true,
1391
+ writable: true,
1392
+ configurable: true
1393
+ });
1394
+ }
1395
+ }
1396
+ if (raw === true || info2 === true) {
1397
+ const extRecord = Object.assign(
1398
+ { record: obj },
1399
+ raw === true ? { raw: this.state.rawBuffer.toString(encoding) } : {},
1400
+ info2 === true ? { info: this.__infoRecord() } : {}
1401
+ );
1402
+ const err = this.__push(
1403
+ objname === void 0 ? extRecord : [obj[objname], extRecord],
1404
+ push
1405
+ );
1406
+ if (err) {
1407
+ return err;
1408
+ }
1409
+ } else {
1410
+ const err = this.__push(
1411
+ objname === void 0 ? obj : [obj[objname], obj],
1412
+ push
1413
+ );
1414
+ if (err) {
1415
+ return err;
1416
+ }
1417
+ }
1418
+ } else {
1419
+ if (raw === true || info2 === true) {
1420
+ const extRecord = Object.assign(
1421
+ { record },
1422
+ raw === true ? { raw: this.state.rawBuffer.toString(encoding) } : {},
1423
+ info2 === true ? { info: this.__infoRecord() } : {}
1424
+ );
1425
+ const err = this.__push(
1426
+ objname === void 0 ? extRecord : [record[objname], extRecord],
1427
+ push
1428
+ );
1429
+ if (err) {
1430
+ return err;
1431
+ }
1432
+ } else {
1433
+ const err = this.__push(
1434
+ objname === void 0 ? record : [record[objname], record],
1435
+ push
1436
+ );
1437
+ if (err) {
1438
+ return err;
1439
+ }
1440
+ }
1441
+ }
1442
+ }
1443
+ this.__resetRecord();
1444
+ },
1445
+ __firstLineToColumns: function(record) {
1446
+ const { firstLineToHeaders } = this.state;
1447
+ try {
1448
+ const headers = firstLineToHeaders === void 0 ? record : firstLineToHeaders.call(null, record);
1449
+ if (!Array.isArray(headers)) {
1450
+ return this.__error(
1451
+ new CsvError(
1452
+ "CSV_INVALID_COLUMN_MAPPING",
1453
+ [
1454
+ "Invalid Column Mapping:",
1455
+ "expect an array from column function,",
1456
+ `got ${JSON.stringify(headers)}`
1457
+ ],
1458
+ this.options,
1459
+ this.__infoField(),
1460
+ {
1461
+ headers
1462
+ }
1463
+ )
1464
+ );
1465
+ }
1466
+ const normalizedHeaders = normalize_columns_array(headers);
1467
+ this.state.expectedRecordLength = normalizedHeaders.length;
1468
+ this.options.columns = normalizedHeaders;
1469
+ this.__resetRecord();
1470
+ return;
1471
+ } catch (err) {
1472
+ return err;
1473
+ }
1474
+ },
1475
+ __resetRecord: function() {
1476
+ if (this.options.raw === true) {
1477
+ this.state.rawBuffer.reset();
1478
+ }
1479
+ this.state.error = void 0;
1480
+ this.state.record = [];
1481
+ this.state.record_length = 0;
1482
+ },
1483
+ __onField: function() {
1484
+ const { cast, encoding, rtrim, max_record_size } = this.options;
1485
+ const { enabled, wasQuoting } = this.state;
1486
+ if (enabled === false) {
1487
+ return this.__resetField();
1488
+ }
1489
+ let field = this.state.field.toString(encoding);
1490
+ if (rtrim === true && wasQuoting === false) {
1491
+ field = field.trimRight();
1492
+ }
1493
+ if (cast === true) {
1494
+ const [err, f] = this.__cast(field);
1495
+ if (err !== void 0) return err;
1496
+ field = f;
1497
+ }
1498
+ this.state.record.push(field);
1499
+ if (max_record_size !== 0 && typeof field === "string") {
1500
+ this.state.record_length += field.length;
1501
+ }
1502
+ this.__resetField();
1503
+ },
1504
+ __resetField: function() {
1505
+ this.state.field.reset();
1506
+ this.state.wasQuoting = false;
1507
+ },
1508
+ __push: function(record, push) {
1509
+ const { on_record } = this.options;
1510
+ if (on_record !== void 0) {
1511
+ const info2 = this.__infoRecord();
1512
+ try {
1513
+ record = on_record.call(null, record, info2);
1514
+ } catch (err) {
1515
+ return err;
1516
+ }
1517
+ if (record === void 0 || record === null) {
1518
+ return;
1519
+ }
1520
+ }
1521
+ this.info.bytes_records += this.info.bytes;
1522
+ push(record);
1523
+ },
1524
+ // Return a tuple with the error and the casted value
1525
+ __cast: function(field) {
1526
+ const { columns, relax_column_count } = this.options;
1527
+ const isColumns = Array.isArray(columns);
1528
+ if (isColumns === true && relax_column_count && this.options.columns.length <= this.state.record.length) {
1529
+ return [void 0, void 0];
1530
+ }
1531
+ if (this.state.castField !== null) {
1532
+ try {
1533
+ const info2 = this.__infoField();
1534
+ return [void 0, this.state.castField.call(null, field, info2)];
1535
+ } catch (err) {
1536
+ return [err];
1537
+ }
1538
+ }
1539
+ if (this.__isFloat(field)) {
1540
+ return [void 0, parseFloat(field)];
1541
+ } else if (this.options.cast_date !== false) {
1542
+ const info2 = this.__infoField();
1543
+ return [void 0, this.options.cast_date.call(null, field, info2)];
1544
+ }
1545
+ return [void 0, field];
1546
+ },
1547
+ __compareBytes: function(sourceBuf, targetBuf, targetPos, firstByte) {
1548
+ if (sourceBuf[0] !== firstByte) return 0;
1549
+ const sourceLength = sourceBuf.length;
1550
+ for (let i = 1; i < sourceLength; i++) {
1551
+ if (sourceBuf[i] !== targetBuf[targetPos + i]) return 0;
1552
+ }
1553
+ return sourceLength;
1554
+ },
1555
+ // Helper to test if a character is trimable
1556
+ __isCharTrimable: function(buf, pos) {
1557
+ const { timchars, timcharFirstBytes } = this.state;
1558
+ const first = buf[pos];
1559
+ if (first === void 0 || timcharFirstBytes[first] === 0) return 0;
1560
+ loop1: for (let i = 0; i < timchars.length; i++) {
1561
+ const timchar = timchars[i];
1562
+ for (let j = 0; j < timchar.length; j++) {
1563
+ if (timchar[j] !== buf[pos + j]) continue loop1;
1564
+ }
1565
+ return timchar.length;
1566
+ }
1567
+ return 0;
1568
+ },
1569
+ __isDelimiter: function(buf, pos, chr) {
1570
+ const { delimiter, ignore_last_delimiters } = this.options;
1571
+ if (ignore_last_delimiters === true && this.state.record.length === this.options.columns.length - 1) {
1572
+ return 0;
1573
+ } else if (ignore_last_delimiters !== false && typeof ignore_last_delimiters === "number" && this.state.record.length === ignore_last_delimiters - 1) {
1574
+ return 0;
1575
+ }
1576
+ loop1: for (let i = 0; i < delimiter.length; i++) {
1577
+ const del = delimiter[i];
1578
+ if (del[0] === chr) {
1579
+ for (let j = 1; j < del.length; j++) {
1580
+ if (del[j] !== buf[pos + j]) continue loop1;
1581
+ }
1582
+ return del.length;
1583
+ }
1584
+ }
1585
+ return 0;
1586
+ },
1587
+ __isEscape: function(buf, pos, chr) {
1588
+ const { escape } = this.options;
1589
+ if (escape === null) return false;
1590
+ const l = escape.length;
1591
+ if (escape[0] === chr) {
1592
+ for (let i = 0; i < l; i++) {
1593
+ if (escape[i] !== buf[pos + i]) {
1594
+ return false;
1595
+ }
1596
+ }
1597
+ return true;
1598
+ }
1599
+ return false;
1600
+ },
1601
+ __isFloat: function(value) {
1602
+ return value - parseFloat(value) + 1 >= 0;
1603
+ },
1604
+ // Keep it in case we implement the `cast_int` option
1605
+ // __isInt(value){
1606
+ // // return Number.isInteger(parseInt(value))
1607
+ // // return !isNaN( parseInt( obj ) );
1608
+ // return /^(\-|\+)?[1-9][0-9]*$/.test(value)
1609
+ // }
1610
+ __isQuote: function(buf, pos) {
1611
+ const { quote } = this.options;
1612
+ if (quote === null) return false;
1613
+ const l = quote.length;
1614
+ for (let i = 0; i < l; i++) {
1615
+ if (quote[i] !== buf[pos + i]) {
1616
+ return false;
1617
+ }
1618
+ }
1619
+ return true;
1620
+ },
1621
+ __isRecordDelimiter: function(chr, buf, pos) {
1622
+ const { record_delimiter } = this.options;
1623
+ const recordDelimiterLength = record_delimiter.length;
1624
+ loop1: for (let i = 0; i < recordDelimiterLength; i++) {
1625
+ const rd = record_delimiter[i];
1626
+ const rdLength = rd.length;
1627
+ if (rd[0] !== chr) {
1628
+ continue;
1629
+ }
1630
+ for (let j = 1; j < rdLength; j++) {
1631
+ if (rd[j] !== buf[pos + j]) {
1632
+ continue loop1;
1633
+ }
1634
+ }
1635
+ return rd.length;
1636
+ }
1637
+ return 0;
1638
+ },
1639
+ __autoDiscoverRecordDelimiter: function(buf, pos) {
1640
+ const { encoding } = this.options;
1641
+ const rds = [
1642
+ // Important, the windows line ending must be before mac os 9
1643
+ Buffer.from("\r\n", encoding),
1644
+ Buffer.from("\n", encoding),
1645
+ Buffer.from("\r", encoding)
1646
+ ];
1647
+ loop: for (let i = 0; i < rds.length; i++) {
1648
+ const l = rds[i].length;
1649
+ for (let j = 0; j < l; j++) {
1650
+ if (rds[i][j] !== buf[pos + j]) {
1651
+ continue loop;
1652
+ }
1653
+ }
1654
+ this.options.record_delimiter.push(rds[i]);
1655
+ this.state.recordDelimiterMaxLength = rds[i].length;
1656
+ return rds[i].length;
1657
+ }
1658
+ return 0;
1659
+ },
1660
+ __error: function(msg) {
1661
+ const { encoding, raw, skip_records_with_error } = this.options;
1662
+ const err = typeof msg === "string" ? new Error(msg) : msg;
1663
+ if (skip_records_with_error) {
1664
+ this.state.recordHasError = true;
1665
+ if (this.options.on_skip !== void 0) {
1666
+ try {
1667
+ this.options.on_skip(
1668
+ err,
1669
+ raw ? this.state.rawBuffer.toString(encoding) : void 0
1670
+ );
1671
+ } catch (err2) {
1672
+ return err2;
1673
+ }
1674
+ }
1675
+ return void 0;
1676
+ } else {
1677
+ return err;
1678
+ }
1679
+ },
1680
+ __infoDataSet: function() {
1681
+ return {
1682
+ ...this.info,
1683
+ columns: this.options.columns
1684
+ };
1685
+ },
1686
+ __infoRecord: function() {
1687
+ const { columns, raw, encoding } = this.options;
1688
+ return {
1689
+ ...this.__infoDataSet(),
1690
+ bytes_records: this.info.bytes,
1691
+ error: this.state.error,
1692
+ header: columns === true,
1693
+ index: this.state.record.length,
1694
+ raw: raw ? this.state.rawBuffer.toString(encoding) : void 0
1695
+ };
1696
+ },
1697
+ __infoField: function() {
1698
+ const { columns } = this.options;
1699
+ const isColumns = Array.isArray(columns);
1700
+ const bytes_records = this.info.bytes_records;
1701
+ return {
1702
+ ...this.__infoRecord(),
1703
+ bytes_records,
1704
+ column: isColumns === true ? columns.length > this.state.record.length ? columns[this.state.record.length].name : null : this.state.record.length,
1705
+ quoting: this.state.wasQuoting
1706
+ };
1707
+ }
1708
+ };
1709
+ };
1710
+
1711
+ // node_modules/csv-parse/lib/sync.js
1712
+ var parse = function(data, opts = {}) {
1713
+ if (typeof data === "string") {
1714
+ data = Buffer.from(data);
1715
+ }
1716
+ const records = opts && opts.objname ? /* @__PURE__ */ Object.create(null) : [];
1717
+ const parser = transform(opts);
1718
+ const push = (record) => {
1719
+ if (parser.options.objname === void 0) records.push(record);
1720
+ else {
1721
+ records[record[0]] = record[1];
1722
+ }
1723
+ };
1724
+ const close = () => {
1725
+ };
1726
+ const error = parser.parse(data, true, push, close);
1727
+ if (error !== void 0) throw error;
1728
+ return records;
1729
+ };
1730
+
1731
+ export {
1732
+ parse
1733
+ };