@loaders.gl/csv 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist/csv-loader.js +235 -186
- package/dist/csv-writer.js +17 -15
- package/dist/dist.dev.js +146 -85
- package/dist/dist.min.js +28 -0
- package/dist/index.cjs +16 -35
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/encoders/encode-csv.d.ts +1 -1
- package/dist/lib/encoders/encode-csv.d.ts.map +1 -1
- package/dist/lib/encoders/encode-csv.js +43 -35
- package/dist/papaparse/async-iterator-streamer.js +52 -25
- package/dist/papaparse/papaparse.js +867 -628
- package/package.json +10 -6
- package/dist/csv-loader.js.map +0 -1
- package/dist/csv-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/encoders/encode-csv.js.map +0 -1
- package/dist/papaparse/async-iterator-streamer.js.map +0 -1
- package/dist/papaparse/papaparse.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
3
|
module.exports = factory();
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['
|
|
6
|
-
else root['
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
7
|
"use strict";
|
|
8
8
|
var __exports__ = (() => {
|
|
9
|
+
var __create = Object.create;
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
10
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
14
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
};
|
|
13
19
|
var __export = (target, all) => {
|
|
14
20
|
for (var name in all)
|
|
15
21
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,18 +28,42 @@ var __exports__ = (() => {
|
|
|
22
28
|
}
|
|
23
29
|
return to;
|
|
24
30
|
};
|
|
31
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
25
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __publicField = (obj, key, value) => {
|
|
42
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
|
+
return value;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// external-global-plugin:@loaders.gl/core
|
|
47
|
+
var require_core = __commonJS({
|
|
48
|
+
"external-global-plugin:@loaders.gl/core"(exports, module) {
|
|
49
|
+
module.exports = globalThis.loaders;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
26
52
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
53
|
+
// bundle.ts
|
|
54
|
+
var bundle_exports = {};
|
|
55
|
+
__export(bundle_exports, {
|
|
30
56
|
CSVLoader: () => CSVLoader,
|
|
31
57
|
CSVWriter: () => CSVWriter
|
|
32
58
|
});
|
|
59
|
+
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
33
60
|
|
|
34
61
|
// ../schema/src/lib/table/batches/base-table-batch-aggregator.ts
|
|
35
62
|
var DEFAULT_ROW_COUNT = 100;
|
|
36
63
|
var BaseTableBatchAggregator = class {
|
|
64
|
+
schema;
|
|
65
|
+
options;
|
|
66
|
+
shape;
|
|
37
67
|
length = 0;
|
|
38
68
|
rows = null;
|
|
39
69
|
cursor = 0;
|
|
@@ -134,6 +164,8 @@ var __exports__ = (() => {
|
|
|
134
164
|
// ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
|
|
135
165
|
var DEFAULT_ROW_COUNT2 = 100;
|
|
136
166
|
var RowTableBatchAggregator = class {
|
|
167
|
+
schema;
|
|
168
|
+
options;
|
|
137
169
|
length = 0;
|
|
138
170
|
objectRows = null;
|
|
139
171
|
arrayRows = null;
|
|
@@ -199,6 +231,7 @@ var __exports__ = (() => {
|
|
|
199
231
|
batchType: "data",
|
|
200
232
|
data: rows,
|
|
201
233
|
length: this.length,
|
|
234
|
+
// @ts-expect-error we should infer a schema
|
|
202
235
|
schema: this.schema,
|
|
203
236
|
cursor: this.cursor
|
|
204
237
|
};
|
|
@@ -208,6 +241,7 @@ var __exports__ = (() => {
|
|
|
208
241
|
// ../schema/src/lib/table/batches/columnar-table-batch-aggregator.ts
|
|
209
242
|
var DEFAULT_ROW_COUNT3 = 100;
|
|
210
243
|
var ColumnarTableBatchAggregator = class {
|
|
244
|
+
schema;
|
|
211
245
|
length = 0;
|
|
212
246
|
allocated = 0;
|
|
213
247
|
columns = {};
|
|
@@ -252,6 +286,7 @@ var __exports__ = (() => {
|
|
|
252
286
|
};
|
|
253
287
|
return batch;
|
|
254
288
|
}
|
|
289
|
+
// HELPERS
|
|
255
290
|
_reallocateColumns() {
|
|
256
291
|
if (this.length < this.allocated) {
|
|
257
292
|
return;
|
|
@@ -290,7 +325,9 @@ var __exports__ = (() => {
|
|
|
290
325
|
_limitMB: 0
|
|
291
326
|
};
|
|
292
327
|
var ERR_MESSAGE = "TableBatchBuilder";
|
|
293
|
-
var
|
|
328
|
+
var _TableBatchBuilder = class {
|
|
329
|
+
schema;
|
|
330
|
+
options;
|
|
294
331
|
aggregator = null;
|
|
295
332
|
batchCount = 0;
|
|
296
333
|
bytesUsed = 0;
|
|
@@ -301,10 +338,7 @@ var __exports__ = (() => {
|
|
|
301
338
|
rowBytes = 0;
|
|
302
339
|
constructor(schema, options) {
|
|
303
340
|
this.schema = schema;
|
|
304
|
-
this.options = {
|
|
305
|
-
...DEFAULT_OPTIONS,
|
|
306
|
-
...options
|
|
307
|
-
};
|
|
341
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
308
342
|
}
|
|
309
343
|
limitReached() {
|
|
310
344
|
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
@@ -315,6 +349,7 @@ var __exports__ = (() => {
|
|
|
315
349
|
}
|
|
316
350
|
return false;
|
|
317
351
|
}
|
|
352
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
318
353
|
addRow(row) {
|
|
319
354
|
if (this.limitReached()) {
|
|
320
355
|
return;
|
|
@@ -328,6 +363,7 @@ var __exports__ = (() => {
|
|
|
328
363
|
this.addObjectRow(row);
|
|
329
364
|
}
|
|
330
365
|
}
|
|
366
|
+
/** Add one row to the batch */
|
|
331
367
|
addArrayRow(row) {
|
|
332
368
|
if (!this.aggregator) {
|
|
333
369
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -335,6 +371,7 @@ var __exports__ = (() => {
|
|
|
335
371
|
}
|
|
336
372
|
this.aggregator.addArrayRow(row);
|
|
337
373
|
}
|
|
374
|
+
/** Add one row to the batch */
|
|
338
375
|
addObjectRow(row) {
|
|
339
376
|
if (!this.aggregator) {
|
|
340
377
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -342,6 +379,7 @@ var __exports__ = (() => {
|
|
|
342
379
|
}
|
|
343
380
|
this.aggregator.addObjectRow(row);
|
|
344
381
|
}
|
|
382
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
345
383
|
chunkComplete(chunk) {
|
|
346
384
|
if (chunk instanceof ArrayBuffer) {
|
|
347
385
|
this.bytesUsed += chunk.byteLength;
|
|
@@ -357,6 +395,7 @@ var __exports__ = (() => {
|
|
|
357
395
|
getFinalBatch(options) {
|
|
358
396
|
return this._getBatch(options);
|
|
359
397
|
}
|
|
398
|
+
// INTERNAL
|
|
360
399
|
_estimateRowMB(row) {
|
|
361
400
|
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
362
401
|
}
|
|
@@ -378,6 +417,9 @@ var __exports__ = (() => {
|
|
|
378
417
|
this.lastBatchEmittedMs = Date.now();
|
|
379
418
|
return true;
|
|
380
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
422
|
+
*/
|
|
381
423
|
_getBatch(options) {
|
|
382
424
|
if (!this.aggregator) {
|
|
383
425
|
return null;
|
|
@@ -401,15 +443,17 @@ var __exports__ = (() => {
|
|
|
401
443
|
case "columnar-table":
|
|
402
444
|
return ColumnarTableBatchAggregator;
|
|
403
445
|
case "arrow-table":
|
|
404
|
-
if (!
|
|
446
|
+
if (!_TableBatchBuilder.ArrowBatch) {
|
|
405
447
|
throw new Error(ERR_MESSAGE);
|
|
406
448
|
}
|
|
407
|
-
return
|
|
449
|
+
return _TableBatchBuilder.ArrowBatch;
|
|
408
450
|
default:
|
|
409
451
|
return BaseTableBatchAggregator;
|
|
410
452
|
}
|
|
411
453
|
}
|
|
412
454
|
};
|
|
455
|
+
var TableBatchBuilder = _TableBatchBuilder;
|
|
456
|
+
__publicField(TableBatchBuilder, "ArrowBatch");
|
|
413
457
|
|
|
414
458
|
// ../schema/src/lib/table/simple-table/table-accessors.ts
|
|
415
459
|
function getTableLength(table) {
|
|
@@ -522,6 +566,9 @@ var __exports__ = (() => {
|
|
|
522
566
|
}
|
|
523
567
|
};
|
|
524
568
|
var AsyncQueue = class {
|
|
569
|
+
_values;
|
|
570
|
+
_settlers;
|
|
571
|
+
_closed;
|
|
525
572
|
constructor() {
|
|
526
573
|
this._values = new ArrayQueue();
|
|
527
574
|
this._settlers = new ArrayQueue();
|
|
@@ -529,9 +576,7 @@ var __exports__ = (() => {
|
|
|
529
576
|
}
|
|
530
577
|
close() {
|
|
531
578
|
while (this._settlers.length > 0) {
|
|
532
|
-
this._settlers.dequeue().resolve({
|
|
533
|
-
done: true
|
|
534
|
-
});
|
|
579
|
+
this._settlers.dequeue().resolve({ done: true });
|
|
535
580
|
}
|
|
536
581
|
this._closed = true;
|
|
537
582
|
}
|
|
@@ -550,37 +595,31 @@ var __exports__ = (() => {
|
|
|
550
595
|
if (value instanceof Error) {
|
|
551
596
|
settler.reject(value);
|
|
552
597
|
} else {
|
|
553
|
-
settler.resolve({
|
|
554
|
-
value
|
|
555
|
-
});
|
|
598
|
+
settler.resolve({ value });
|
|
556
599
|
}
|
|
557
600
|
} else {
|
|
558
601
|
this._values.enqueue(value);
|
|
559
602
|
}
|
|
560
603
|
}
|
|
604
|
+
/**
|
|
605
|
+
* @returns a Promise for an IteratorResult
|
|
606
|
+
*/
|
|
561
607
|
next() {
|
|
562
608
|
if (this._values.length > 0) {
|
|
563
609
|
const value = this._values.dequeue();
|
|
564
610
|
if (value instanceof Error) {
|
|
565
611
|
return Promise.reject(value);
|
|
566
612
|
}
|
|
567
|
-
return Promise.resolve({
|
|
568
|
-
value
|
|
569
|
-
});
|
|
613
|
+
return Promise.resolve({ value });
|
|
570
614
|
}
|
|
571
615
|
if (this._closed) {
|
|
572
616
|
if (this._settlers.length > 0) {
|
|
573
617
|
throw new Error("Illegal internal state");
|
|
574
618
|
}
|
|
575
|
-
return Promise.resolve({
|
|
576
|
-
done: true
|
|
577
|
-
});
|
|
619
|
+
return Promise.resolve({ done: true });
|
|
578
620
|
}
|
|
579
621
|
return new Promise((resolve, reject) => {
|
|
580
|
-
this._settlers.enqueue({
|
|
581
|
-
resolve,
|
|
582
|
-
reject
|
|
583
|
-
});
|
|
622
|
+
this._settlers.enqueue({ resolve, reject });
|
|
584
623
|
});
|
|
585
624
|
}
|
|
586
625
|
};
|
|
@@ -595,12 +634,19 @@ var __exports__ = (() => {
|
|
|
595
634
|
BYTE_ORDER_MARK,
|
|
596
635
|
BAD_DELIMITERS: ["\r", "\n", '"', BYTE_ORDER_MARK],
|
|
597
636
|
WORKERS_SUPPORTED: false,
|
|
637
|
+
// !IS_WORKER && !!globalThis.Worker
|
|
598
638
|
NODE_STREAM_INPUT: 1,
|
|
639
|
+
// Configurable chunk sizes for local and remote files, respectively
|
|
599
640
|
LocalChunkSize: 1024 * 1024 * 10,
|
|
641
|
+
// 10 M,
|
|
600
642
|
RemoteChunkSize: 1024 * 1024 * 5,
|
|
643
|
+
// 5 M,
|
|
601
644
|
DefaultDelimiter: ",",
|
|
645
|
+
// Used if not specified and detection fail,
|
|
646
|
+
// Exposed for testing and development only
|
|
602
647
|
Parser,
|
|
603
648
|
ParserHandle,
|
|
649
|
+
// BEGIN FORK
|
|
604
650
|
ChunkStreamer,
|
|
605
651
|
StringStreamer
|
|
606
652
|
};
|
|
@@ -874,6 +920,7 @@ var __exports__ = (() => {
|
|
|
874
920
|
var _delimiterError;
|
|
875
921
|
var _fields = [];
|
|
876
922
|
var _results = {
|
|
923
|
+
// The last results returned from the parser
|
|
877
924
|
data: [],
|
|
878
925
|
errors: [],
|
|
879
926
|
meta: {}
|
|
@@ -902,7 +949,13 @@ var __exports__ = (() => {
|
|
|
902
949
|
_config.newline = guessLineEndings(input, quoteChar);
|
|
903
950
|
_delimiterError = false;
|
|
904
951
|
if (!_config.delimiter) {
|
|
905
|
-
var delimGuess = guessDelimiter(
|
|
952
|
+
var delimGuess = guessDelimiter(
|
|
953
|
+
input,
|
|
954
|
+
_config.newline,
|
|
955
|
+
_config.skipEmptyLines,
|
|
956
|
+
_config.comments,
|
|
957
|
+
_config.delimitersToGuess
|
|
958
|
+
);
|
|
906
959
|
if (delimGuess.successful)
|
|
907
960
|
_config.delimiter = delimGuess.bestDelimiter;
|
|
908
961
|
else {
|
|
@@ -921,15 +974,7 @@ var __exports__ = (() => {
|
|
|
921
974
|
_parser = new Parser(parserConfig);
|
|
922
975
|
_results = _parser.parse(_input, baseIndex, ignoreLastRow);
|
|
923
976
|
processResults();
|
|
924
|
-
return _paused ? {
|
|
925
|
-
meta: {
|
|
926
|
-
paused: true
|
|
927
|
-
}
|
|
928
|
-
} : _results || {
|
|
929
|
-
meta: {
|
|
930
|
-
paused: false
|
|
931
|
-
}
|
|
932
|
-
};
|
|
977
|
+
return _paused ? { meta: { paused: true } } : _results || { meta: { paused: false } };
|
|
933
978
|
};
|
|
934
979
|
this.paused = function() {
|
|
935
980
|
return _paused;
|
|
@@ -959,7 +1004,11 @@ var __exports__ = (() => {
|
|
|
959
1004
|
}
|
|
960
1005
|
function processResults() {
|
|
961
1006
|
if (_results && _delimiterError) {
|
|
962
|
-
addError(
|
|
1007
|
+
addError(
|
|
1008
|
+
"Delimiter",
|
|
1009
|
+
"UndetectableDelimiter",
|
|
1010
|
+
"Unable to auto-detect delimiting character; defaulted to '" + Papa.DefaultDelimiter + "'"
|
|
1011
|
+
);
|
|
963
1012
|
_delimiterError = false;
|
|
964
1013
|
}
|
|
965
1014
|
if (_config.skipEmptyLines) {
|
|
@@ -1032,9 +1081,19 @@ var __exports__ = (() => {
|
|
|
1032
1081
|
}
|
|
1033
1082
|
if (_config.header) {
|
|
1034
1083
|
if (j > _fields.length)
|
|
1035
|
-
addError(
|
|
1084
|
+
addError(
|
|
1085
|
+
"FieldMismatch",
|
|
1086
|
+
"TooManyFields",
|
|
1087
|
+
"Too many fields: expected " + _fields.length + " fields but parsed " + j,
|
|
1088
|
+
_rowCounter + i
|
|
1089
|
+
);
|
|
1036
1090
|
else if (j < _fields.length)
|
|
1037
|
-
addError(
|
|
1091
|
+
addError(
|
|
1092
|
+
"FieldMismatch",
|
|
1093
|
+
"TooFewFields",
|
|
1094
|
+
"Too few fields: expected " + _fields.length + " fields but parsed " + j,
|
|
1095
|
+
_rowCounter + i
|
|
1096
|
+
);
|
|
1038
1097
|
}
|
|
1039
1098
|
return row;
|
|
1040
1099
|
}
|
|
@@ -1200,6 +1259,7 @@ var __exports__ = (() => {
|
|
|
1200
1259
|
code: "MissingQuotes",
|
|
1201
1260
|
message: "Quoted field unterminated",
|
|
1202
1261
|
row: data.length,
|
|
1262
|
+
// row has yet to be inserted
|
|
1203
1263
|
index: cursor
|
|
1204
1264
|
});
|
|
1205
1265
|
}
|
|
@@ -1251,6 +1311,7 @@ var __exports__ = (() => {
|
|
|
1251
1311
|
code: "InvalidQuotes",
|
|
1252
1312
|
message: "Trailing quote on quoted field is malformed",
|
|
1253
1313
|
row: data.length,
|
|
1314
|
+
// row has yet to be inserted
|
|
1254
1315
|
index: cursor
|
|
1255
1316
|
});
|
|
1256
1317
|
quoteSearch++;
|
|
@@ -1366,9 +1427,7 @@ var __exports__ = (() => {
|
|
|
1366
1427
|
}
|
|
1367
1428
|
|
|
1368
1429
|
// src/papaparse/async-iterator-streamer.ts
|
|
1369
|
-
var {
|
|
1370
|
-
ChunkStreamer: ChunkStreamer2
|
|
1371
|
-
} = papaparse_default;
|
|
1430
|
+
var { ChunkStreamer: ChunkStreamer2 } = papaparse_default;
|
|
1372
1431
|
function AsyncIteratorStreamer(config) {
|
|
1373
1432
|
config = config || {};
|
|
1374
1433
|
ChunkStreamer2.call(this, config);
|
|
@@ -1388,16 +1447,14 @@ var __exports__ = (() => {
|
|
|
1388
1447
|
this._nextChunk = function nextChunk() {
|
|
1389
1448
|
};
|
|
1390
1449
|
this.getStringChunk = function(chunk) {
|
|
1391
|
-
return typeof chunk === "string" ? chunk : this.textDecoder.decode(chunk, {
|
|
1392
|
-
stream: true
|
|
1393
|
-
});
|
|
1450
|
+
return typeof chunk === "string" ? chunk : this.textDecoder.decode(chunk, { stream: true });
|
|
1394
1451
|
};
|
|
1395
1452
|
}
|
|
1396
1453
|
AsyncIteratorStreamer.prototype = Object.create(ChunkStreamer2.prototype);
|
|
1397
1454
|
AsyncIteratorStreamer.prototype.constructor = AsyncIteratorStreamer;
|
|
1398
1455
|
|
|
1399
1456
|
// src/csv-loader.ts
|
|
1400
|
-
var VERSION =
|
|
1457
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1401
1458
|
var DEFAULT_CSV_SHAPE = "object-row-table";
|
|
1402
1459
|
var CSVLoader = {
|
|
1403
1460
|
id: "csv",
|
|
@@ -1410,33 +1467,40 @@ var __exports__ = (() => {
|
|
|
1410
1467
|
parse: async (arrayBuffer, options) => parseCSV(new TextDecoder().decode(arrayBuffer), options),
|
|
1411
1468
|
parseText: (text, options) => parseCSV(text, options),
|
|
1412
1469
|
parseInBatches: parseCSVInBatches,
|
|
1470
|
+
// @ts-ignore
|
|
1471
|
+
// testText: null,
|
|
1413
1472
|
options: {
|
|
1414
1473
|
csv: {
|
|
1415
1474
|
shape: DEFAULT_CSV_SHAPE,
|
|
1475
|
+
// 'object-row-table'
|
|
1416
1476
|
optimizeMemoryUsage: false,
|
|
1477
|
+
// CSV options
|
|
1417
1478
|
header: "auto",
|
|
1418
1479
|
columnPrefix: "column",
|
|
1480
|
+
// delimiter: auto
|
|
1481
|
+
// newline: auto
|
|
1419
1482
|
quoteChar: '"',
|
|
1420
1483
|
escapeChar: '"',
|
|
1421
1484
|
dynamicTyping: true,
|
|
1422
1485
|
comments: false,
|
|
1423
1486
|
skipEmptyLines: true,
|
|
1487
|
+
// transform: null?
|
|
1424
1488
|
delimitersToGuess: [",", " ", "|", ";"]
|
|
1489
|
+
// fastMode: auto
|
|
1425
1490
|
}
|
|
1426
1491
|
}
|
|
1427
1492
|
};
|
|
1428
1493
|
async function parseCSV(csvText, options) {
|
|
1429
|
-
const csvOptions = {
|
|
1430
|
-
...CSVLoader.options.csv,
|
|
1431
|
-
...options?.csv
|
|
1432
|
-
};
|
|
1494
|
+
const csvOptions = { ...CSVLoader.options.csv, ...options?.csv };
|
|
1433
1495
|
const firstRow = readFirstRow(csvText);
|
|
1434
1496
|
const header = csvOptions.header === "auto" ? isHeaderRow(firstRow) : Boolean(csvOptions.header);
|
|
1435
1497
|
const parseWithHeader = header;
|
|
1436
1498
|
const papaparseConfig = {
|
|
1499
|
+
// dynamicTyping: true,
|
|
1437
1500
|
...csvOptions,
|
|
1438
1501
|
header: parseWithHeader,
|
|
1439
1502
|
download: false,
|
|
1503
|
+
// We handle loading, no need for papaparse to do it for us
|
|
1440
1504
|
transformHeader: parseWithHeader ? duplicateColumnTransformer() : void 0,
|
|
1441
1505
|
error: (e) => {
|
|
1442
1506
|
throw new Error(e);
|
|
@@ -1462,27 +1526,35 @@ var __exports__ = (() => {
|
|
|
1462
1526
|
}
|
|
1463
1527
|
}
|
|
1464
1528
|
function parseCSVInBatches(asyncIterator, options) {
|
|
1465
|
-
options = {
|
|
1466
|
-
...options
|
|
1467
|
-
};
|
|
1529
|
+
options = { ...options };
|
|
1468
1530
|
if (options.batchSize === "auto") {
|
|
1469
1531
|
options.batchSize = 4e3;
|
|
1470
1532
|
}
|
|
1471
|
-
const csvOptions = {
|
|
1472
|
-
...CSVLoader.options.csv,
|
|
1473
|
-
...options?.csv
|
|
1474
|
-
};
|
|
1533
|
+
const csvOptions = { ...CSVLoader.options.csv, ...options?.csv };
|
|
1475
1534
|
const asyncQueue = new AsyncQueue();
|
|
1476
1535
|
let isFirstRow = true;
|
|
1477
1536
|
let headerRow = null;
|
|
1478
1537
|
let tableBatchBuilder = null;
|
|
1479
1538
|
let schema = null;
|
|
1480
1539
|
const config = {
|
|
1540
|
+
// dynamicTyping: true, // Convert numbers and boolean values in rows from strings,
|
|
1481
1541
|
...csvOptions,
|
|
1482
1542
|
header: false,
|
|
1543
|
+
// Unfortunately, header detection is not automatic and does not infer shapes
|
|
1483
1544
|
download: false,
|
|
1545
|
+
// We handle loading, no need for papaparse to do it for us
|
|
1546
|
+
// chunkSize is set to 5MB explicitly (same as Papaparse default) due to a bug where the
|
|
1547
|
+
// streaming parser gets stuck if skipEmptyLines and a step callback are both supplied.
|
|
1548
|
+
// See https://github.com/mholt/PapaParse/issues/465
|
|
1484
1549
|
chunkSize: 1024 * 1024 * 5,
|
|
1550
|
+
// skipEmptyLines is set to a boolean value if supplied. Greedy is set to true
|
|
1551
|
+
// skipEmptyLines is handled manually given two bugs where the streaming parser gets stuck if
|
|
1552
|
+
// both of the skipEmptyLines and step callback options are provided:
|
|
1553
|
+
// - true doesn't work unless chunkSize is set: https://github.com/mholt/PapaParse/issues/465
|
|
1554
|
+
// - greedy doesn't work: https://github.com/mholt/PapaParse/issues/825
|
|
1485
1555
|
skipEmptyLines: false,
|
|
1556
|
+
// step is called on every row
|
|
1557
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1486
1558
|
step(results) {
|
|
1487
1559
|
let row = results.data;
|
|
1488
1560
|
if (csvOptions.skipEmptyLines) {
|
|
@@ -1510,15 +1582,17 @@ var __exports__ = (() => {
|
|
|
1510
1582
|
row = JSON.parse(JSON.stringify(row));
|
|
1511
1583
|
}
|
|
1512
1584
|
const shape = csvOptions.shape || DEFAULT_CSV_SHAPE;
|
|
1513
|
-
tableBatchBuilder = tableBatchBuilder || new TableBatchBuilder(
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1585
|
+
tableBatchBuilder = tableBatchBuilder || new TableBatchBuilder(
|
|
1586
|
+
// @ts-expect-error TODO this is not a proper schema
|
|
1587
|
+
schema,
|
|
1588
|
+
{
|
|
1589
|
+
shape,
|
|
1590
|
+
...options
|
|
1591
|
+
}
|
|
1592
|
+
);
|
|
1517
1593
|
try {
|
|
1518
1594
|
tableBatchBuilder.addRow(row);
|
|
1519
|
-
const batch = tableBatchBuilder && tableBatchBuilder.getFullBatch({
|
|
1520
|
-
bytesUsed
|
|
1521
|
-
});
|
|
1595
|
+
const batch = tableBatchBuilder && tableBatchBuilder.getFullBatch({ bytesUsed });
|
|
1522
1596
|
if (batch) {
|
|
1523
1597
|
asyncQueue.enqueue(batch);
|
|
1524
1598
|
}
|
|
@@ -1526,12 +1600,11 @@ var __exports__ = (() => {
|
|
|
1526
1600
|
asyncQueue.enqueue(error);
|
|
1527
1601
|
}
|
|
1528
1602
|
},
|
|
1603
|
+
// complete is called when all rows have been read
|
|
1529
1604
|
complete(results) {
|
|
1530
1605
|
try {
|
|
1531
1606
|
const bytesUsed = results.meta.cursor;
|
|
1532
|
-
const batch = tableBatchBuilder && tableBatchBuilder.getFinalBatch({
|
|
1533
|
-
bytesUsed
|
|
1534
|
-
});
|
|
1607
|
+
const batch = tableBatchBuilder && tableBatchBuilder.getFinalBatch({ bytesUsed });
|
|
1535
1608
|
if (batch) {
|
|
1536
1609
|
asyncQueue.enqueue(batch);
|
|
1537
1610
|
}
|
|
@@ -1583,19 +1656,11 @@ var __exports__ = (() => {
|
|
|
1583
1656
|
switch (typeof value) {
|
|
1584
1657
|
case "number":
|
|
1585
1658
|
case "boolean":
|
|
1586
|
-
schema[columnName] = {
|
|
1587
|
-
name: String(columnName),
|
|
1588
|
-
index: i,
|
|
1589
|
-
type: Float32Array
|
|
1590
|
-
};
|
|
1659
|
+
schema[columnName] = { name: String(columnName), index: i, type: Float32Array };
|
|
1591
1660
|
break;
|
|
1592
1661
|
case "string":
|
|
1593
1662
|
default:
|
|
1594
|
-
schema[columnName] = {
|
|
1595
|
-
name: String(columnName),
|
|
1596
|
-
index: i,
|
|
1597
|
-
type: Array
|
|
1598
|
-
};
|
|
1663
|
+
schema[columnName] = { name: String(columnName), index: i, type: Array };
|
|
1599
1664
|
}
|
|
1600
1665
|
}
|
|
1601
1666
|
return schema;
|
|
@@ -1748,11 +1813,7 @@ var __exports__ = (() => {
|
|
|
1748
1813
|
var csvFormatValue = csv.formatValue;
|
|
1749
1814
|
|
|
1750
1815
|
// src/lib/encoders/encode-csv.ts
|
|
1751
|
-
function encodeTableAsCSV(table, options = {
|
|
1752
|
-
csv: {
|
|
1753
|
-
useDisplayNames: true
|
|
1754
|
-
}
|
|
1755
|
-
}) {
|
|
1816
|
+
function encodeTableAsCSV(table, options = { csv: { useDisplayNames: true } }) {
|
|
1756
1817
|
const useDisplayNames = options.useDisplayNames || options.csv?.useDisplayNames;
|
|
1757
1818
|
const fields = table.schema?.fields || [];
|
|
1758
1819
|
const columnNames = fields.map((f) => {
|
|
@@ -1800,7 +1861,7 @@ var __exports__ = (() => {
|
|
|
1800
1861
|
encode: async (table, options) => new TextEncoder().encode(encodeTableAsCSV(table, options)).buffer,
|
|
1801
1862
|
encodeTextSync: (table, options) => encodeTableAsCSV(table, options)
|
|
1802
1863
|
};
|
|
1803
|
-
return __toCommonJS(
|
|
1864
|
+
return __toCommonJS(bundle_exports);
|
|
1804
1865
|
})();
|
|
1805
1866
|
/* @license
|
|
1806
1867
|
Papa Parse
|
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";var __exports__=(()=>{var ze=Object.create;var Q=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var We=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty;var $e=(t,e,r)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Ze=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ke=(t,e)=>{for(var r in e)Q(t,r,{get:e[r],enumerable:!0})},ae=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ve(e))!Je.call(t,o)&&o!==r&&Q(t,o,{get:()=>e[o],enumerable:!(a=He(e,o))||a.enumerable});return t},se=(t,e,r)=>(ae(t,e,"default"),r&&ae(r,e,"default")),Qe=(t,e,r)=>(r=t!=null?ze(We(t)):{},ae(e||!t||!t.__esModule?Q(r,"default",{value:t,enumerable:!0}):r,t)),Ye=t=>ae(Q({},"__esModule",{value:!0}),t);var Re=(t,e,r)=>($e(t,typeof e!="symbol"?e+"":e,r),r);var Ce=Ze((wt,Ae)=>{Ae.exports=globalThis.loaders});var te={};Ke(te,{CSVLoader:()=>ce,CSVWriter:()=>qe});se(te,Qe(Ce(),1));var ne=class{schema;options;shape;length=0;rows=null;cursor=0;_headers=[];constructor(e,r){if(this.options=r,this.schema=e,!Array.isArray(e)){this._headers=[];for(let a in e)this._headers[e[a].index]=e[a].name}}rowCount(){return this.length}addArrayRow(e,r){Number.isFinite(r)&&(this.cursor=r),this.shape="array-row-table",this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}addObjectRow(e,r){Number.isFinite(r)&&(this.cursor=r),this.shape="object-row-table",this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}getBatch(){let e=this.rows;return e?(e=e.slice(0,this.length),this.rows=null,{shape:this.shape||"array-row-table",batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}):null}};function Y(t,e){if(!t)throw new Error("null row");let r={};if(e)for(let a=0;a<e.length;a++)r[e[a]]=t[a];else for(let a=0;a<t.length;a++){let o=`column-${a}`;r[o]=t[a]}return r}function X(t,e){if(!t)throw new Error("null row");if(e){let r=new Array(e.length);for(let a=0;a<e.length;a++)r[a]=t[e[a]];return r}return Object.values(t)}function xe(t){let e=[];for(let r=0;r<t.length;r++){let a=`column-${r}`;e.push(a)}return e}function Ee(t){return Object.keys(t)}var je=100,oe=class{schema;options;length=0;objectRows=null;arrayRows=null;cursor=0;_headers=null;constructor(e,r){if(this.options=r,this.schema=e,e){this._headers=[];for(let a in e)this._headers[e[a].index]=e[a].name}}rowCount(){return this.length}addArrayRow(e,r){switch(Number.isFinite(r)&&(this.cursor=r),this._headers||=xe(e),this.options.shape){case"object-row-table":let a=Y(e,this._headers);this.addObjectRow(a,r);break;case"array-row-table":this.arrayRows=this.arrayRows||new Array(je),this.arrayRows[this.length]=e,this.length++;break}}addObjectRow(e,r){switch(Number.isFinite(r)&&(this.cursor=r),this._headers||=Ee(e),this.options.shape){case"array-row-table":let a=X(e,this._headers);this.addArrayRow(a,r);break;case"object-row-table":this.objectRows=this.objectRows||new Array(je),this.objectRows[this.length]=e,this.length++;break}}getBatch(){let e=this.arrayRows||this.objectRows;return e?(e=e.slice(0,this.length),this.arrayRows=null,this.objectRows=null,{shape:this.options.shape,batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}):null}};var ie=class{schema;length=0;allocated=0;columns={};constructor(e,r){this.schema=e,this._reallocateColumns()}rowCount(){return this.length}addArrayRow(e){this._reallocateColumns();let r=0;for(let a in this.columns)this.columns[a][this.length]=e[r++];this.length++}addObjectRow(e){this._reallocateColumns();for(let r in e)this.columns[r][this.length]=e[r];this.length++}getBatch(){this._pruneColumns();let e=Array.isArray(this.schema)?this.columns:{};if(!Array.isArray(this.schema))for(let a in this.schema){let o=this.schema[a];e[o.name]=this.columns[o.index]}return this.columns={},{shape:"columnar-table",batchType:"data",data:e,schema:this.schema,length:this.length}}_reallocateColumns(){if(!(this.length<this.allocated)){this.allocated=this.allocated>0?this.allocated*=2:100,this.columns={};for(let e in this.schema){let r=this.schema[e],a=r.type||Float32Array,o=this.columns[r.index];if(o&&ArrayBuffer.isView(o)){let c=new a(this.allocated);c.set(o),this.columns[r.index]=c}else o?(o.length=this.allocated,this.columns[r.index]=o):this.columns[r.index]=new a(this.allocated)}}}_pruneColumns(){for(let[e,r]of Object.entries(this.columns))this.columns[e]=r.slice(0,this.length)}};var Xe={shape:void 0,batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0},Ge="TableBatchBuilder",he=class{schema;options;aggregator=null;batchCount=0;bytesUsed=0;isChunkComplete=!1;lastBatchEmittedMs=Date.now();totalLength=0;totalBytes=0;rowBytes=0;constructor(e,r){this.schema=e,this.options={...Xe,...r}}limitReached(){return!!(Boolean(this.options?.limit)&&this.totalLength>=this.options.limit||Boolean(this.options?._limitMB)&&this.totalBytes/1e6>=this.options._limitMB)}addRow(e){this.limitReached()||(this.totalLength++,this.rowBytes=this.rowBytes||this._estimateRowMB(e),this.totalBytes+=this.rowBytes,Array.isArray(e)?this.addArrayRow(e):this.addObjectRow(e))}addArrayRow(e){if(!this.aggregator){let r=this._getTableBatchType();this.aggregator=new r(this.schema,this.options)}this.aggregator.addArrayRow(e)}addObjectRow(e){if(!this.aggregator){let r=this._getTableBatchType();this.aggregator=new r(this.schema,this.options)}this.aggregator.addObjectRow(e)}chunkComplete(e){e instanceof ArrayBuffer&&(this.bytesUsed+=e.byteLength),typeof e=="string"&&(this.bytesUsed+=e.length),this.isChunkComplete=!0}getFullBatch(e){return this._isFull()?this._getBatch(e):null}getFinalBatch(e){return this._getBatch(e)}_estimateRowMB(e){return Array.isArray(e)?e.length*8:Object.keys(e).length*8}_isFull(){if(!this.aggregator||this.aggregator.rowCount()===0)return!1;if(this.options.batchSize==="auto"){if(!this.isChunkComplete)return!1}else if(this.options.batchSize>this.aggregator.rowCount())return!1;return this.options.batchDebounceMs>Date.now()-this.lastBatchEmittedMs?!1:(this.isChunkComplete=!1,this.lastBatchEmittedMs=Date.now(),!0)}_getBatch(e){if(!this.aggregator)return null;e?.bytesUsed&&(this.bytesUsed=e.bytesUsed);let r=this.aggregator.getBatch();return r.count=this.batchCount,r.bytesUsed=this.bytesUsed,Object.assign(r,e),this.batchCount++,this.aggregator=null,r}_getTableBatchType(){switch(this.options.shape){case"array-row-table":case"object-row-table":return oe;case"columnar-table":return ie;case"arrow-table":if(!he.ArrowBatch)throw new Error(Ge);return he.ArrowBatch;default:return ne}}},H=he;Re(H,"ArrowBatch");function ue(t){switch(t.shape){case"array-row-table":case"object-row-table":return t.data.length;case"geojson-table":return t.features.length;case"arrow-table":return t.data.numRows;case"columnar-table":for(let r of Object.values(t.data))return r.length||0;return 0;default:throw new Error("table")}}function fe(t){if(t.schema)return t.schema.fields.length;if(ue(t)===0)throw new Error("empty table");switch(t.shape){case"array-row-table":return t.data[0].length;case"object-row-table":return Object.keys(t.data[0]).length;case"geojson-table":return Object.keys(t.features[0]).length;case"columnar-table":return Object.keys(t.data).length;case"arrow-table":return t.data.numCols;default:throw new Error("table")}}function Oe(t,e,r,a){switch(t.shape){case"array-row-table":return a?Array.from(t.data[e]):t.data[e];case"object-row-table":if(t.schema){let u=r||[];for(let n=0;n<t.schema.fields.length;n++)u[n]=t.data[e][t.schema.fields[n].name];return u}return Object.values(t.data[e]);case"geojson-table":if(t.schema){let u=r||[];for(let n=0;n<t.schema.fields.length;n++)u[n]=t.features[e][t.schema.fields[n].name];return u}return Object.values(t.features[e]);case"columnar-table":if(t.schema){let u=r||[];for(let n=0;n<t.schema.fields.length;n++)u[n]=t.data[t.schema.fields[n].name][e];return u}else{let u=r||[],n=0;for(let y of Object.values(t.data))u[n]=y[e],n++;return u}case"arrow-table":let o=t.data,c=r||[],l=o.get(e),d=o.schema;for(let u=0;u<d.fields.length;u++)c[u]=l?.[d.fields[u].name];return c;default:throw new Error("shape")}}function*de(t,e=[]){let r=ue(t);for(let a=0;a<r;a++)yield Oe(t,a,e)}var le=class extends Array{enqueue(e){return this.push(e)}dequeue(){return this.shift()}},V=class{_values;_settlers;_closed;constructor(){this._values=new le,this._settlers=new le,this._closed=!1}close(){for(;this._settlers.length>0;)this._settlers.dequeue().resolve({done:!0});this._closed=!0}[Symbol.asyncIterator](){return this}enqueue(e){if(this._closed)throw new Error("Closed");if(this._settlers.length>0){if(this._values.length>0)throw new Error("Illegal internal state");let r=this._settlers.dequeue();e instanceof Error?r.reject(e):r.resolve({value:e})}else this._values.enqueue(e)}next(){if(this._values.length>0){let e=this._values.dequeue();return e instanceof Error?Promise.reject(e):Promise.resolve({value:e})}if(this._closed){if(this._settlers.length>0)throw new Error("Illegal internal state");return Promise.resolve({done:!0})}return new Promise((e,r)=>{this._settlers.enqueue({resolve:e,reject:r})})}};var Se="\uFEFF",I={parse:et,unparse:tt,RECORD_SEP:String.fromCharCode(30),UNIT_SEP:String.fromCharCode(31),BYTE_ORDER_MARK:Se,BAD_DELIMITERS:["\r",`
|
|
8
|
+
`,'"',Se],WORKERS_SUPPORTED:!1,NODE_STREAM_INPUT:1,LocalChunkSize:10485760,RemoteChunkSize:5242880,DefaultDelimiter:",",Parser:me,ParserHandle:Fe,ChunkStreamer:ke,StringStreamer:W},J=I;function et(t,e,r){e=e||{};var a=e.dynamicTyping||!1;if(N(a)&&(e.dynamicTypingFunction=a,a={}),e.dynamicTyping=a,e.transform=N(e.transform)?e.transform:!1,e.worker&&I.WORKERS_SUPPORTED){var o=newWorker();o.userStep=e.step,o.userChunk=e.chunk,o.userComplete=e.complete,o.userError=e.error,e.step=N(e.step),e.chunk=N(e.chunk),e.complete=N(e.complete),e.error=N(e.error),delete e.worker,o.postMessage({input:t,config:e,workerId:o.id});return}var c=null;return typeof t=="string"&&(c=new W(e)),c||(c=new r(e)),c.stream(t)}function tt(t,e){var r=!1,a=!0,o=",",c=`\r
|
|
9
|
+
`,l='"',d=l+l,u=!1,n=null;s();var y=new RegExp(G(l),"g");if(typeof t=="string"&&(t=JSON.parse(t)),Array.isArray(t)){if(!t.length||Array.isArray(t[0]))return v(null,t,u);if(typeof t[0]=="object")return v(n||i(t[0]),t,u)}else if(typeof t=="object")return typeof t.data=="string"&&(t.data=JSON.parse(t.data)),Array.isArray(t.data)&&(t.fields||(t.fields=t.meta&&t.meta.fields),t.fields||(t.fields=Array.isArray(t.data[0])?t.fields:i(t.data[0])),!Array.isArray(t.data[0])&&typeof t.data[0]!="object"&&(t.data=[t.data])),v(t.fields||[],t.data||[],u);throw new Error("Unable to serialize unrecognized input");function s(){if(typeof e=="object"){if(typeof e.delimiter=="string"&&!I.BAD_DELIMITERS.filter(function(f){return e.delimiter.indexOf(f)!==-1}).length&&(o=e.delimiter),(typeof e.quotes=="boolean"||Array.isArray(e.quotes))&&(r=e.quotes),(typeof e.skipEmptyLines=="boolean"||typeof e.skipEmptyLines=="string")&&(u=e.skipEmptyLines),typeof e.newline=="string"&&(c=e.newline),typeof e.quoteChar=="string"&&(l=e.quoteChar),typeof e.header=="boolean"&&(a=e.header),Array.isArray(e.columns)){if(e.columns.length===0)throw new Error("Option columns is empty");n=e.columns}e.escapeChar!==void 0&&(d=e.escapeChar+l)}}function i(f){if(typeof f!="object")return[];var w=[];for(var T in f)w.push(T);return w}function v(f,w,T){var b="";typeof f=="string"&&(f=JSON.parse(f)),typeof w=="string"&&(w=JSON.parse(w));var D=Array.isArray(f)&&f.length>0,C=!Array.isArray(w[0]);if(D&&a){for(var B=0;B<f.length;B++)B>0&&(b+=o),b+=j(f[B],B);w.length>0&&(b+=c)}for(var x=0;x<w.length;x++){var h=D?f.length:w[x].length,m=!1,g=D?Object.keys(w[x]).length===0:w[x].length===0;if(T&&!D&&(m=T==="greedy"?w[x].join("").trim()==="":w[x].length===1&&w[x][0].length===0),T==="greedy"&&D){for(var S=[],p=0;p<h;p++){var R=C?f[p]:p;S.push(w[x][R])}m=S.join("").trim()===""}if(!m){for(var E=0;E<h;E++){E>0&&!g&&(b+=o);var k=D&&C?f[E]:E;b+=j(w[x][k],E)}x<w.length-1&&(!T||h>0&&!g)&&(b+=c)}}return b}function j(f,w){if(typeof f>"u"||f===null)return"";if(f.constructor===Date)return JSON.stringify(f).slice(1,25);f=f.toString().replace(y,d);var T=typeof r=="boolean"&&r||Array.isArray(r)&&r[w]||A(f,I.BAD_DELIMITERS)||f.indexOf(o)>-1||f.charAt(0)===" "||f.charAt(f.length-1)===" ";return T?l+f+l:f}function A(f,w){for(var T=0;T<w.length;T++)if(f.indexOf(w[T])>-1)return!0;return!1}}function ke(t){this._handle=null,this._finished=!1,this._completed=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},e.call(this,t),this.parseChunk=function(r,a){if(this.isFirstChunk&&N(this._config.beforeFirstChunk)){var o=this._config.beforeFirstChunk(r);o!==void 0&&(r=o)}this.isFirstChunk=!1;var c=this._partialLine+r;this._partialLine="";var l=this._handle.parse(c,this._baseIndex,!this._finished);if(!(this._handle.paused()||this._handle.aborted())){var d=l.meta.cursor;this._finished||(this._partialLine=c.substring(d-this._baseIndex),this._baseIndex=d),l&&l.data&&(this._rowCount+=l.data.length);var u=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(N(this._config.chunk)&&!a){if(this._config.chunk(l,this._handle),this._handle.paused()||this._handle.aborted())return;l=void 0,this._completeResults=void 0}return!this._config.step&&!this._config.chunk&&(this._completeResults.data=this._completeResults.data.concat(l.data),this._completeResults.errors=this._completeResults.errors.concat(l.errors),this._completeResults.meta=l.meta),!this._completed&&u&&N(this._config.complete)&&(!l||!l.meta.aborted)&&(this._config.complete(this._completeResults,this._input),this._completed=!0),!u&&(!l||!l.meta.paused)&&this._nextChunk(),l}},this._sendError=function(r){N(this._config.error)&&this._config.error(r)};function e(r){var a=pe(r);a.chunkSize=parseInt(a.chunkSize),!r.step&&!r.chunk&&(a.chunkSize=null),this._handle=new Fe(a),this._handle.streamer=this,this._config=a}}function W(t){t=t||{},ke.call(this,t);var e;this.stream=function(r){return e=r,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var r=this._config.chunkSize,a=r?e.substr(0,r):e;return e=r?e.substr(r):"",this._finished=!e,this.parseChunk(a)}}}W.prototype=Object.create(W.prototype);W.prototype.constructor=W;function Fe(t){var e=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,r=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,a=this,o=0,c=0,l,d,u=!1,n=!1,y,s=[],i={data:[],errors:[],meta:{}};if(N(t.step)){var v=t.step;t.step=function(h){if(i=h,f())A();else{if(A(),!i.data||i.data.length===0)return;o+=h.data.length,t.preview&&o>t.preview?d.abort():v(i,a)}}}this.parse=function(h,m,g){var S=t.quoteChar||'"';if(t.newline||(t.newline=B(h,S)),y=!1,t.delimiter)N(t.delimiter)&&(t.delimiter=t.delimiter(h),i.meta.delimiter=t.delimiter);else{var p=C(h,t.newline,t.skipEmptyLines,t.comments,t.delimitersToGuess);p.successful?t.delimiter=p.bestDelimiter:(y=!0,t.delimiter=I.DefaultDelimiter),i.meta.delimiter=t.delimiter}var R=pe(t);return t.preview&&t.header&&R.preview++,l=h,d=new me(R),i=d.parse(l,m,g),A(),u?{meta:{paused:!0}}:i||{meta:{paused:!1}}},this.paused=function(){return u},this.pause=function(){u=!0,d.abort(),l=l.substr(d.getCharIndex())},this.resume=function(){u=!1,a.streamer.parseChunk(l,!0)},this.aborted=function(){return n},this.abort=function(){n=!0,d.abort(),i.meta.aborted=!0,N(t.complete)&&t.complete(i),l=""};function j(h){return t.skipEmptyLines==="greedy"?h.join("").trim()==="":h.length===1&&h[0].length===0}function A(){if(i&&y&&(x("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+I.DefaultDelimiter+"'"),y=!1),t.skipEmptyLines)for(var h=0;h<i.data.length;h++)j(i.data[h])&&i.data.splice(h--,1);return f()&&w(),D()}function f(){return t.header&&s.length===0}function w(){if(!i)return;function h(g){N(t.transformHeader)&&(g=t.transformHeader(g)),s.push(g)}if(Array.isArray(i.data[0])){for(var m=0;f()&&m<i.data.length;m++)i.data[m].forEach(h);i.data.splice(0,1)}else i.data.forEach(h)}function T(h){return t.dynamicTypingFunction&&t.dynamicTyping[h]===void 0&&(t.dynamicTyping[h]=t.dynamicTypingFunction(h)),(t.dynamicTyping[h]||t.dynamicTyping)===!0}function b(h,m){return T(h)?m==="true"||m==="TRUE"?!0:m==="false"||m==="FALSE"?!1:e.test(m)?parseFloat(m):r.test(m)?new Date(m):m===""?null:m:m}function D(){if(!i||!i.data||!t.header&&!t.dynamicTyping&&!t.transform)return i;function h(g,S){var p=t.header?{}:[],R;for(R=0;R<g.length;R++){var E=R,k=g[R];t.header&&(E=R>=s.length?"__parsed_extra":s[R]),t.transform&&(k=t.transform(k,E)),k=b(E,k),E==="__parsed_extra"?(p[E]=p[E]||[],p[E].push(k)):p[E]=k}return t.header&&(R>s.length?x("FieldMismatch","TooManyFields","Too many fields: expected "+s.length+" fields but parsed "+R,c+S):R<s.length&&x("FieldMismatch","TooFewFields","Too few fields: expected "+s.length+" fields but parsed "+R,c+S)),p}var m=1;return!i.data[0]||Array.isArray(i.data[0])?(i.data=i.data.map(h),m=i.data.length):i.data=h(i.data,0),t.header&&i.meta&&(i.meta.fields=s),c+=m,i}function C(h,m,g,S,p){var R,E,k;p=p||[","," ","|",";",I.RECORD_SEP,I.UNIT_SEP];for(var q=0;q<p.length;q++){var M=p[q],z=0,L=0,Z=0;k=void 0;for(var O=new me({comments:S,delimiter:M,newline:m,preview:10}).parse(h),_=0;_<O.data.length;_++){if(g&&j(O.data[_])){Z++;continue}var F=O.data[_].length;if(L+=F,typeof k>"u"){k=0;continue}else F>1&&(z+=Math.abs(F-k),k=F)}O.data.length>0&&(L/=O.data.length-Z),(typeof E>"u"||z>E)&&L>1.99&&(E=z,R=M)}return t.delimiter=R,{successful:!!R,bestDelimiter:R}}function B(h,m){h=h.substr(0,1024*1024);var g=new RegExp(G(m)+"([^]*?)"+G(m),"gm");h=h.replace(g,"");var S=h.split("\r"),p=h.split(`
|
|
10
|
+
`),R=p.length>1&&p[0].length<S[0].length;if(S.length===1||R)return`
|
|
11
|
+
`;for(var E=0,k=0;k<S.length;k++)S[k][0]===`
|
|
12
|
+
`&&E++;return E>=S.length/2?`\r
|
|
13
|
+
`:"\r"}function x(h,m,g,S){i.errors.push({type:h,code:m,message:g,row:S})}}function G(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function me(t){t=t||{};var e=t.delimiter,r=t.newline,a=t.comments,o=t.step,c=t.preview,l=t.fastMode,d;t.quoteChar===void 0?d='"':d=t.quoteChar;var u=d;if(t.escapeChar!==void 0&&(u=t.escapeChar),(typeof e!="string"||I.BAD_DELIMITERS.indexOf(e)>-1)&&(e=","),a===e)throw new Error("Comment character same as delimiter");a===!0?a="#":(typeof a!="string"||I.BAD_DELIMITERS.indexOf(a)>-1)&&(a=!1),r!==`
|
|
14
|
+
`&&r!=="\r"&&r!==`\r
|
|
15
|
+
`&&(r=`
|
|
16
|
+
`);var n=0,y=!1;this.parse=function(s,i,v){if(typeof s!="string")throw new Error("Input must be a string");var j=s.length,A=e.length,f=r.length,w=a.length,T=N(o);n=0;var b=[],D=[],C=[],B=0;if(!s)return O();if(l||l!==!1&&s.indexOf(d)===-1){for(var x=s.split(r),h=0;h<x.length;h++){if(C=x[h],n+=C.length,h!==x.length-1)n+=r.length;else if(v)return O();if(!(a&&C.substr(0,w)===a)){if(T){if(b=[],M(C.split(e)),_(),y)return O()}else M(C.split(e));if(c&&h>=c)return b=b.slice(0,c),O(!0)}}return O()}for(var m=s.indexOf(e,n),g=s.indexOf(r,n),S=new RegExp(G(u)+G(d),"g"),p;;){if(s[n]===d){for(p=n,n++;;){if(p=s.indexOf(d,p+1),p===-1)return v||D.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:b.length,index:n}),L();if(p===j-1){var R=s.substring(n,p).replace(S,d);return L(R)}if(d===u&&s[p+1]===u){p++;continue}if(!(d!==u&&p!==0&&s[p-1]===u)){var E=g===-1?m:Math.min(m,g),k=z(E);if(s[p+1+k]===e){if(C.push(s.substring(n,p).replace(S,d)),n=p+1+k+A,m=s.indexOf(e,n),g=s.indexOf(r,n),T&&(_(),y))return O();if(c&&b.length>=c)return O(!0);break}var q=z(g);if(s.substr(p+1+q,f)===r){if(C.push(s.substring(n,p).replace(S,d)),Z(p+1+q+f),m=s.indexOf(e,n),T&&(_(),y))return O();if(c&&b.length>=c)return O(!0);break}D.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:b.length,index:n}),p++}}if(T&&(_(),y))return O();if(c&&b.length>=c)return O(!0);continue}if(a&&C.length===0&&s.substr(n,w)===a){if(g===-1)return O();n=g+f,g=s.indexOf(r,n),m=s.indexOf(e,n);continue}if(m!==-1&&(m<g||g===-1)){C.push(s.substring(n,m)),n=m+A,m=s.indexOf(e,n);continue}if(g!==-1){if(C.push(s.substring(n,g)),Z(g+f),T&&(_(),y))return O();if(c&&b.length>=c)return O(!0);continue}break}return L();function M(F){b.push(F),B=n}function z(F){var re=0;if(F!==-1){var K=s.substring(p+1,F);K&&K.trim()===""&&(re=K.length)}return re}function L(F){return v||(typeof F>"u"&&(F=s.substr(n)),C.push(F),n=j,M(C),T&&_()),O()}function Z(F){n=F,M(C),C=[],g=s.indexOf(r,n)}function O(F,re){var K=re||!1;return{data:K?b[0]:b,errors:D,meta:{delimiter:e,linebreak:r,aborted:y,truncated:!!F,cursor:B+(i||0)}}}function _(){o(O(void 0,!0)),b=[],D=[]}},this.abort=function(){y=!0},this.getCharIndex=function(){return n}}function pe(t){if(typeof t!="object"||t===null)return t;var e=Array.isArray(t)?[]:{};for(var r in t)e[r]=pe(t[r]);return e}function N(t){return typeof t=="function"}var{ChunkStreamer:De}=J;function $(t){t=t||{},De.call(this,t),this.textDecoder=new TextDecoder(this._config.encoding),this.stream=async function(e){this._input=e;try{for await(let r of e)this.parseChunk(this.getStringChunk(r));this._finished=!0,this.parseChunk("")}catch(r){this._sendError(r)}},this._nextChunk=function(){},this.getStringChunk=function(e){return typeof e=="string"?e:this.textDecoder.decode(e,{stream:!0})}}$.prototype=Object.create(De.prototype);$.prototype.constructor=$;var rt="4.2.0-alpha.5",ye="object-row-table",ce={id:"csv",module:"csv",name:"CSV",version:rt,extensions:["csv","tsv","dsv"],mimeTypes:["text/csv","text/tab-separated-values","text/dsv"],category:"table",parse:async(t,e)=>Be(new TextDecoder().decode(t),e),parseText:(t,e)=>Be(t,e),parseInBatches:at,options:{csv:{shape:ye,optimizeMemoryUsage:!1,header:"auto",columnPrefix:"column",quoteChar:'"',escapeChar:'"',dynamicTyping:!0,comments:!1,skipEmptyLines:!0,delimitersToGuess:[","," ","|",";"]}}};async function Be(t,e){let r={...ce.options.csv,...e?.csv},a=st(t),c=r.header==="auto"?Ne(a):Boolean(r.header),l={...r,header:c,download:!1,transformHeader:c?Ue():void 0,error:s=>{throw new Error(s)}},d=J.parse(t,l),u=d.data,n=d.meta.fields||_e(r.columnPrefix,a.length),y=r.shape||ye;switch(y){case"object-row-table":return{shape:"object-row-table",data:u.map(s=>Array.isArray(s)?Y(s,n):s)};case"array-row-table":return{shape:"array-row-table",data:u.map(s=>Array.isArray(s)?s:X(s,n))};default:throw new Error(y)}}function at(t,e){e={...e},e.batchSize==="auto"&&(e.batchSize=4e3);let r={...ce.options.csv,...e?.csv},a=new V,o=!0,c=null,l=null,d=null,u={...r,header:!1,download:!1,chunkSize:1024*1024*5,skipEmptyLines:!1,step(n){let y=n.data;if(r.skipEmptyLines&&y.flat().join("").trim()==="")return;let s=n.meta.cursor;if(o&&!c&&(r.header==="auto"?Ne(y):Boolean(r.header))){c=y.map(Ue());return}o&&(o=!1,c||(c=_e(r.columnPrefix,y.length)),d=nt(y,c)),r.optimizeMemoryUsage&&(y=JSON.parse(JSON.stringify(y)));let i=r.shape||ye;l=l||new H(d,{shape:i,...e});try{l.addRow(y);let v=l&&l.getFullBatch({bytesUsed:s});v&&a.enqueue(v)}catch(v){a.enqueue(v)}},complete(n){try{let y=n.meta.cursor,s=l&&l.getFinalBatch({bytesUsed:y});s&&a.enqueue(s)}catch(y){a.enqueue(y)}a.close()}};return J.parse(t,u,$),a}function Ne(t){return t&&t.every(e=>typeof e=="string")}function st(t){return J.parse(t,{download:!1,dynamicTyping:!0,preview:1}).data[0]}function Ue(){let t=new Set;return e=>{let r=e,a=1;for(;t.has(r);)r=`${e}.${a}`,a++;return t.add(r),r}}function _e(t,e=0){let r=[];for(let a=0;a<e;a++)r.push(`${t}${a+1}`);return r}function nt(t,e){let r=e?{}:[];for(let a=0;a<t.length;a++){let o=e&&e[a]||a;switch(typeof t[a]){case"number":case"boolean":r[o]={name:String(o),index:a,type:Float32Array};break;case"string":default:r[o]={name:String(o),index:a,type:Array}}}return r}var Ie={},we={},ge=34,ee=10,be=13;function Le(t){return new Function("d","return {"+t.map(function(e,r){return JSON.stringify(e)+": d["+r+'] || ""'}).join(",")+"}")}function ot(t,e){var r=Le(t);return function(a,o){return e(r(a),o,t)}}function Me(t){var e=Object.create(null),r=[];return t.forEach(function(a){for(var o in a)o in e||r.push(e[o]=o)}),r}function U(t,e){var r=t+"",a=r.length;return a<e?new Array(e-a+1).join(0)+r:r}function it(t){return t<0?"-"+U(-t,6):t>9999?"+"+U(t,6):U(t,4)}function ht(t){var e=t.getUTCHours(),r=t.getUTCMinutes(),a=t.getUTCSeconds(),o=t.getUTCMilliseconds();return isNaN(t)?"Invalid Date":it(t.getUTCFullYear(),4)+"-"+U(t.getUTCMonth()+1,2)+"-"+U(t.getUTCDate(),2)+(o?"T"+U(e,2)+":"+U(r,2)+":"+U(a,2)+"."+U(o,3)+"Z":a?"T"+U(e,2)+":"+U(r,2)+":"+U(a,2)+"Z":r||e?"T"+U(e,2)+":"+U(r,2)+"Z":"")}function Pe(t){var e=new RegExp('["'+t+`
|
|
17
|
+
\r]`),r=t.charCodeAt(0);function a(s,i){var v,j,A=o(s,function(f,w){if(v)return v(f,w-1);j=f,v=i?ot(f,i):Le(f)});return A.columns=j||[],A}function o(s,i){var v=[],j=s.length,A=0,f=0,w,T=j<=0,b=!1;s.charCodeAt(j-1)===ee&&--j,s.charCodeAt(j-1)===be&&--j;function D(){if(T)return we;if(b)return b=!1,Ie;var B,x=A,h;if(s.charCodeAt(x)===ge){for(;A++<j&&s.charCodeAt(A)!==ge||s.charCodeAt(++A)===ge;);return(B=A)>=j?T=!0:(h=s.charCodeAt(A++))===ee?b=!0:h===be&&(b=!0,s.charCodeAt(A)===ee&&++A),s.slice(x+1,B-1).replace(/""/g,'"')}for(;A<j;){if((h=s.charCodeAt(B=A++))===ee)b=!0;else if(h===be)b=!0,s.charCodeAt(A)===ee&&++A;else if(h!==r)continue;return s.slice(x,B)}return T=!0,s.slice(x,j)}for(;(w=D())!==we;){for(var C=[];w!==Ie&&w!==we;)C.push(w),w=D();i&&(C=i(C,f++))==null||v.push(C)}return v}function c(s,i){return s.map(function(v){return i.map(function(j){return y(v[j])}).join(t)})}function l(s,i){return i==null&&(i=Me(s)),[i.map(y).join(t)].concat(c(s,i)).join(`
|
|
18
|
+
`)}function d(s,i){return i==null&&(i=Me(s)),c(s,i).join(`
|
|
19
|
+
`)}function u(s){return s.map(n).join(`
|
|
20
|
+
`)}function n(s){return s.map(y).join(t)}function y(s){return s==null?"":s instanceof Date?ht(s):e.test(s+="")?'"'+s.replace(/"/g,'""')+'"':s}return{parse:a,parseRows:o,format:l,formatBody:d,formatRows:u,formatRow:n,formatValue:y}}var P=Pe(","),lt=P.parse,ct=P.parseRows,ut=P.format,ft=P.formatBody,ve=P.formatRows,dt=P.formatRow,mt=P.formatValue;function Te(t,e={csv:{useDisplayNames:!0}}){let r=e.useDisplayNames||e.csv?.useDisplayNames,c=[(t.schema?.fields||[]).map(l=>{let d=l.metadata?.displayName;return r&&typeof d=="string"?d:l.name})];for(let l of de(t)){let d=[];for(let u=0;u<fe(t);++u){let n=l[u];d[u]=pt(n)}c.push(d)}return ve(c)}var pt=t=>t==null?null:t instanceof Date?t.toISOString():typeof t=="object"?JSON.stringify(t):String(t);var qe={id:"csv",version:"latest",module:"csv",name:"CSV",extensions:["csv"],mimeTypes:["text/csv"],options:{csv:{useDisplayNames:!1}},text:!0,encode:async(t,e)=>new TextEncoder().encode(Te(t,e)).buffer,encodeTextSync:(t,e)=>Te(t,e)};return Ye(te);})();
|
|
21
|
+
/* @license
|
|
22
|
+
Papa Parse
|
|
23
|
+
v5.0.0-beta.0
|
|
24
|
+
https://github.com/mholt/PapaParse
|
|
25
|
+
License: MIT
|
|
26
|
+
*/
|
|
27
|
+
return __exports__;
|
|
28
|
+
});
|