@loaders.gl/csv 3.1.0-alpha.5 → 3.1.0-beta.4

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 (41) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +1503 -0
  4. package/dist/csv-loader.d.ts +34 -0
  5. package/dist/csv-loader.d.ts.map +1 -0
  6. package/dist/csv-loader.js +267 -0
  7. package/dist/csv-writer.d.ts +1 -0
  8. package/dist/csv-writer.d.ts.map +1 -0
  9. package/dist/csv-writer.js +6 -0
  10. package/dist/es5/csv-loader.js +3 -3
  11. package/dist/es5/csv-loader.js.map +1 -1
  12. package/dist/es5/papaparse/async-iterator-streamer.js +1 -1
  13. package/dist/es5/papaparse/async-iterator-streamer.js.map +1 -1
  14. package/dist/{esm/libs → es5/papaparse}/papaparse.js +170 -404
  15. package/dist/es5/papaparse/papaparse.js.map +1 -0
  16. package/dist/esm/csv-loader.js +3 -3
  17. package/dist/esm/csv-loader.js.map +1 -1
  18. package/dist/esm/papaparse/async-iterator-streamer.js +1 -1
  19. package/dist/esm/papaparse/async-iterator-streamer.js.map +1 -1
  20. package/{src/libs → dist/esm/papaparse}/papaparse.js +162 -404
  21. package/dist/esm/papaparse/papaparse.js.map +1 -0
  22. package/dist/index.d.ts +3 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +5 -0
  25. package/dist/papaparse/async-iterator-streamer.d.ts +6 -0
  26. package/dist/papaparse/async-iterator-streamer.d.ts.map +1 -0
  27. package/dist/papaparse/async-iterator-streamer.js +63 -0
  28. package/dist/papaparse/papaparse.d.ts +30 -0
  29. package/dist/papaparse/papaparse.d.ts.map +1 -0
  30. package/dist/papaparse/papaparse.js +935 -0
  31. package/package.json +6 -6
  32. package/src/csv-loader.ts +2 -2
  33. package/src/{lib → papaparse}/async-iterator-streamer.ts +2 -2
  34. package/{dist/es5/libs/papaparse.js → src/papaparse/papaparse.ts} +48 -73
  35. package/dist/dist.min.js +0 -9
  36. package/dist/dist.min.js.map +0 -1
  37. package/dist/es5/lib/async-iterator-streamer.js +0 -47
  38. package/dist/es5/lib/async-iterator-streamer.js.map +0 -1
  39. package/dist/esm/lib/async-iterator-streamer.js +0 -35
  40. package/dist/esm/lib/async-iterator-streamer.js.map +0 -1
  41. package/src/papaparse/async-iterator-streamer.js +0 -71
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/csv",
3
- "version": "3.1.0-alpha.5",
3
+ "version": "3.1.0-beta.4",
4
4
  "description": "Framework-independent loader for CSV and DSV table formats",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -16,7 +16,7 @@
16
16
  "table",
17
17
  "CSV"
18
18
  ],
19
- "types": "src/index.ts",
19
+ "types": "dist/index.d.ts",
20
20
  "main": "dist/es5/index.js",
21
21
  "module": "dist/esm/index.js",
22
22
  "sideEffects": false,
@@ -27,14 +27,14 @@
27
27
  ],
28
28
  "scripts": {
29
29
  "pre-build": "npm run build-bundle",
30
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js"
30
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js"
31
31
  },
32
32
  "dependencies": {
33
- "@loaders.gl/loader-utils": "3.1.0-alpha.5",
34
- "@loaders.gl/schema": "3.1.0-alpha.5"
33
+ "@loaders.gl/loader-utils": "3.1.0-beta.4",
34
+ "@loaders.gl/schema": "3.1.0-beta.4"
35
35
  },
36
36
  "devDependencies": {
37
37
  "d3-dsv": "^1.2.0"
38
38
  },
39
- "gitHead": "352241dd910a8c6307a235dadbe154ca915b885b"
39
+ "gitHead": "5c7c74215416b30fcea98f5cecc820c8a21023b3"
40
40
  }
package/src/csv-loader.ts CHANGED
@@ -8,8 +8,8 @@ import {
8
8
  convertToArrayRow,
9
9
  convertToObjectRow
10
10
  } from '@loaders.gl/schema';
11
- import Papa from './libs/papaparse';
12
- import AsyncIteratorStreamer from './lib/async-iterator-streamer';
11
+ import Papa from './papaparse/papaparse';
12
+ import AsyncIteratorStreamer from './papaparse/async-iterator-streamer';
13
13
 
14
14
  // __VERSION__ is injected by babel-plugin-version-inline
15
15
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
@@ -1,12 +1,12 @@
1
+ // @ts-nocheck
1
2
  // A custom papaparse `Streamer` for async iterators
2
3
  // Ideally this can be contributed back to papaparse
3
4
  // Or papaparse can expose Streamer API so we can extend without forking.
4
5
 
5
- // @ts-nocheck
6
6
  /* eslint-disable no-invalid-this */
7
7
 
8
8
  // Note: papaparse is not an ES6 module
9
- import Papa from '../libs/papaparse';
9
+ import Papa from './papaparse';
10
10
  const {ChunkStreamer} = Papa;
11
11
 
12
12
  export default function AsyncIteratorStreamer(config) {
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  // This is a fork of papaparse
2
3
  // https://github.com/mholt/PapaParse
3
4
  /* @license
@@ -14,52 +15,34 @@ License: MIT
14
15
  // - Remove unused jQuery plugin support
15
16
 
16
17
  /* eslint-disable */
17
- // @ts-nocheck
18
- var global = (function() {
19
- // alternative method, similar to `Function('return this')()`
20
- // but without using `eval` (which is disabled when
21
- // using Content Security Policy).
22
-
23
- if (typeof self !== 'undefined') {
24
- return self;
25
- }
26
- if (typeof window !== 'undefined') {
27
- return window;
28
- }
29
- if (typeof global !== 'undefined') {
30
- return global;
31
- }
18
+ const BYTE_ORDER_MARK = '\ufeff';
32
19
 
33
- // When running tests none of the above have been defined
34
- return {};
35
- })();
20
+ const Papa = {
21
+ parse: CsvToJson,
22
+ unparse: JsonToCsv,
36
23
 
37
- var IS_PAPA_WORKER = false;
24
+ RECORD_SEP: String.fromCharCode(30),
25
+ UNIT_SEP: String.fromCharCode(31),
26
+ BYTE_ORDER_MARK,
27
+ BAD_DELIMITERS: ['\r', '\n', '"', BYTE_ORDER_MARK],
28
+ WORKERS_SUPPORTED: false, // !IS_WORKER && !!globalThis.Worker
29
+ NODE_STREAM_INPUT: 1,
38
30
 
39
- var Papa = {};
40
- module.exports = Papa;
41
- Papa.parse = CsvToJson;
42
- Papa.unparse = JsonToCsv;
31
+ // Configurable chunk sizes for local and remote files, respectively
32
+ LocalChunkSize: 1024 * 1024 * 10, // 10 M,
33
+ RemoteChunkSize: 1024 * 1024 * 5, // 5 M,
34
+ DefaultDelimiter: ',', // Used if not specified and detection fail,
43
35
 
44
- Papa.RECORD_SEP = String.fromCharCode(30);
45
- Papa.UNIT_SEP = String.fromCharCode(31);
46
- Papa.BYTE_ORDER_MARK = '\ufeff';
47
- Papa.BAD_DELIMITERS = ['\r', '\n', '"', Papa.BYTE_ORDER_MARK];
48
- Papa.WORKERS_SUPPORTED = false; // !IS_WORKER && !!global.Worker;
49
- Papa.NODE_STREAM_INPUT = 1;
36
+ // Exposed for testing and development only
37
+ Parser: Parser,
38
+ ParserHandle: ParserHandle,
50
39
 
51
- // Configurable chunk sizes for local and remote files, respectively
52
- Papa.LocalChunkSize = 1024 * 1024 * 10; // 10 MB
53
- Papa.RemoteChunkSize = 1024 * 1024 * 5; // 5 MB
54
- Papa.DefaultDelimiter = ','; // Used if not specified and detection fails
55
-
56
- // Exposed for testing and development only
57
- Papa.Parser = Parser;
58
- Papa.ParserHandle = ParserHandle;
40
+ // BEGIN FORK
41
+ ChunkStreamer: ChunkStreamer,
42
+ StringStreamer: StringStreamer
43
+ };
44
+ export default Papa;
59
45
 
60
- // BEGIN FORK
61
- Papa.ChunkStreamer = ChunkStreamer;
62
- Papa.StringStreamer = StringStreamer;
63
46
  /*
64
47
  Papa.NetworkStreamer = NetworkStreamer;
65
48
  Papa.FileStreamer = FileStreamer;
@@ -76,7 +59,7 @@ if (typeof PAPA_BROWSER_CONTEXT === 'undefined') {
76
59
  function CsvToJson(
77
60
  _input,
78
61
  _config,
79
- UserDefinedStreamer // BEGIN FORK
62
+ UserDefinedStreamer? // BEGIN FORK
80
63
  ) {
81
64
  _config = _config || {};
82
65
  var dynamicTyping = _config.dynamicTyping || false;
@@ -129,7 +112,7 @@ function CsvToJson(
129
112
  /*
130
113
  else if (_input.readable === true && isFunction(_input.read) && isFunction(_input.on)) {
131
114
  streamer = new ReadableStreamStreamer(_config);
132
- } else if ((global.File && _input instanceof File) || _input instanceof Object)
115
+ } else if ((globalThis.File && _input instanceof File) || _input instanceof Object)
133
116
  // ...Safari. (see issue #106)
134
117
  streamer = new FileStreamer(_config);
135
118
  */
@@ -204,7 +187,7 @@ function JsonToCsv(_input, _config) {
204
187
 
205
188
  if (
206
189
  typeof _config.delimiter === 'string' &&
207
- !Papa.BAD_DELIMITERS.filter(function(value) {
190
+ !Papa.BAD_DELIMITERS.filter(function (value) {
208
191
  return _config.delimiter.indexOf(value) !== -1;
209
192
  }).length
210
193
  ) {
@@ -339,7 +322,7 @@ function ChunkStreamer(config) {
339
322
  };
340
323
  replaceConfig.call(this, config);
341
324
 
342
- this.parseChunk = function(chunk, isFakeChunk) {
325
+ this.parseChunk = function (chunk, isFakeChunk) {
343
326
  // First chunk pre-processing
344
327
  if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk)) {
345
328
  var modifiedChunk = this._config.beforeFirstChunk(chunk);
@@ -367,13 +350,7 @@ function ChunkStreamer(config) {
367
350
  var finishedIncludingPreview =
368
351
  this._finished || (this._config.preview && this._rowCount >= this._config.preview);
369
352
 
370
- if (IS_PAPA_WORKER) {
371
- global.postMessage({
372
- results: results,
373
- workerId: Papa.WORKER_ID,
374
- finished: finishedIncludingPreview
375
- });
376
- } else if (isFunction(this._config.chunk) && !isFakeChunk) {
353
+ if (isFunction(this._config.chunk) && !isFakeChunk) {
377
354
  this._config.chunk(results, this._handle);
378
355
  if (this._handle.paused() || this._handle.aborted()) return;
379
356
  results = undefined;
@@ -401,15 +378,8 @@ function ChunkStreamer(config) {
401
378
  return results;
402
379
  };
403
380
 
404
- this._sendError = function(error) {
381
+ this._sendError = function (error) {
405
382
  if (isFunction(this._config.error)) this._config.error(error);
406
- else if (IS_PAPA_WORKER && this._config.error) {
407
- global.postMessage({
408
- workerId: Papa.WORKER_ID,
409
- error: error,
410
- finished: false
411
- });
412
- }
413
383
  };
414
384
 
415
385
  function replaceConfig(config) {
@@ -427,11 +397,11 @@ function StringStreamer(config) {
427
397
  ChunkStreamer.call(this, config);
428
398
 
429
399
  var remaining;
430
- this.stream = function(s) {
400
+ this.stream = function (s) {
431
401
  remaining = s;
432
402
  return this._nextChunk();
433
403
  };
434
- this._nextChunk = function() {
404
+ this._nextChunk = function () {
435
405
  if (this._finished) return;
436
406
  var size = this._config.chunkSize;
437
407
  var chunk = size ? remaining.substr(0, size) : remaining;
@@ -447,7 +417,8 @@ StringStreamer.prototype.constructor = StringStreamer;
447
417
  function ParserHandle(_config) {
448
418
  // One goal is to minimize the use of regular expressions...
449
419
  var FLOAT = /^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i;
450
- var ISO_DATE = /(\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))/;
420
+ var ISO_DATE =
421
+ /(\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))/;
451
422
 
452
423
  var self = this;
453
424
  var _stepCounter = 0; // Number of times step was called (number of rows parsed)
@@ -467,7 +438,7 @@ function ParserHandle(_config) {
467
438
 
468
439
  if (isFunction(_config.step)) {
469
440
  var userStep = _config.step;
470
- _config.step = function(results) {
441
+ _config.step = function (results) {
471
442
  _results = results;
472
443
 
473
444
  if (needsHeaderRow()) processResults();
@@ -490,7 +461,7 @@ function ParserHandle(_config) {
490
461
  * and ignoreLastRow parameters. They are used by streamers (wrapper functions)
491
462
  * when an input comes in multiple chunks, like from a file.
492
463
  */
493
- this.parse = function(input, baseIndex, ignoreLastRow) {
464
+ this.parse = function (input, baseIndex, ignoreLastRow) {
494
465
  var quoteChar = _config.quoteChar || '"';
495
466
  if (!_config.newline) _config.newline = guessLineEndings(input, quoteChar);
496
467
 
@@ -524,26 +495,26 @@ function ParserHandle(_config) {
524
495
  return _paused ? {meta: {paused: true}} : _results || {meta: {paused: false}};
525
496
  };
526
497
 
527
- this.paused = function() {
498
+ this.paused = function () {
528
499
  return _paused;
529
500
  };
530
501
 
531
- this.pause = function() {
502
+ this.pause = function () {
532
503
  _paused = true;
533
504
  _parser.abort();
534
505
  _input = _input.substr(_parser.getCharIndex());
535
506
  };
536
507
 
537
- this.resume = function() {
508
+ this.resume = function () {
538
509
  _paused = false;
539
510
  self.streamer.parseChunk(_input, true);
540
511
  };
541
512
 
542
- this.aborted = function() {
513
+ this.aborted = function () {
543
514
  return _aborted;
544
515
  };
545
516
 
546
- this.abort = function() {
517
+ this.abort = function () {
547
518
  _aborted = true;
548
519
  _parser.abort();
549
520
  _results.meta.aborted = true;
@@ -620,7 +591,11 @@ function ParserHandle(_config) {
620
591
  }
621
592
 
622
593
  function applyHeaderAndDynamicTypingAndTransformation() {
623
- if (!_results || !_results.data || (!_config.header && !_config.dynamicTyping && !_config.transform))
594
+ if (
595
+ !_results ||
596
+ !_results.data ||
597
+ (!_config.header && !_config.dynamicTyping && !_config.transform)
598
+ )
624
599
  return _results;
625
600
 
626
601
  function processRow(rowSource, i) {
@@ -802,7 +777,7 @@ function Parser(config) {
802
777
  var cursor = 0;
803
778
  var aborted = false;
804
779
 
805
- this.parse = function(input, baseIndex, ignoreLastRow) {
780
+ this.parse = function (input, baseIndex, ignoreLastRow) {
806
781
  // For some reason, in Chrome, this speeds things up (!?)
807
782
  if (typeof input !== 'string') throw new Error('Input must be a string');
808
783
 
@@ -1075,12 +1050,12 @@ function Parser(config) {
1075
1050
  };
1076
1051
 
1077
1052
  /** Sets the abort flag */
1078
- this.abort = function() {
1053
+ this.abort = function () {
1079
1054
  aborted = true;
1080
1055
  };
1081
1056
 
1082
1057
  /** Gets the cursor position */
1083
- this.getCharIndex = function() {
1058
+ this.getCharIndex = function () {
1084
1059
  return cursor;
1085
1060
  };
1086
1061
  }
package/dist/dist.min.js DELETED
@@ -1,9 +0,0 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(window,(function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(i,s,function(t){return e[t]}.bind(null,s));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t){
2
- /* @license
3
- Papa Parse
4
- v5.0.0-beta.0
5
- https://github.com/mholt/PapaParse
6
- License: MIT
7
- */
8
- var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==r?r:{},i={};function s(e){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:{}},function(e){var t=l(e);t.chunkSize=parseInt(t.chunkSize),e.step||e.chunk||(t.chunkSize=null);this._handle=new a(t),this._handle.streamer=this,this._config=t}.call(this,e),this.parseChunk=function(e,t){if(this.isFirstChunk&&u(this._config.beforeFirstChunk)){var r=this._config.beforeFirstChunk(e);void 0!==r&&(e=r)}this.isFirstChunk=!1;var i=this._partialLine+e;this._partialLine="";var s=this._handle.parse(i,this._baseIndex,!this._finished);if(!this._handle.paused()&&!this._handle.aborted()){var n=s.meta.cursor;this._finished||(this._partialLine=i.substring(n-this._baseIndex),this._baseIndex=n),s&&s.data&&(this._rowCount+=s.data.length);var a=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(u(this._config.chunk)&&!t){if(this._config.chunk(s,this._handle),this._handle.paused()||this._handle.aborted())return;s=void 0,this._completeResults=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(s.data),this._completeResults.errors=this._completeResults.errors.concat(s.errors),this._completeResults.meta=s.meta),this._completed||!a||!u(this._config.complete)||s&&s.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),a||s&&s.meta.paused||this._nextChunk(),s}},this._sendError=function(e){u(this._config.error)&&this._config.error(e)}}function n(e){var t;e=e||{},s.call(this,e),this.stream=function(e){return t=e,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var e=this._config.chunkSize,r=e?t.substr(0,e):t;return t=e?t.substr(e):"",this._finished=!t,this.parseChunk(r)}}}function a(e){var t,r,s,n=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,a=/(\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))/,c=this,d=0,f=0,p=!1,g=!1,m=[],y={data:[],errors:[],meta:{}};if(u(e.step)){var b=e.step;e.step=function(t){if(y=t,_())v();else{if(v(),!y.data||0===y.data.length)return;d+=t.data.length,e.preview&&d>e.preview?r.abort():b(y,c)}}}function w(t){return"greedy"===e.skipEmptyLines?""===t.join("").trim():1===t.length&&0===t[0].length}function v(){if(y&&s&&(C("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+i.DefaultDelimiter+"'"),s=!1),e.skipEmptyLines)for(var t=0;t<y.data.length;t++)w(y.data[t])&&y.data.splice(t--,1);return _()&&function(){if(!y)return;function t(t){u(e.transformHeader)&&(t=e.transformHeader(t)),m.push(t)}if(Array.isArray(y.data[0])){for(var r=0;_()&&r<y.data.length;r++)y.data[r].forEach(t);y.data.splice(0,1)}else y.data.forEach(t)}(),function(){if(!y||!y.data||!e.header&&!e.dynamicTyping&&!e.transform)return y;function t(t,r){var i,s=e.header?{}:[];for(i=0;i<t.length;i++){var n=i,a=t[i];e.header&&(n=i>=m.length?"__parsed_extra":m[i]),e.transform&&(a=e.transform(a,n)),a=A(n,a),"__parsed_extra"===n?(s[n]=s[n]||[],s[n].push(a)):s[n]=a}return e.header&&(i>m.length?C("FieldMismatch","TooManyFields","Too many fields: expected "+m.length+" fields but parsed "+i,f+r):i<m.length&&C("FieldMismatch","TooFewFields","Too few fields: expected "+m.length+" fields but parsed "+i,f+r)),s}var r=1;!y.data[0]||Array.isArray(y.data[0])?(y.data=y.data.map(t),r=y.data.length):y.data=t(y.data,0);e.header&&y.meta&&(y.meta.fields=m);return f+=r,y}()}function _(){return e.header&&0===m.length}function A(t,r){return function(t){return e.dynamicTypingFunction&&void 0===e.dynamicTyping[t]&&(e.dynamicTyping[t]=e.dynamicTypingFunction(t)),!0===(e.dynamicTyping[t]||e.dynamicTyping)}(t)?"true"===r||"TRUE"===r||"false"!==r&&"FALSE"!==r&&(n.test(r)?parseFloat(r):a.test(r)?new Date(r):""===r?null:r):r}function C(e,t,r,i){y.errors.push({type:e,code:t,message:r,row:i})}this.parse=function(n,a,c){var d=e.quoteChar||'"';if(e.newline||(e.newline=function(e,t){e=e.substr(0,1048576);var r=new RegExp(o(t)+"([^]*?)"+o(t),"gm"),i=(e=e.replace(r,"")).split("\r"),s=e.split("\n"),n=s.length>1&&s[0].length<i[0].length;if(1===i.length||n)return"\n";for(var a=0,h=0;h<i.length;h++)"\n"===i[h][0]&&a++;return a>=i.length/2?"\r\n":"\r"}(n,d)),s=!1,e.delimiter)u(e.delimiter)&&(e.delimiter=e.delimiter(n),y.meta.delimiter=e.delimiter);else{var f=function(t,r,s,n,a){var o,l,u;a=a||[",","\t","|",";",i.RECORD_SEP,i.UNIT_SEP];for(var c=0;c<a.length;c++){var d=a[c],f=0,p=0,g=0;u=void 0;for(var m=new h({comments:n,delimiter:d,newline:r,preview:10}).parse(t),y=0;y<m.data.length;y++)if(s&&w(m.data[y]))g++;else{var b=m.data[y].length;p+=b,void 0!==u?b>1&&(f+=Math.abs(b-u),u=b):u=0}m.data.length>0&&(p/=m.data.length-g),(void 0===l||f>l)&&p>1.99&&(l=f,o=d)}return e.delimiter=o,{successful:!!o,bestDelimiter:o}}(n,e.newline,e.skipEmptyLines,e.comments,e.delimitersToGuess);f.successful?e.delimiter=f.bestDelimiter:(s=!0,e.delimiter=i.DefaultDelimiter),y.meta.delimiter=e.delimiter}var g=l(e);return e.preview&&e.header&&g.preview++,t=n,r=new h(g),y=r.parse(t,a,c),v(),p?{meta:{paused:!0}}:y||{meta:{paused:!1}}},this.paused=function(){return p},this.pause=function(){p=!0,r.abort(),t=t.substr(r.getCharIndex())},this.resume=function(){p=!1,c.streamer.parseChunk(t,!0)},this.aborted=function(){return g},this.abort=function(){g=!0,r.abort(),y.meta.aborted=!0,u(e.complete)&&e.complete(y),t=""}}function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function h(e){var t,r=(e=e||{}).delimiter,s=e.newline,n=e.comments,a=e.step,h=e.preview,l=e.fastMode,c=t=void 0===e.quoteChar?'"':e.quoteChar;if(void 0!==e.escapeChar&&(c=e.escapeChar),("string"!=typeof r||i.BAD_DELIMITERS.indexOf(r)>-1)&&(r=","),n===r)throw new Error("Comment character same as delimiter");!0===n?n="#":("string"!=typeof n||i.BAD_DELIMITERS.indexOf(n)>-1)&&(n=!1),"\n"!==s&&"\r"!==s&&"\r\n"!==s&&(s="\n");var d=0,f=!1;this.parse=function(e,i,p){if("string"!=typeof e)throw new Error("Input must be a string");var g=e.length,m=r.length,y=s.length,b=n.length,w=u(a);d=0;var v=[],_=[],A=[],C=0;if(!e)return F();if(l||!1!==l&&-1===e.indexOf(t)){for(var x=e.split(s),R=0;R<x.length;R++){if(A=x[R],d+=A.length,R!==x.length-1)d+=s.length;else if(p)return F();if(!n||A.substr(0,b)!==n){if(w){if(v=[],B(A.split(r)),I(),f)return F()}else B(A.split(r));if(h&&R>=h)return v=v.slice(0,h),F(!0)}}return F()}for(var E,k=e.indexOf(r,d),O=e.indexOf(s,d),T=new RegExp(o(c)+o(t),"g");;)if(e[d]!==t)if(n&&0===A.length&&e.substr(d,b)===n){if(-1===O)return F();d=O+y,O=e.indexOf(s,d),k=e.indexOf(r,d)}else if(-1!==k&&(k<O||-1===O))A.push(e.substring(d,k)),d=k+m,k=e.indexOf(r,d);else{if(-1===O)break;if(A.push(e.substring(d,O)),P(O+y),w&&(I(),f))return F();if(h&&v.length>=h)return F(!0)}else{for(E=d,d++;;){if(-1===(E=e.indexOf(t,E+1)))return p||_.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:v.length,index:d}),M();if(E===g-1)return M(e.substring(d,E).replace(T,t));if(t!==c||e[E+1]!==c){if(t===c||0===E||e[E-1]!==c){var S=D(-1===O?k:Math.min(k,O));if(e[E+1+S]===r){if(A.push(e.substring(d,E).replace(T,t)),d=E+1+S+m,k=e.indexOf(r,d),O=e.indexOf(s,d),w&&(I(),f))return F();if(h&&v.length>=h)return F(!0);break}var j=D(O);if(e.substr(E+1+j,y)===s){if(A.push(e.substring(d,E).replace(T,t)),P(E+1+j+y),k=e.indexOf(r,d),w&&(I(),f))return F();if(h&&v.length>=h)return F(!0);break}_.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:v.length,index:d}),E++}}else E++}if(w&&(I(),f))return F();if(h&&v.length>=h)return F(!0)}return M();function B(e){v.push(e),C=d}function D(t){var r=0;if(-1!==t){var i=e.substring(E+1,t);i&&""===i.trim()&&(r=i.length)}return r}function M(t){return p||(void 0===t&&(t=e.substr(d)),A.push(t),d=g,B(A),w&&I()),F()}function P(t){d=t,B(A),A=[],O=e.indexOf(s,d)}function F(e,t){return{data:t||!1?v[0]:v,errors:_,meta:{delimiter:r,linebreak:s,aborted:f,truncated:!!e,cursor:C+(i||0)}}}function I(){a(F(void 0,!0)),v=[],_=[]}},this.abort=function(){f=!0},this.getCharIndex=function(){return d}}function l(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var r in e)t[r]=l(e[r]);return t}function u(e){return"function"==typeof e}e.exports=i,i.parse=function(e,t,r){var s=(t=t||{}).dynamicTyping||!1;u(s)&&(t.dynamicTypingFunction=s,s={});if(t.dynamicTyping=s,t.transform=!!u(t.transform)&&t.transform,t.worker&&i.WORKERS_SUPPORTED){var a=newWorker();return a.userStep=t.step,a.userChunk=t.chunk,a.userComplete=t.complete,a.userError=t.error,t.step=u(t.step),t.chunk=u(t.chunk),t.complete=u(t.complete),t.error=u(t.error),delete t.worker,void a.postMessage({input:e,config:t,workerId:a.id})}var o=null;"string"==typeof e&&(o=new n(t));o||(o=new r(t));return o.stream(e)},i.unparse=function(e,t){var r=!1,s=!0,n=",",a="\r\n",h='"',l=h+h,u=!1,c=null;!function(){if("object"!=typeof t)return;"string"!=typeof t.delimiter||i.BAD_DELIMITERS.filter((function(e){return-1!==t.delimiter.indexOf(e)})).length||(n=t.delimiter);("boolean"==typeof t.quotes||Array.isArray(t.quotes))&&(r=t.quotes);"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(u=t.skipEmptyLines);"string"==typeof t.newline&&(a=t.newline);"string"==typeof t.quoteChar&&(h=t.quoteChar);"boolean"==typeof t.header&&(s=t.header);if(Array.isArray(t.columns)){if(0===t.columns.length)throw new Error("Option columns is empty");c=t.columns}void 0!==t.escapeChar&&(l=t.escapeChar+h)}();var d=new RegExp(o(h),"g");"string"==typeof e&&(e=JSON.parse(e));if(Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return p(null,e,u);if("object"==typeof e[0])return p(c||f(e[0]),e,u)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:f(e.data[0])),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),p(e.fields||[],e.data||[],u);throw new Error("Unable to serialize unrecognized input");function f(e){if("object"!=typeof e)return[];var t=[];for(var r in e)t.push(r);return t}function p(e,t,r){var i="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var o=Array.isArray(e)&&e.length>0,h=!Array.isArray(t[0]);if(o&&s){for(var l=0;l<e.length;l++)l>0&&(i+=n),i+=g(e[l],l);t.length>0&&(i+=a)}for(var u=0;u<t.length;u++){var c=o?e.length:t[u].length,d=!1,f=o?0===Object.keys(t[u]).length:0===t[u].length;if(r&&!o&&(d="greedy"===r?""===t[u].join("").trim():1===t[u].length&&0===t[u][0].length),"greedy"===r&&o){for(var p=[],m=0;m<c;m++){var y=h?e[m]:m;p.push(t[u][y])}d=""===p.join("").trim()}if(!d){for(var b=0;b<c;b++){b>0&&!f&&(i+=n);var w=o&&h?e[b]:b;i+=g(t[u][w],b)}u<t.length-1&&(!r||c>0&&!f)&&(i+=a)}}return i}function g(e,t){return null==e?"":e.constructor===Date?JSON.stringify(e).slice(1,25):(e=e.toString().replace(d,l),"boolean"==typeof r&&r||Array.isArray(r)&&r[t]||function(e,t){for(var r=0;r<t.length;r++)if(e.indexOf(t[r])>-1)return!0;return!1}(e,i.BAD_DELIMITERS)||e.indexOf(n)>-1||" "===e.charAt(0)||" "===e.charAt(e.length-1)?h+e+h:e)}},i.RECORD_SEP=String.fromCharCode(30),i.UNIT_SEP=String.fromCharCode(31),i.BYTE_ORDER_MARK="\ufeff",i.BAD_DELIMITERS=["\r","\n",'"',i.BYTE_ORDER_MARK],i.WORKERS_SUPPORTED=!1,i.NODE_STREAM_INPUT=1,i.LocalChunkSize=10485760,i.RemoteChunkSize=5242880,i.DefaultDelimiter=",",i.Parser=h,i.ParserHandle=a,i.ChunkStreamer=s,i.StringStreamer=n,n.prototype=Object.create(n.prototype),n.prototype.constructor=n},function(e,t,r){const i=r(2);globalThis.loaders=globalThis.loaders||{},e.exports=Object.assign(globalThis.loaders,i)},function(e,t,r){"use strict";function i(e,t){if(!e)throw new Error("null row");if(!t)throw new Error("no headers");const r={};for(let i=0;i<t.length;i++)r[t[i]]=e[i];return r}function s(e,t){if(!e)throw new Error("null row");if(!t)throw new Error("no headers");const r=new Array(t.length);for(let i=0;i<t.length;i++)r[i]=e[t[i]];return r}let n;function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.r(t),r.d(t,"CSVLoader",(function(){return C}));class o extends Array{enqueue(e){return this.push(e)}dequeue(){return this.shift()}}n=Symbol.asyncIterator;class h{constructor(){a(this,"_values",void 0),a(this,"_settlers",void 0),a(this,"_closed",void 0),this._values=new o,this._settlers=new o,this._closed=!1}close(){for(;this._settlers.length>0;)this._settlers.dequeue().resolve({done:!0});this._closed=!0}[n](){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");const t=this._settlers.dequeue();e instanceof Error?t.reject(e):t.resolve({value:e})}else this._values.enqueue(e)}next(){if(this._values.length>0){const 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,t)=>{this._settlers.enqueue({resolve:e,reject:t})})}}function l(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class u{constructor(e,t){if(l(this,"schema",void 0),l(this,"options",void 0),l(this,"length",0),l(this,"rows",null),l(this,"cursor",0),l(this,"_headers",[]),this.options=t,this.schema=e,!Array.isArray(e)){this._headers=[];for(const t in e)this._headers[e[t].index]=e[t].name}}rowCount(){return this.length}addArrayRow(e,t){Number.isFinite(t)&&(this.cursor=t),this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}addObjectRow(e,t){Number.isFinite(t)&&(this.cursor=t),this.rows=this.rows||new Array(100),this.rows[this.length]=e,this.length++}getBatch(){let e=this.rows;if(!e)return null;e=e.slice(0,this.length),this.rows=null;return{shape:this.options.shape,batchType:"data",data:e,length:this.length,schema:this.schema,cursor:this.cursor}}}function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class d{constructor(e,t){if(c(this,"schema",void 0),c(this,"options",void 0),c(this,"length",0),c(this,"objectRows",null),c(this,"arrayRows",null),c(this,"cursor",0),c(this,"_headers",[]),this.options=t,this.schema=e,!Array.isArray(e)){this._headers=[];for(const t in e)this._headers[e[t].index]=e[t].name}}rowCount(){return this.length}addArrayRow(e,t){switch(Number.isFinite(t)&&(this.cursor=t),this.options.shape){case"object-row-table":const r=i(e,this._headers);this.addObjectRow(r,t);break;case"array-row-table":this.arrayRows=this.arrayRows||new Array(100),this.arrayRows[this.length]=e,this.length++}}addObjectRow(e,t){switch(Number.isFinite(t)&&(this.cursor=t),this.options.shape){case"array-row-table":const r=s(e,this._headers);this.addArrayRow(r,t);break;case"object-row-table":this.objectRows=this.objectRows||new Array(100),this.objectRows[this.length]=e,this.length++}}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}}function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class p{constructor(e,t){f(this,"schema",void 0),f(this,"length",0),f(this,"allocated",0),f(this,"columns",{}),this.schema=e,this._reallocateColumns()}rowCount(){return this.length}addArrayRow(e){this._reallocateColumns();let t=0;for(const r in this.columns)this.columns[r][this.length]=e[t++];this.length++}addObjectRow(e){this._reallocateColumns();for(const t in e)this.columns[t][this.length]=e[t];this.length++}getBatch(){this._pruneColumns();const e=Array.isArray(this.schema)?this.columns:{};if(!Array.isArray(this.schema))for(const t in this.schema){const r=this.schema[t];e[r.name]=this.columns[r.index]}this.columns={};return{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(const e in this.schema){const t=this.schema[e],r=t.type||Float32Array,i=this.columns[t.index];if(i&&ArrayBuffer.isView(i)){const e=new r(this.allocated);e.set(i),this.columns[t.index]=e}else i?(i.length=this.allocated,this.columns[t.index]=i):this.columns[t.index]=new r(this.allocated)}}}_pruneColumns(){for(const[e,t]of Object.entries(this.columns))this.columns[e]=t.slice(0,this.length)}}function g(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const m={shape:"array-row-table",batchSize:"auto",batchDebounceMs:0,limit:0,_limitMB:0};class y{constructor(e,t){g(this,"schema",void 0),g(this,"options",void 0),g(this,"aggregator",null),g(this,"batchCount",0),g(this,"bytesUsed",0),g(this,"isChunkComplete",!1),g(this,"lastBatchEmittedMs",Date.now()),g(this,"totalLength",0),g(this,"totalBytes",0),g(this,"rowBytes",0),this.schema=e,this.options={...m,...t}}limitReached(){var e,t;return!!(Boolean(null===(e=this.options)||void 0===e?void 0:e.limit)&&this.totalLength>=this.options.limit)||!!(Boolean(null===(t=this.options)||void 0===t?void 0:t._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){const e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addArrayRow(e)}addObjectRow(e){if(!this.aggregator){const e=this._getTableBatchType();this.aggregator=new e(this.schema,this.options)}this.aggregator.addObjectRow(e)}chunkComplete(e){e instanceof ArrayBuffer&&(this.bytesUsed+=e.byteLength),"string"==typeof e&&(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)?8*e.length:8*Object.keys(e).length}_isFull(){if(!this.aggregator||0===this.aggregator.rowCount())return!1;if("auto"===this.options.batchSize){if(!this.isChunkComplete)return!1}else if(this.options.batchSize>this.aggregator.rowCount())return!1;return!(this.options.batchDebounceMs>Date.now()-this.lastBatchEmittedMs)&&(this.isChunkComplete=!1,this.lastBatchEmittedMs=Date.now(),!0)}_getBatch(e){if(!this.aggregator)return null;null!=e&&e.bytesUsed&&(this.bytesUsed=e.bytesUsed);const t=this.aggregator.getBatch();return t.count=this.batchCount,t.bytesUsed=this.bytesUsed,Object.assign(t,e),this.batchCount++,this.aggregator=null,t}_getTableBatchType(){switch(this.options.shape){case"row-table":return u;case"array-row-table":case"object-row-table":return d;case"columnar-table":return p;case"arrow-table":if(!y.ArrowBatch)throw new Error("TableBatchBuilder");return y.ArrowBatch;default:throw new Error("TableBatchBuilder")}}}g(y,"ArrowBatch",void 0);var b=r(0),w=r.n(b);const{ChunkStreamer:v}=w.a;function _(e){e=e||{},v.call(this,e),this.textDecoder=new TextDecoder(this._config.encoding),this.stream=async function(e){this._input=e;try{for await(const t of e)this.parseChunk(this.getStringChunk(t));this._finished=!0,this.parseChunk("")}catch(e){this._sendError(e)}},this._nextChunk=function(){},this.getStringChunk=function(e){return"string"==typeof e?e:this.textDecoder.decode(e,{stream:!0})}}_.prototype=Object.create(v.prototype),_.prototype.constructor=_;const A={csv:{shape:"object-row-table",optimizeMemoryUsage:!1,header:"auto",columnPrefix:"column",quoteChar:'"',escapeChar:'"',dynamicTyping:!0,comments:!1,skipEmptyLines:!0,delimitersToGuess:[",","\t","|",";"]}},C={id:"csv",module:"csv",name:"CSV",version:"3.1.0-alpha.5",extensions:["csv","tsv","dsv"],mimeTypes:["text/csv","text/tab-separated-values","text/dsv"],category:"table",parse:async(e,t)=>x((new TextDecoder).decode(e),t),parseText:(e,t)=>x(e,t),parseInBatches:function(e,t){var r;"auto"===(t={...t}).batchSize&&(t.batchSize=4e3);const i={...A.csv,...null===(r=t)||void 0===r?void 0:r.csv},s=new h;let n=!0,a=null,o=null,l=null;const u={...i,header:!1,download:!1,chunkSize:5242880,skipEmptyLines:!1,step(e){let r=e.data;if(i.skipEmptyLines){if(""===r.flat().join("").trim())return}const h=e.meta.cursor;if(n&&!a){if("auto"===i.header?R(r):Boolean(i.header))return void(a=r.map(E()))}n&&(n=!1,a||(a=k(i.columnPrefix,r.length)),l=function(e,t){const r=t?{}:[];for(let i=0;i<e.length;i++){const s=t&&t[i]||i;switch(typeof e[i]){case"number":case"boolean":r[s]={name:String(s),index:i,type:Float32Array};break;case"string":default:r[s]={name:String(s),index:i,type:Array}}}return r}(r,a)),i.optimizeMemoryUsage&&(r=JSON.parse(JSON.stringify(r))),o=o||new y(l,{shape:i.shape||"array-row-table",...t});try{o.addRow(r);const e=o&&o.getFullBatch({bytesUsed:h});e&&s.enqueue(e)}catch(e){s.enqueue(e)}},complete(e){try{const t=e.meta.cursor,r=o&&o.getFinalBatch({bytesUsed:t});r&&s.enqueue(r)}catch(e){s.enqueue(e)}s.close()}};return w.a.parse(e,u,_),s},options:A};async function x(e,t){const r={...A.csv,...null==t?void 0:t.csv},n=function(e){return w.a.parse(e,{download:!1,dynamicTyping:!0,preview:1}).data[0]}(e),a="auto"===r.header?R(n):Boolean(r.header),o={...r,header:a,download:!1,transformHeader:a?E():void 0,error:e=>{throw new Error(e)}},h=w.a.parse(e,o);let{data:l}=h;const u=h.meta.fields||k(r.columnPrefix,n.length);switch(r.shape){case"object-row-table":l=l.map(e=>Array.isArray(e)?i(e,u):e);break;case"array-row-table":l=l.map(e=>Array.isArray(e)?e:s(e,u))}return l}function R(e){return e&&e.every(e=>"string"==typeof e)}function E(){const e=new Set;return t=>{let r=t,i=1;for(;e.has(r);)r=`${t}.${i}`,i++;return e.add(r),r}}function k(e,t=0){const r=[];for(let i=0;i<t;i++)r.push(`${e}${i+1}`);return r}}])}));
9
- //# sourceMappingURL=dist.min.js.map