@loaders.gl/csv 4.3.0-alpha.8 → 4.3.0-beta.2

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/dist.dev.js CHANGED
@@ -626,32 +626,7 @@ var __exports__ = (() => {
626
626
 
627
627
  // src/papaparse/papaparse.ts
628
628
  var BYTE_ORDER_MARK = "\uFEFF";
629
- var Papa = {
630
- parse: CsvToJson,
631
- unparse: JsonToCsv,
632
- RECORD_SEP: String.fromCharCode(30),
633
- UNIT_SEP: String.fromCharCode(31),
634
- BYTE_ORDER_MARK,
635
- BAD_DELIMITERS: ["\r", "\n", '"', BYTE_ORDER_MARK],
636
- WORKERS_SUPPORTED: false,
637
- // !IS_WORKER && !!globalThis.Worker
638
- NODE_STREAM_INPUT: 1,
639
- // Configurable chunk sizes for local and remote files, respectively
640
- LocalChunkSize: 1024 * 1024 * 10,
641
- // 10 M,
642
- RemoteChunkSize: 1024 * 1024 * 5,
643
- // 5 M,
644
- DefaultDelimiter: ",",
645
- // Used if not specified and detection fail,
646
- // Exposed for testing and development only
647
- Parser,
648
- ParserHandle,
649
- // BEGIN FORK
650
- ChunkStreamer,
651
- StringStreamer
652
- };
653
- var papaparse_default = Papa;
654
- function CsvToJson(_input, _config, UserDefinedStreamer) {
629
+ function CsvToJson(_input, _config = {}, Streamer = StringStreamer) {
655
630
  _config = _config || {};
656
631
  var dynamicTyping = _config.dynamicTyping || false;
657
632
  if (isFunction(dynamicTyping)) {
@@ -660,31 +635,7 @@ var __exports__ = (() => {
660
635
  }
661
636
  _config.dynamicTyping = dynamicTyping;
662
637
  _config.transform = isFunction(_config.transform) ? _config.transform : false;
663
- if (_config.worker && Papa.WORKERS_SUPPORTED) {
664
- var w = newWorker();
665
- w.userStep = _config.step;
666
- w.userChunk = _config.chunk;
667
- w.userComplete = _config.complete;
668
- w.userError = _config.error;
669
- _config.step = isFunction(_config.step);
670
- _config.chunk = isFunction(_config.chunk);
671
- _config.complete = isFunction(_config.complete);
672
- _config.error = isFunction(_config.error);
673
- delete _config.worker;
674
- w.postMessage({
675
- input: _input,
676
- config: _config,
677
- workerId: w.id
678
- });
679
- return;
680
- }
681
- var streamer = null;
682
- if (typeof _input === "string") {
683
- streamer = new StringStreamer(_config);
684
- }
685
- if (!streamer) {
686
- streamer = new UserDefinedStreamer(_config);
687
- }
638
+ var streamer = new Streamer(_config);
688
639
  return streamer.stream(_input);
689
640
  }
690
641
  function JsonToCsv(_input, _config) {
@@ -704,7 +655,7 @@ var __exports__ = (() => {
704
655
  if (!_input.length || Array.isArray(_input[0]))
705
656
  return serialize(null, _input, _skipEmptyLines);
706
657
  else if (typeof _input[0] === "object")
707
- return serialize(_columns || objectKeys(_input[0]), _input, _skipEmptyLines);
658
+ return serialize(_columns || Object.keys(_input[0]), _input, _skipEmptyLines);
708
659
  } else if (typeof _input === "object") {
709
660
  if (typeof _input.data === "string")
710
661
  _input.data = JSON.parse(_input.data);
@@ -712,7 +663,7 @@ var __exports__ = (() => {
712
663
  if (!_input.fields)
713
664
  _input.fields = _input.meta && _input.meta.fields;
714
665
  if (!_input.fields)
715
- _input.fields = Array.isArray(_input.data[0]) ? _input.fields : objectKeys(_input.data[0]);
666
+ _input.fields = Array.isArray(_input.data[0]) ? _input.fields : Object.keys(_input.data[0]);
716
667
  if (!Array.isArray(_input.data[0]) && typeof _input.data[0] !== "object")
717
668
  _input.data = [_input.data];
718
669
  }
@@ -746,14 +697,6 @@ var __exports__ = (() => {
746
697
  _escapedQuote = _config.escapeChar + _quoteChar;
747
698
  }
748
699
  }
749
- function objectKeys(obj) {
750
- if (typeof obj !== "object")
751
- return [];
752
- var keys = [];
753
- for (var key in obj)
754
- keys.push(key);
755
- return keys;
756
- }
757
700
  function serialize(fields, data, skipEmptyLines) {
758
701
  var csv2 = "";
759
702
  if (typeof fields === "string")
@@ -816,24 +759,33 @@ var __exports__ = (() => {
816
759
  return false;
817
760
  }
818
761
  }
819
- function ChunkStreamer(config) {
820
- this._handle = null;
821
- this._finished = false;
822
- this._completed = false;
823
- this._input = null;
824
- this._baseIndex = 0;
825
- this._partialLine = "";
826
- this._rowCount = 0;
827
- this._start = 0;
828
- this._nextChunk = null;
829
- this.isFirstChunk = true;
830
- this._completeResults = {
762
+ var ChunkStreamer = class {
763
+ _handle;
764
+ _config;
765
+ _finished = false;
766
+ _completed = false;
767
+ _input = null;
768
+ _baseIndex = 0;
769
+ _partialLine = "";
770
+ _rowCount = 0;
771
+ _start = 0;
772
+ isFirstChunk = true;
773
+ _completeResults = {
831
774
  data: [],
832
775
  errors: [],
833
776
  meta: {}
834
777
  };
835
- replaceConfig.call(this, config);
836
- this.parseChunk = function(chunk, isFakeChunk) {
778
+ constructor(config) {
779
+ var configCopy = { ...config };
780
+ configCopy.chunkSize = parseInt(configCopy.chunkSize);
781
+ if (!config.step && !config.chunk) {
782
+ configCopy.chunkSize = null;
783
+ }
784
+ this._handle = new ParserHandle(configCopy);
785
+ this._handle.streamer = this;
786
+ this._config = configCopy;
787
+ }
788
+ parseChunk(chunk, isFakeChunk) {
837
789
  if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk)) {
838
790
  var modifiedChunk = this._config.beforeFirstChunk(chunk);
839
791
  if (modifiedChunk !== void 0)
@@ -869,183 +821,191 @@ var __exports__ = (() => {
869
821
  this._config.complete(this._completeResults, this._input);
870
822
  this._completed = true;
871
823
  }
872
- if (!finishedIncludingPreview && (!results || !results.meta.paused))
873
- this._nextChunk();
874
824
  return results;
875
- };
876
- this._sendError = function(error) {
825
+ }
826
+ _sendError(error) {
877
827
  if (isFunction(this._config.error))
878
828
  this._config.error(error);
879
- };
880
- function replaceConfig(config2) {
881
- var configCopy = copy(config2);
882
- configCopy.chunkSize = parseInt(configCopy.chunkSize);
883
- if (!config2.step && !config2.chunk)
884
- configCopy.chunkSize = null;
885
- this._handle = new ParserHandle(configCopy);
886
- this._handle.streamer = this;
887
- this._config = configCopy;
888
829
  }
889
- }
890
- function StringStreamer(config) {
891
- config = config || {};
892
- ChunkStreamer.call(this, config);
893
- var remaining;
894
- this.stream = function(s) {
895
- remaining = s;
830
+ };
831
+ var StringStreamer = class extends ChunkStreamer {
832
+ remaining;
833
+ constructor(config = {}) {
834
+ super(config);
835
+ }
836
+ stream(s) {
837
+ this.remaining = s;
896
838
  return this._nextChunk();
897
- };
898
- this._nextChunk = function() {
839
+ }
840
+ _nextChunk() {
899
841
  if (this._finished)
900
842
  return;
901
843
  var size = this._config.chunkSize;
902
- var chunk = size ? remaining.substr(0, size) : remaining;
903
- remaining = size ? remaining.substr(size) : "";
904
- this._finished = !remaining;
844
+ var chunk = size ? this.remaining.substr(0, size) : this.remaining;
845
+ this.remaining = size ? this.remaining.substr(size) : "";
846
+ this._finished = !this.remaining;
905
847
  return this.parseChunk(chunk);
906
- };
907
- }
908
- StringStreamer.prototype = Object.create(StringStreamer.prototype);
909
- StringStreamer.prototype.constructor = StringStreamer;
910
- function ParserHandle(_config) {
911
- var FLOAT = /^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i;
912
- 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))/;
913
- var self = this;
914
- var _stepCounter = 0;
915
- var _rowCounter = 0;
916
- var _input;
917
- var _parser;
918
- var _paused = false;
919
- var _aborted = false;
920
- var _delimiterError;
921
- var _fields = [];
922
- var _results = {
923
- // The last results returned from the parser
848
+ }
849
+ };
850
+ var FLOAT = /^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i;
851
+ 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))/;
852
+ var ParserHandle = class {
853
+ _config;
854
+ /** Number of times step was called (number of rows parsed) */
855
+ _stepCounter = 0;
856
+ /** Number of rows that have been parsed so far */
857
+ _rowCounter = 0;
858
+ /** The input being parsed */
859
+ _input;
860
+ /** The core parser being used */
861
+ _parser;
862
+ /** Whether we are paused or not */
863
+ _paused = false;
864
+ /** Whether the parser has aborted or not */
865
+ _aborted = false;
866
+ /** Temporary state between delimiter detection and processing results */
867
+ _delimiterError = false;
868
+ /** Fields are from the header row of the input, if there is one */
869
+ _fields = [];
870
+ /** The last results returned from the parser */
871
+ _results = {
924
872
  data: [],
925
873
  errors: [],
926
874
  meta: {}
927
875
  };
928
- if (isFunction(_config.step)) {
929
- var userStep = _config.step;
930
- _config.step = function(results) {
931
- _results = results;
932
- if (needsHeaderRow())
933
- processResults();
934
- else {
935
- processResults();
936
- if (!_results.data || _results.data.length === 0)
937
- return;
938
- _stepCounter += results.data.length;
939
- if (_config.preview && _stepCounter > _config.preview)
940
- _parser.abort();
941
- else
942
- userStep(_results, self);
943
- }
944
- };
876
+ constructor(_config) {
877
+ if (isFunction(_config.step)) {
878
+ var userStep = _config.step;
879
+ _config.step = (results) => {
880
+ this._results = results;
881
+ if (this.needsHeaderRow()) {
882
+ this.processResults();
883
+ } else {
884
+ this.processResults();
885
+ if (!this._results.data || this._results.data.length === 0)
886
+ return;
887
+ this._stepCounter += results.data.length;
888
+ if (_config.preview && this._stepCounter > _config.preview) {
889
+ this._parser.abort();
890
+ } else {
891
+ userStep(this._results, this);
892
+ }
893
+ }
894
+ };
895
+ }
896
+ this._config = _config;
945
897
  }
946
- this.parse = function(input, baseIndex, ignoreLastRow) {
947
- var quoteChar = _config.quoteChar || '"';
948
- if (!_config.newline)
949
- _config.newline = guessLineEndings(input, quoteChar);
950
- _delimiterError = false;
951
- if (!_config.delimiter) {
952
- var delimGuess = guessDelimiter(
898
+ /**
899
+ * Parses input. Most users won't need, and shouldn't mess with, the baseIndex
900
+ * and ignoreLastRow parameters. They are used by streamers (wrapper functions)
901
+ * when an input comes in multiple chunks, like from a file.
902
+ */
903
+ parse(input, baseIndex, ignoreLastRow) {
904
+ var quoteChar = this._config.quoteChar || '"';
905
+ if (!this._config.newline)
906
+ this._config.newline = guessLineEndings(input, quoteChar);
907
+ this._delimiterError = false;
908
+ if (!this._config.delimiter) {
909
+ var delimGuess = this.guessDelimiter(
953
910
  input,
954
- _config.newline,
955
- _config.skipEmptyLines,
956
- _config.comments,
957
- _config.delimitersToGuess
911
+ this._config.newline,
912
+ this._config.skipEmptyLines,
913
+ this._config.comments,
914
+ this._config.delimitersToGuess
958
915
  );
959
- if (delimGuess.successful)
960
- _config.delimiter = delimGuess.bestDelimiter;
961
- else {
962
- _delimiterError = true;
963
- _config.delimiter = Papa.DefaultDelimiter;
916
+ if (delimGuess.successful) {
917
+ this._config.delimiter = delimGuess.bestDelimiter;
918
+ } else {
919
+ this._delimiterError = true;
920
+ this._config.delimiter = Papa.DefaultDelimiter;
964
921
  }
965
- _results.meta.delimiter = _config.delimiter;
966
- } else if (isFunction(_config.delimiter)) {
967
- _config.delimiter = _config.delimiter(input);
968
- _results.meta.delimiter = _config.delimiter;
922
+ this._results.meta.delimiter = this._config.delimiter;
923
+ } else if (isFunction(this._config.delimiter)) {
924
+ this._config.delimiter = this._config.delimiter(input);
925
+ this._results.meta.delimiter = this._config.delimiter;
969
926
  }
970
- var parserConfig = copy(_config);
971
- if (_config.preview && _config.header)
927
+ var parserConfig = copy(this._config);
928
+ if (this._config.preview && this._config.header)
972
929
  parserConfig.preview++;
973
- _input = input;
974
- _parser = new Parser(parserConfig);
975
- _results = _parser.parse(_input, baseIndex, ignoreLastRow);
976
- processResults();
977
- return _paused ? { meta: { paused: true } } : _results || { meta: { paused: false } };
978
- };
979
- this.paused = function() {
980
- return _paused;
981
- };
982
- this.pause = function() {
983
- _paused = true;
984
- _parser.abort();
985
- _input = _input.substr(_parser.getCharIndex());
986
- };
987
- this.resume = function() {
988
- _paused = false;
989
- self.streamer.parseChunk(_input, true);
990
- };
991
- this.aborted = function() {
992
- return _aborted;
993
- };
994
- this.abort = function() {
995
- _aborted = true;
996
- _parser.abort();
997
- _results.meta.aborted = true;
998
- if (isFunction(_config.complete))
999
- _config.complete(_results);
1000
- _input = "";
1001
- };
1002
- function testEmptyLine(s) {
1003
- return _config.skipEmptyLines === "greedy" ? s.join("").trim() === "" : s.length === 1 && s[0].length === 0;
1004
- }
1005
- function processResults() {
1006
- if (_results && _delimiterError) {
1007
- addError(
930
+ this._input = input;
931
+ this._parser = new Parser(parserConfig);
932
+ this._results = this._parser.parse(this._input, baseIndex, ignoreLastRow);
933
+ this.processResults();
934
+ return this._paused ? { meta: { paused: true } } : this._results || { meta: { paused: false } };
935
+ }
936
+ paused() {
937
+ return this._paused;
938
+ }
939
+ pause() {
940
+ this._paused = true;
941
+ this._parser.abort();
942
+ this._input = this._input.substr(this._parser.getCharIndex());
943
+ }
944
+ resume() {
945
+ this._paused = false;
946
+ this.streamer.parseChunk(this._input, true);
947
+ }
948
+ aborted() {
949
+ return this._aborted;
950
+ }
951
+ abort() {
952
+ this._aborted = true;
953
+ this._parser.abort();
954
+ this._results.meta.aborted = true;
955
+ if (isFunction(this._config.complete)) {
956
+ this._config.complete(this._results);
957
+ }
958
+ this._input = "";
959
+ }
960
+ testEmptyLine(s) {
961
+ return this._config.skipEmptyLines === "greedy" ? s.join("").trim() === "" : s.length === 1 && s[0].length === 0;
962
+ }
963
+ processResults() {
964
+ if (this._results && this._delimiterError) {
965
+ this.addError(
1008
966
  "Delimiter",
1009
967
  "UndetectableDelimiter",
1010
968
  "Unable to auto-detect delimiting character; defaulted to '" + Papa.DefaultDelimiter + "'"
1011
969
  );
1012
- _delimiterError = false;
970
+ this._delimiterError = false;
971
+ }
972
+ if (this._config.skipEmptyLines) {
973
+ for (var i = 0; i < this._results.data.length; i++)
974
+ if (this.testEmptyLine(this._results.data[i]))
975
+ this._results.data.splice(i--, 1);
1013
976
  }
1014
- if (_config.skipEmptyLines) {
1015
- for (var i = 0; i < _results.data.length; i++)
1016
- if (testEmptyLine(_results.data[i]))
1017
- _results.data.splice(i--, 1);
977
+ if (this.needsHeaderRow()) {
978
+ this.fillHeaderFields();
1018
979
  }
1019
- if (needsHeaderRow())
1020
- fillHeaderFields();
1021
- return applyHeaderAndDynamicTypingAndTransformation();
980
+ return this.applyHeaderAndDynamicTypingAndTransformation();
1022
981
  }
1023
- function needsHeaderRow() {
1024
- return _config.header && _fields.length === 0;
982
+ needsHeaderRow() {
983
+ return this._config.header && this._fields.length === 0;
1025
984
  }
1026
- function fillHeaderFields() {
1027
- if (!_results)
985
+ fillHeaderFields() {
986
+ if (!this._results)
1028
987
  return;
1029
- function addHeder(header) {
1030
- if (isFunction(_config.transformHeader))
1031
- header = _config.transformHeader(header);
1032
- _fields.push(header);
1033
- }
1034
- if (Array.isArray(_results.data[0])) {
1035
- for (var i = 0; needsHeaderRow() && i < _results.data.length; i++)
1036
- _results.data[i].forEach(addHeder);
1037
- _results.data.splice(0, 1);
1038
- } else
1039
- _results.data.forEach(addHeder);
1040
- }
1041
- function shouldApplyDynamicTyping(field) {
1042
- if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === void 0) {
1043
- _config.dynamicTyping[field] = _config.dynamicTypingFunction(field);
1044
- }
1045
- return (_config.dynamicTyping[field] || _config.dynamicTyping) === true;
1046
- }
1047
- function parseDynamic(field, value) {
1048
- if (shouldApplyDynamicTyping(field)) {
988
+ const addHeder = (header) => {
989
+ if (isFunction(this._config.transformHeader))
990
+ header = this._config.transformHeader(header);
991
+ this._fields.push(header);
992
+ };
993
+ if (Array.isArray(this._results.data[0])) {
994
+ for (var i = 0; this.needsHeaderRow() && i < this._results.data.length; i++)
995
+ this._results.data[i].forEach(addHeder);
996
+ this._results.data.splice(0, 1);
997
+ } else {
998
+ this._results.data.forEach(addHeder);
999
+ }
1000
+ }
1001
+ shouldApplyDynamicTyping(field) {
1002
+ if (this._config.dynamicTypingFunction && this._config.dynamicTyping[field] === void 0) {
1003
+ this._config.dynamicTyping[field] = this._config.dynamicTypingFunction(field);
1004
+ }
1005
+ return (this._config.dynamicTyping[field] || this._config.dynamicTyping) === true;
1006
+ }
1007
+ parseDynamic(field, value) {
1008
+ if (this.shouldApplyDynamicTyping(field)) {
1049
1009
  if (value === "true" || value === "TRUE")
1050
1010
  return true;
1051
1011
  else if (value === "false" || value === "FALSE")
@@ -1059,56 +1019,58 @@ var __exports__ = (() => {
1059
1019
  }
1060
1020
  return value;
1061
1021
  }
1062
- function applyHeaderAndDynamicTypingAndTransformation() {
1063
- if (!_results || !_results.data || !_config.header && !_config.dynamicTyping && !_config.transform)
1064
- return _results;
1065
- function processRow(rowSource, i) {
1066
- var row = _config.header ? {} : [];
1067
- var j;
1068
- for (j = 0; j < rowSource.length; j++) {
1069
- var field = j;
1070
- var value = rowSource[j];
1071
- if (_config.header)
1072
- field = j >= _fields.length ? "__parsed_extra" : _fields[j];
1073
- if (_config.transform)
1074
- value = _config.transform(value, field);
1075
- value = parseDynamic(field, value);
1076
- if (field === "__parsed_extra") {
1077
- row[field] = row[field] || [];
1078
- row[field].push(value);
1079
- } else
1080
- row[field] = value;
1081
- }
1082
- if (_config.header) {
1083
- if (j > _fields.length)
1084
- addError(
1085
- "FieldMismatch",
1086
- "TooManyFields",
1087
- "Too many fields: expected " + _fields.length + " fields but parsed " + j,
1088
- _rowCounter + i
1089
- );
1090
- else if (j < _fields.length)
1091
- addError(
1092
- "FieldMismatch",
1093
- "TooFewFields",
1094
- "Too few fields: expected " + _fields.length + " fields but parsed " + j,
1095
- _rowCounter + i
1096
- );
1097
- }
1098
- return row;
1022
+ applyHeaderAndDynamicTypingAndTransformation() {
1023
+ if (!this._results || !this._results.data || !this._config.header && !this._config.dynamicTyping && !this._config.transform) {
1024
+ return this._results;
1099
1025
  }
1100
1026
  var incrementBy = 1;
1101
- if (!_results.data[0] || Array.isArray(_results.data[0])) {
1102
- _results.data = _results.data.map(processRow);
1103
- incrementBy = _results.data.length;
1104
- } else
1105
- _results.data = processRow(_results.data, 0);
1106
- if (_config.header && _results.meta)
1107
- _results.meta.fields = _fields;
1108
- _rowCounter += incrementBy;
1109
- return _results;
1110
- }
1111
- function guessDelimiter(input, newline, skipEmptyLines, comments, delimitersToGuess) {
1027
+ if (!this._results.data[0] || Array.isArray(this._results.data[0])) {
1028
+ this._results.data = this._results.data.map(this.processRow.bind(this));
1029
+ incrementBy = this._results.data.length;
1030
+ } else {
1031
+ this._results.data = this.processRow(this._results.data, 0);
1032
+ }
1033
+ if (this._config.header && this._results.meta)
1034
+ this._results.meta.fields = this._fields;
1035
+ this._rowCounter += incrementBy;
1036
+ return this._results;
1037
+ }
1038
+ processRow(rowSource, i) {
1039
+ var row = this._config.header ? {} : [];
1040
+ var j;
1041
+ for (j = 0; j < rowSource.length; j++) {
1042
+ var field = j;
1043
+ var value = rowSource[j];
1044
+ if (this._config.header)
1045
+ field = j >= this._fields.length ? "__parsed_extra" : this._fields[j];
1046
+ if (this._config.transform)
1047
+ value = this._config.transform(value, field);
1048
+ value = this.parseDynamic(field, value);
1049
+ if (field === "__parsed_extra") {
1050
+ row[field] = row[field] || [];
1051
+ row[field].push(value);
1052
+ } else
1053
+ row[field] = value;
1054
+ }
1055
+ if (this._config.header) {
1056
+ if (j > this._fields.length)
1057
+ this.addError(
1058
+ "FieldMismatch",
1059
+ "TooManyFields",
1060
+ "Too many fields: expected " + this._fields.length + " fields but parsed " + j,
1061
+ this._rowCounter + i
1062
+ );
1063
+ else if (j < this._fields.length)
1064
+ this.addError(
1065
+ "FieldMismatch",
1066
+ "TooFewFields",
1067
+ "Too few fields: expected " + this._fields.length + " fields but parsed " + j,
1068
+ this._rowCounter + i
1069
+ );
1070
+ }
1071
+ return row;
1072
+ }
1073
+ guessDelimiter(input, newline, skipEmptyLines, comments, delimitersToGuess) {
1112
1074
  var bestDelim, bestDelta, fieldCountPrevRow;
1113
1075
  delimitersToGuess = delimitersToGuess || [",", " ", "|", ";", Papa.RECORD_SEP, Papa.UNIT_SEP];
1114
1076
  for (var i = 0; i < delimitersToGuess.length; i++) {
@@ -1122,7 +1084,7 @@ var __exports__ = (() => {
1122
1084
  preview: 10
1123
1085
  }).parse(input);
1124
1086
  for (var j = 0; j < preview.data.length; j++) {
1125
- if (skipEmptyLines && testEmptyLine(preview.data[j])) {
1087
+ if (skipEmptyLines && this.testEmptyLine(preview.data[j])) {
1126
1088
  emptyLinesCount++;
1127
1089
  continue;
1128
1090
  }
@@ -1143,36 +1105,36 @@ var __exports__ = (() => {
1143
1105
  bestDelim = delim;
1144
1106
  }
1145
1107
  }
1146
- _config.delimiter = bestDelim;
1108
+ this._config.delimiter = bestDelim;
1147
1109
  return {
1148
1110
  successful: !!bestDelim,
1149
1111
  bestDelimiter: bestDelim
1150
1112
  };
1151
1113
  }
1152
- function guessLineEndings(input, quoteChar) {
1153
- input = input.substr(0, 1024 * 1024);
1154
- var re = new RegExp(escapeRegExp(quoteChar) + "([^]*?)" + escapeRegExp(quoteChar), "gm");
1155
- input = input.replace(re, "");
1156
- var r = input.split("\r");
1157
- var n = input.split("\n");
1158
- var nAppearsFirst = n.length > 1 && n[0].length < r[0].length;
1159
- if (r.length === 1 || nAppearsFirst)
1160
- return "\n";
1161
- var numWithN = 0;
1162
- for (var i = 0; i < r.length; i++) {
1163
- if (r[i][0] === "\n")
1164
- numWithN++;
1165
- }
1166
- return numWithN >= r.length / 2 ? "\r\n" : "\r";
1167
- }
1168
- function addError(type, code, msg, row) {
1169
- _results.errors.push({
1114
+ addError(type, code, msg, row) {
1115
+ this._results.errors.push({
1170
1116
  type,
1171
1117
  code,
1172
1118
  message: msg,
1173
1119
  row
1174
1120
  });
1175
1121
  }
1122
+ };
1123
+ function guessLineEndings(input, quoteChar) {
1124
+ input = input.substr(0, 1024 * 1024);
1125
+ var re = new RegExp(escapeRegExp(quoteChar) + "([^]*?)" + escapeRegExp(quoteChar), "gm");
1126
+ input = input.replace(re, "");
1127
+ var r = input.split("\r");
1128
+ var n = input.split("\n");
1129
+ var nAppearsFirst = n.length > 1 && n[0].length < r[0].length;
1130
+ if (r.length === 1 || nAppearsFirst)
1131
+ return "\n";
1132
+ var numWithN = 0;
1133
+ for (var i = 0; i < r.length; i++) {
1134
+ if (r[i][0] === "\n")
1135
+ numWithN++;
1136
+ }
1137
+ return numWithN >= r.length / 2 ? "\r\n" : "\r";
1176
1138
  }
1177
1139
  function escapeRegExp(string) {
1178
1140
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1219,22 +1181,22 @@ var __exports__ = (() => {
1219
1181
  if (fastMode || fastMode !== false && input.indexOf(quoteChar) === -1) {
1220
1182
  var rows = input.split(newline);
1221
1183
  for (var i = 0; i < rows.length; i++) {
1222
- row = rows[i];
1223
- cursor += row.length;
1184
+ const row2 = rows[i];
1185
+ cursor += row2.length;
1224
1186
  if (i !== rows.length - 1)
1225
1187
  cursor += newline.length;
1226
1188
  else if (ignoreLastRow)
1227
1189
  return returnable();
1228
- if (comments && row.substr(0, commentsLen) === comments)
1190
+ if (comments && row2.substr(0, commentsLen) === comments)
1229
1191
  continue;
1230
1192
  if (stepIsFunction) {
1231
1193
  data = [];
1232
- pushRow(row.split(delim));
1194
+ pushRow(row2.split(delim));
1233
1195
  doStep();
1234
1196
  if (aborted)
1235
1197
  return returnable();
1236
1198
  } else
1237
- pushRow(row.split(delim));
1199
+ pushRow(row2.split(delim));
1238
1200
  if (preview && i >= preview) {
1239
1201
  data = data.slice(0, preview);
1240
1202
  return returnable(true);
@@ -1425,14 +1387,47 @@ var __exports__ = (() => {
1425
1387
  function isFunction(func) {
1426
1388
  return typeof func === "function";
1427
1389
  }
1390
+ var Papa = {
1391
+ parse: CsvToJson,
1392
+ unparse: JsonToCsv,
1393
+ RECORD_SEP: String.fromCharCode(30),
1394
+ UNIT_SEP: String.fromCharCode(31),
1395
+ BYTE_ORDER_MARK,
1396
+ BAD_DELIMITERS: ["\r", "\n", '"', BYTE_ORDER_MARK],
1397
+ WORKERS_SUPPORTED: false,
1398
+ // !IS_WORKER && !!globalThis.Worker
1399
+ NODE_STREAM_INPUT: 1,
1400
+ // Configurable chunk sizes for local and remote files, respectively
1401
+ LocalChunkSize: 1024 * 1024 * 10,
1402
+ // 10 M,
1403
+ RemoteChunkSize: 1024 * 1024 * 5,
1404
+ // 5 M,
1405
+ DefaultDelimiter: ",",
1406
+ // Used if not specified and detection fail,
1407
+ // Exposed for testing and development only
1408
+ Parser,
1409
+ ParserHandle,
1410
+ // BEGIN FORK
1411
+ ChunkStreamer
1412
+ };
1413
+ var papaparse_default = Papa;
1428
1414
 
1429
1415
  // src/papaparse/async-iterator-streamer.ts
1430
1416
  var { ChunkStreamer: ChunkStreamer2 } = papaparse_default;
1431
- function AsyncIteratorStreamer(config) {
1432
- config = config || {};
1433
- ChunkStreamer2.call(this, config);
1434
- this.textDecoder = new TextDecoder(this._config.encoding);
1435
- this.stream = async function(asyncIterator) {
1417
+ var AsyncIteratorStreamer = class extends ChunkStreamer2 {
1418
+ textDecoder = new TextDecoder(this._config.encoding);
1419
+ constructor(config = {}) {
1420
+ super(config);
1421
+ }
1422
+ // Implement ChunkStreamer base class methods
1423
+ // this.pause = function() {
1424
+ // ChunkStreamer.prototype.pause.apply(this, arguments);
1425
+ // };
1426
+ // this.resume = function() {
1427
+ // ChunkStreamer.prototype.resume.apply(this, arguments);
1428
+ // this._input.resume();
1429
+ // };
1430
+ async stream(asyncIterator) {
1436
1431
  this._input = asyncIterator;
1437
1432
  try {
1438
1433
  for await (const chunk of asyncIterator) {
@@ -1443,15 +1438,14 @@ var __exports__ = (() => {
1443
1438
  } catch (error) {
1444
1439
  this._sendError(error);
1445
1440
  }
1446
- };
1447
- this._nextChunk = function nextChunk() {
1448
- };
1449
- this.getStringChunk = function(chunk) {
1441
+ }
1442
+ _nextChunk() {
1443
+ }
1444
+ // HELPER METHODS
1445
+ getStringChunk(chunk) {
1450
1446
  return typeof chunk === "string" ? chunk : this.textDecoder.decode(chunk, { stream: true });
1451
- };
1452
- }
1453
- AsyncIteratorStreamer.prototype = Object.create(ChunkStreamer2.prototype);
1454
- AsyncIteratorStreamer.prototype.constructor = AsyncIteratorStreamer;
1447
+ }
1448
+ };
1455
1449
 
1456
1450
  // src/csv-loader.ts
1457
1451
  var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
@@ -1624,7 +1618,6 @@ var __exports__ = (() => {
1624
1618
  }
1625
1619
  function readFirstRow(csvText) {
1626
1620
  const result = papaparse_default.parse(csvText, {
1627
- download: false,
1628
1621
  dynamicTyping: true,
1629
1622
  preview: 1
1630
1623
  });