@bigbinary/neeto-email-notifications-frontend 2.2.21 → 2.2.23

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.
@@ -0,0 +1,2141 @@
1
+ import * as React from 'react';
2
+ import require$$0 from 'stream';
3
+ import { useQuery } from '@tanstack/react-query';
4
+ import { isNotEmpty } from '@bigbinary/neeto-cist';
5
+ import { DEFAULT_STALE_TIME } from '@bigbinary/neeto-commons-frontend/constants';
6
+ import { useMutationWithInvalidation } from '@bigbinary/neeto-commons-frontend/react-utils';
7
+ import { prop } from 'ramda';
8
+ import axios from 'axios';
9
+
10
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
11
+
12
+ function getDefaultExportFromCjs (x) {
13
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
14
+ }
15
+
16
+ var propTypes = {exports: {}};
17
+
18
+ /**
19
+ * Copyright (c) 2013-present, Facebook, Inc.
20
+ *
21
+ * This source code is licensed under the MIT license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ */
24
+
25
+ var ReactPropTypesSecret_1;
26
+ var hasRequiredReactPropTypesSecret;
27
+
28
+ function requireReactPropTypesSecret () {
29
+ if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
30
+ hasRequiredReactPropTypesSecret = 1;
31
+
32
+ var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
33
+
34
+ ReactPropTypesSecret_1 = ReactPropTypesSecret;
35
+ return ReactPropTypesSecret_1;
36
+ }
37
+
38
+ /**
39
+ * Copyright (c) 2013-present, Facebook, Inc.
40
+ *
41
+ * This source code is licensed under the MIT license found in the
42
+ * LICENSE file in the root directory of this source tree.
43
+ */
44
+
45
+ var factoryWithThrowingShims;
46
+ var hasRequiredFactoryWithThrowingShims;
47
+
48
+ function requireFactoryWithThrowingShims () {
49
+ if (hasRequiredFactoryWithThrowingShims) return factoryWithThrowingShims;
50
+ hasRequiredFactoryWithThrowingShims = 1;
51
+
52
+ var ReactPropTypesSecret = requireReactPropTypesSecret();
53
+
54
+ function emptyFunction() {}
55
+ function emptyFunctionWithReset() {}
56
+ emptyFunctionWithReset.resetWarningCache = emptyFunction;
57
+
58
+ factoryWithThrowingShims = function() {
59
+ function shim(props, propName, componentName, location, propFullName, secret) {
60
+ if (secret === ReactPropTypesSecret) {
61
+ // It is still safe when called from React.
62
+ return;
63
+ }
64
+ var err = new Error(
65
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
66
+ 'Use PropTypes.checkPropTypes() to call them. ' +
67
+ 'Read more at http://fb.me/use-check-prop-types'
68
+ );
69
+ err.name = 'Invariant Violation';
70
+ throw err;
71
+ } shim.isRequired = shim;
72
+ function getShim() {
73
+ return shim;
74
+ } // Important!
75
+ // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
76
+ var ReactPropTypes = {
77
+ array: shim,
78
+ bigint: shim,
79
+ bool: shim,
80
+ func: shim,
81
+ number: shim,
82
+ object: shim,
83
+ string: shim,
84
+ symbol: shim,
85
+
86
+ any: shim,
87
+ arrayOf: getShim,
88
+ element: shim,
89
+ elementType: shim,
90
+ instanceOf: getShim,
91
+ node: shim,
92
+ objectOf: getShim,
93
+ oneOf: getShim,
94
+ oneOfType: getShim,
95
+ shape: getShim,
96
+ exact: getShim,
97
+
98
+ checkPropTypes: emptyFunctionWithReset,
99
+ resetWarningCache: emptyFunction
100
+ };
101
+
102
+ ReactPropTypes.PropTypes = ReactPropTypes;
103
+
104
+ return ReactPropTypes;
105
+ };
106
+ return factoryWithThrowingShims;
107
+ }
108
+
109
+ /**
110
+ * Copyright (c) 2013-present, Facebook, Inc.
111
+ *
112
+ * This source code is licensed under the MIT license found in the
113
+ * LICENSE file in the root directory of this source tree.
114
+ */
115
+
116
+ {
117
+ // By explicitly using `prop-types` you are opting into new production behavior.
118
+ // http://fb.me/prop-types-in-prod
119
+ propTypes.exports = requireFactoryWithThrowingShims()();
120
+ }
121
+
122
+ var propTypesExports = propTypes.exports;
123
+ var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
124
+
125
+ var _rect, _path;
126
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
127
+ var SvgAvatarPlaceholder = function SvgAvatarPlaceholder(props) {
128
+ return /*#__PURE__*/React.createElement("svg", _extends({
129
+ xmlns: "http://www.w3.org/2000/svg",
130
+ width: 32,
131
+ height: 32,
132
+ fill: "none"
133
+ }, props), _rect || (_rect = /*#__PURE__*/React.createElement("rect", {
134
+ width: 31.558,
135
+ height: 31.558,
136
+ fill: "#F1F3F4",
137
+ rx: 15.779
138
+ })), _path || (_path = /*#__PURE__*/React.createElement("path", {
139
+ fill: "#C2C8CC",
140
+ d: "M15.778 15.778a2.892 2.892 0 1 0 0-5.786 2.892 2.892 0 1 0 0 5.786m0 1.446c-1.931 0-5.786.97-5.786 2.893v1.447h11.572v-1.447c0-1.924-3.855-2.893-5.786-2.893"
141
+ })));
142
+ };
143
+
144
+ var papaparse = {exports: {}};
145
+
146
+ /* @license
147
+ Papa Parse
148
+ v5.5.3
149
+ https://github.com/mholt/PapaParse
150
+ License: MIT
151
+ */
152
+
153
+ (function (module, exports$1) {
154
+ (function(root, factory)
155
+ {
156
+ /* globals define */
157
+ {
158
+ // Node. Does not work with strict CommonJS, but
159
+ // only CommonJS-like environments that support module.exports,
160
+ // like Node.
161
+ module.exports = factory();
162
+ }
163
+ // in strict mode we cannot access arguments.callee, so we need a named reference to
164
+ // stringify the factory method for the blob worker
165
+ // eslint-disable-next-line func-name
166
+ }(commonjsGlobal, function moduleFactory()
167
+ {
168
+
169
+ var global = (function() {
170
+ // alternative method, similar to `Function('return this')()`
171
+ // but without using `eval` (which is disabled when
172
+ // using Content Security Policy).
173
+
174
+ if (typeof self !== 'undefined') { return self; }
175
+ if (typeof window !== 'undefined') { return window; }
176
+ if (typeof global !== 'undefined') { return global; }
177
+
178
+ // When running tests none of the above have been defined
179
+ return {};
180
+ })();
181
+
182
+
183
+ function getWorkerBlob() {
184
+ var URL = global.URL || global.webkitURL || null;
185
+ var code = moduleFactory.toString();
186
+ return Papa.BLOB_URL || (Papa.BLOB_URL = URL.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ", '(', code, ')();'], {type: 'text/javascript'})));
187
+ }
188
+
189
+ var IS_WORKER = !global.document && !!global.postMessage,
190
+ IS_PAPA_WORKER = global.IS_PAPA_WORKER || false;
191
+
192
+ var workers = {}, workerIdCounter = 0;
193
+
194
+ var Papa = {};
195
+
196
+ Papa.parse = CsvToJson;
197
+ Papa.unparse = JsonToCsv;
198
+
199
+ Papa.RECORD_SEP = String.fromCharCode(30);
200
+ Papa.UNIT_SEP = String.fromCharCode(31);
201
+ Papa.BYTE_ORDER_MARK = '\ufeff';
202
+ Papa.BAD_DELIMITERS = ['\r', '\n', '"', Papa.BYTE_ORDER_MARK];
203
+ Papa.WORKERS_SUPPORTED = !IS_WORKER && !!global.Worker;
204
+ Papa.NODE_STREAM_INPUT = 1;
205
+
206
+ // Configurable chunk sizes for local and remote files, respectively
207
+ Papa.LocalChunkSize = 1024 * 1024 * 10; // 10 MB
208
+ Papa.RemoteChunkSize = 1024 * 1024 * 5; // 5 MB
209
+ Papa.DefaultDelimiter = ','; // Used if not specified and detection fails
210
+
211
+ // Exposed for testing and development only
212
+ Papa.Parser = Parser;
213
+ Papa.ParserHandle = ParserHandle;
214
+ Papa.NetworkStreamer = NetworkStreamer;
215
+ Papa.FileStreamer = FileStreamer;
216
+ Papa.StringStreamer = StringStreamer;
217
+ Papa.ReadableStreamStreamer = ReadableStreamStreamer;
218
+ if (typeof PAPA_BROWSER_CONTEXT === 'undefined') {
219
+ Papa.DuplexStreamStreamer = DuplexStreamStreamer;
220
+ }
221
+
222
+ if (global.jQuery)
223
+ {
224
+ var $ = global.jQuery;
225
+ $.fn.parse = function(options)
226
+ {
227
+ var config = options.config || {};
228
+ var queue = [];
229
+
230
+ this.each(function(idx)
231
+ {
232
+ var supported = $(this).prop('tagName').toUpperCase() === 'INPUT'
233
+ && $(this).attr('type').toLowerCase() === 'file'
234
+ && global.FileReader;
235
+
236
+ if (!supported || !this.files || this.files.length === 0)
237
+ return true; // continue to next input element
238
+
239
+ for (var i = 0; i < this.files.length; i++)
240
+ {
241
+ queue.push({
242
+ file: this.files[i],
243
+ inputElem: this,
244
+ instanceConfig: $.extend({}, config)
245
+ });
246
+ }
247
+ });
248
+
249
+ parseNextFile(); // begin parsing
250
+ return this; // maintains chainability
251
+
252
+
253
+ function parseNextFile()
254
+ {
255
+ if (queue.length === 0)
256
+ {
257
+ if (isFunction(options.complete))
258
+ options.complete();
259
+ return;
260
+ }
261
+
262
+ var f = queue[0];
263
+
264
+ if (isFunction(options.before))
265
+ {
266
+ var returned = options.before(f.file, f.inputElem);
267
+
268
+ if (typeof returned === 'object')
269
+ {
270
+ if (returned.action === 'abort')
271
+ {
272
+ error('AbortError', f.file, f.inputElem, returned.reason);
273
+ return; // Aborts all queued files immediately
274
+ }
275
+ else if (returned.action === 'skip')
276
+ {
277
+ fileComplete(); // parse the next file in the queue, if any
278
+ return;
279
+ }
280
+ else if (typeof returned.config === 'object')
281
+ f.instanceConfig = $.extend(f.instanceConfig, returned.config);
282
+ }
283
+ else if (returned === 'skip')
284
+ {
285
+ fileComplete(); // parse the next file in the queue, if any
286
+ return;
287
+ }
288
+ }
289
+
290
+ // Wrap up the user's complete callback, if any, so that ours also gets executed
291
+ var userCompleteFunc = f.instanceConfig.complete;
292
+ f.instanceConfig.complete = function(results)
293
+ {
294
+ if (isFunction(userCompleteFunc))
295
+ userCompleteFunc(results, f.file, f.inputElem);
296
+ fileComplete();
297
+ };
298
+
299
+ Papa.parse(f.file, f.instanceConfig);
300
+ }
301
+
302
+ function error(name, file, elem, reason)
303
+ {
304
+ if (isFunction(options.error))
305
+ options.error({name: name}, file, elem, reason);
306
+ }
307
+
308
+ function fileComplete()
309
+ {
310
+ queue.splice(0, 1);
311
+ parseNextFile();
312
+ }
313
+ };
314
+ }
315
+
316
+
317
+ if (IS_PAPA_WORKER)
318
+ {
319
+ global.onmessage = workerThreadReceivedMessage;
320
+ }
321
+
322
+
323
+
324
+
325
+ function CsvToJson(_input, _config)
326
+ {
327
+ _config = _config || {};
328
+ var dynamicTyping = _config.dynamicTyping || false;
329
+ if (isFunction(dynamicTyping)) {
330
+ _config.dynamicTypingFunction = dynamicTyping;
331
+ // Will be filled on first row call
332
+ dynamicTyping = {};
333
+ }
334
+ _config.dynamicTyping = dynamicTyping;
335
+
336
+ _config.transform = isFunction(_config.transform) ? _config.transform : false;
337
+
338
+ if (_config.worker && Papa.WORKERS_SUPPORTED)
339
+ {
340
+ var w = newWorker();
341
+
342
+ w.userStep = _config.step;
343
+ w.userChunk = _config.chunk;
344
+ w.userComplete = _config.complete;
345
+ w.userError = _config.error;
346
+
347
+ _config.step = isFunction(_config.step);
348
+ _config.chunk = isFunction(_config.chunk);
349
+ _config.complete = isFunction(_config.complete);
350
+ _config.error = isFunction(_config.error);
351
+ delete _config.worker; // prevent infinite loop
352
+
353
+ w.postMessage({
354
+ input: _input,
355
+ config: _config,
356
+ workerId: w.id
357
+ });
358
+
359
+ return;
360
+ }
361
+
362
+ var streamer = null;
363
+ if (_input === Papa.NODE_STREAM_INPUT && typeof PAPA_BROWSER_CONTEXT === 'undefined')
364
+ {
365
+ // create a node Duplex stream for use
366
+ // with .pipe
367
+ streamer = new DuplexStreamStreamer(_config);
368
+ return streamer.getStream();
369
+ }
370
+ else if (typeof _input === 'string')
371
+ {
372
+ _input = stripBom(_input);
373
+ if (_config.download)
374
+ streamer = new NetworkStreamer(_config);
375
+ else
376
+ streamer = new StringStreamer(_config);
377
+ }
378
+ else if (_input.readable === true && isFunction(_input.read) && isFunction(_input.on))
379
+ {
380
+ streamer = new ReadableStreamStreamer(_config);
381
+ }
382
+ else if ((global.File && _input instanceof File) || _input instanceof Object) // ...Safari. (see issue #106)
383
+ streamer = new FileStreamer(_config);
384
+
385
+ return streamer.stream(_input);
386
+
387
+ // Strip character from UTF-8 BOM encoded files that cause issue parsing the file
388
+ function stripBom(string) {
389
+ if (string.charCodeAt(0) === 0xfeff) {
390
+ return string.slice(1);
391
+ }
392
+ return string;
393
+ }
394
+ }
395
+
396
+
397
+
398
+
399
+
400
+
401
+ function JsonToCsv(_input, _config)
402
+ {
403
+ // Default configuration
404
+
405
+ /** whether to surround every datum with quotes */
406
+ var _quotes = false;
407
+
408
+ /** whether to write headers */
409
+ var _writeHeader = true;
410
+
411
+ /** delimiting character(s) */
412
+ var _delimiter = ',';
413
+
414
+ /** newline character(s) */
415
+ var _newline = '\r\n';
416
+
417
+ /** quote character */
418
+ var _quoteChar = '"';
419
+
420
+ /** escaped quote character, either "" or <config.escapeChar>" */
421
+ var _escapedQuote = _quoteChar + _quoteChar;
422
+
423
+ /** whether to skip empty lines */
424
+ var _skipEmptyLines = false;
425
+
426
+ /** the columns (keys) we expect when we unparse objects */
427
+ var _columns = null;
428
+
429
+ /** whether to prevent outputting cells that can be parsed as formulae by spreadsheet software (Excel and LibreOffice) */
430
+ var _escapeFormulae = false;
431
+
432
+ unpackConfig();
433
+
434
+ var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), 'g');
435
+
436
+ if (typeof _input === 'string')
437
+ _input = JSON.parse(_input);
438
+
439
+ if (Array.isArray(_input))
440
+ {
441
+ if (!_input.length || Array.isArray(_input[0]))
442
+ return serialize(null, _input, _skipEmptyLines);
443
+ else if (typeof _input[0] === 'object')
444
+ return serialize(_columns || Object.keys(_input[0]), _input, _skipEmptyLines);
445
+ }
446
+ else if (typeof _input === 'object')
447
+ {
448
+ if (typeof _input.data === 'string')
449
+ _input.data = JSON.parse(_input.data);
450
+
451
+ if (Array.isArray(_input.data))
452
+ {
453
+ if (!_input.fields)
454
+ _input.fields = _input.meta && _input.meta.fields || _columns;
455
+
456
+ if (!_input.fields)
457
+ _input.fields = Array.isArray(_input.data[0])
458
+ ? _input.fields
459
+ : typeof _input.data[0] === 'object'
460
+ ? Object.keys(_input.data[0])
461
+ : [];
462
+
463
+ if (!(Array.isArray(_input.data[0])) && typeof _input.data[0] !== 'object')
464
+ _input.data = [_input.data]; // handles input like [1,2,3] or ['asdf']
465
+ }
466
+
467
+ return serialize(_input.fields || [], _input.data || [], _skipEmptyLines);
468
+ }
469
+
470
+ // Default (any valid paths should return before this)
471
+ throw new Error('Unable to serialize unrecognized input');
472
+
473
+
474
+ function unpackConfig()
475
+ {
476
+ if (typeof _config !== 'object')
477
+ return;
478
+
479
+ if (typeof _config.delimiter === 'string'
480
+ && !Papa.BAD_DELIMITERS.filter(function(value) { return _config.delimiter.indexOf(value) !== -1; }).length)
481
+ {
482
+ _delimiter = _config.delimiter;
483
+ }
484
+
485
+ if (typeof _config.quotes === 'boolean'
486
+ || typeof _config.quotes === 'function'
487
+ || Array.isArray(_config.quotes))
488
+ _quotes = _config.quotes;
489
+
490
+ if (typeof _config.skipEmptyLines === 'boolean'
491
+ || typeof _config.skipEmptyLines === 'string')
492
+ _skipEmptyLines = _config.skipEmptyLines;
493
+
494
+ if (typeof _config.newline === 'string')
495
+ _newline = _config.newline;
496
+
497
+ if (typeof _config.quoteChar === 'string')
498
+ _quoteChar = _config.quoteChar;
499
+
500
+ if (typeof _config.header === 'boolean')
501
+ _writeHeader = _config.header;
502
+
503
+ if (Array.isArray(_config.columns)) {
504
+
505
+ if (_config.columns.length === 0) throw new Error('Option columns is empty');
506
+
507
+ _columns = _config.columns;
508
+ }
509
+
510
+ if (_config.escapeChar !== undefined) {
511
+ _escapedQuote = _config.escapeChar + _quoteChar;
512
+ }
513
+
514
+ if (_config.escapeFormulae instanceof RegExp) {
515
+ _escapeFormulae = _config.escapeFormulae;
516
+ } else if (typeof _config.escapeFormulae === 'boolean' && _config.escapeFormulae) {
517
+ _escapeFormulae = /^[=+\-@\t\r].*$/;
518
+ }
519
+ }
520
+
521
+ /** The double for loop that iterates the data and writes out a CSV string including header row */
522
+ function serialize(fields, data, skipEmptyLines)
523
+ {
524
+ var csv = '';
525
+
526
+ if (typeof fields === 'string')
527
+ fields = JSON.parse(fields);
528
+ if (typeof data === 'string')
529
+ data = JSON.parse(data);
530
+
531
+ var hasHeader = Array.isArray(fields) && fields.length > 0;
532
+ var dataKeyedByField = !(Array.isArray(data[0]));
533
+
534
+ // If there a header row, write it first
535
+ if (hasHeader && _writeHeader)
536
+ {
537
+ for (var i = 0; i < fields.length; i++)
538
+ {
539
+ if (i > 0)
540
+ csv += _delimiter;
541
+ csv += safe(fields[i], i);
542
+ }
543
+ if (data.length > 0)
544
+ csv += _newline;
545
+ }
546
+
547
+ // Then write out the data
548
+ for (var row = 0; row < data.length; row++)
549
+ {
550
+ var maxCol = hasHeader ? fields.length : data[row].length;
551
+
552
+ var emptyLine = false;
553
+ var nullLine = hasHeader ? Object.keys(data[row]).length === 0 : data[row].length === 0;
554
+ if (skipEmptyLines && !hasHeader)
555
+ {
556
+ emptyLine = skipEmptyLines === 'greedy' ? data[row].join('').trim() === '' : data[row].length === 1 && data[row][0].length === 0;
557
+ }
558
+ if (skipEmptyLines === 'greedy' && hasHeader) {
559
+ var line = [];
560
+ for (var c = 0; c < maxCol; c++) {
561
+ var cx = dataKeyedByField ? fields[c] : c;
562
+ line.push(data[row][cx]);
563
+ }
564
+ emptyLine = line.join('').trim() === '';
565
+ }
566
+ if (!emptyLine)
567
+ {
568
+ for (var col = 0; col < maxCol; col++)
569
+ {
570
+ if (col > 0 && !nullLine)
571
+ csv += _delimiter;
572
+ var colIdx = hasHeader && dataKeyedByField ? fields[col] : col;
573
+ csv += safe(data[row][colIdx], col);
574
+ }
575
+ if (row < data.length - 1 && (!skipEmptyLines || (maxCol > 0 && !nullLine)))
576
+ {
577
+ csv += _newline;
578
+ }
579
+ }
580
+ }
581
+ return csv;
582
+ }
583
+
584
+ /** Encloses a value around quotes if needed (makes a value safe for CSV insertion) */
585
+ function safe(str, col)
586
+ {
587
+ if (typeof str === 'undefined' || str === null)
588
+ return '';
589
+
590
+ if (str.constructor === Date)
591
+ return JSON.stringify(str).slice(1, 25);
592
+
593
+ var needsQuotes = false;
594
+
595
+ if (_escapeFormulae && typeof str === "string" && _escapeFormulae.test(str)) {
596
+ str = "'" + str;
597
+ needsQuotes = true;
598
+ }
599
+
600
+ var escapedQuoteStr = str.toString().replace(quoteCharRegex, _escapedQuote);
601
+
602
+ needsQuotes = needsQuotes
603
+ || _quotes === true
604
+ || (typeof _quotes === 'function' && _quotes(str, col))
605
+ || (Array.isArray(_quotes) && _quotes[col])
606
+ || hasAny(escapedQuoteStr, Papa.BAD_DELIMITERS)
607
+ || escapedQuoteStr.indexOf(_delimiter) > -1
608
+ || escapedQuoteStr.charAt(0) === ' '
609
+ || escapedQuoteStr.charAt(escapedQuoteStr.length - 1) === ' ';
610
+
611
+ return needsQuotes ? _quoteChar + escapedQuoteStr + _quoteChar : escapedQuoteStr;
612
+ }
613
+
614
+ function hasAny(str, substrings)
615
+ {
616
+ for (var i = 0; i < substrings.length; i++)
617
+ if (str.indexOf(substrings[i]) > -1)
618
+ return true;
619
+ return false;
620
+ }
621
+ }
622
+
623
+
624
+ /** ChunkStreamer is the base prototype for various streamer implementations. */
625
+ function ChunkStreamer(config)
626
+ {
627
+ this._handle = null;
628
+ this._finished = false;
629
+ this._completed = false;
630
+ this._halted = false;
631
+ this._input = null;
632
+ this._baseIndex = 0;
633
+ this._partialLine = '';
634
+ this._rowCount = 0;
635
+ this._start = 0;
636
+ this._nextChunk = null;
637
+ this.isFirstChunk = true;
638
+ this._completeResults = {
639
+ data: [],
640
+ errors: [],
641
+ meta: {}
642
+ };
643
+ replaceConfig.call(this, config);
644
+
645
+ this.parseChunk = function(chunk, isFakeChunk)
646
+ {
647
+ // First chunk pre-processing
648
+ const skipFirstNLines = parseInt(this._config.skipFirstNLines) || 0;
649
+ if (this.isFirstChunk && skipFirstNLines > 0) {
650
+ let _newline = this._config.newline;
651
+ if (!_newline) {
652
+ const quoteChar = this._config.quoteChar || '"';
653
+ _newline = this._handle.guessLineEndings(chunk, quoteChar);
654
+ }
655
+ const splitChunk = chunk.split(_newline);
656
+ chunk = [...splitChunk.slice(skipFirstNLines)].join(_newline);
657
+ }
658
+ if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk))
659
+ {
660
+ var modifiedChunk = this._config.beforeFirstChunk(chunk);
661
+ if (modifiedChunk !== undefined)
662
+ chunk = modifiedChunk;
663
+ }
664
+ this.isFirstChunk = false;
665
+ this._halted = false;
666
+
667
+ // Rejoin the line we likely just split in two by chunking the file
668
+ var aggregate = this._partialLine + chunk;
669
+ this._partialLine = '';
670
+ var results = this._handle.parse(aggregate, this._baseIndex, !this._finished);
671
+
672
+ if (this._handle.paused() || this._handle.aborted()) {
673
+ this._halted = true;
674
+ return;
675
+ }
676
+
677
+ var lastIndex = results.meta.cursor;
678
+
679
+ if (!this._finished)
680
+ {
681
+ this._partialLine = aggregate.substring(lastIndex - this._baseIndex);
682
+ this._baseIndex = lastIndex;
683
+ }
684
+
685
+ if (results && results.data)
686
+ this._rowCount += results.data.length;
687
+
688
+ var finishedIncludingPreview = this._finished || (this._config.preview && this._rowCount >= this._config.preview);
689
+
690
+ if (IS_PAPA_WORKER)
691
+ {
692
+ global.postMessage({
693
+ results: results,
694
+ workerId: Papa.WORKER_ID,
695
+ finished: finishedIncludingPreview
696
+ });
697
+ }
698
+ else if (isFunction(this._config.chunk) && !isFakeChunk)
699
+ {
700
+ this._config.chunk(results, this._handle);
701
+ if (this._handle.paused() || this._handle.aborted()) {
702
+ this._halted = true;
703
+ return;
704
+ }
705
+ results = undefined;
706
+ this._completeResults = undefined;
707
+ }
708
+
709
+ if (!this._config.step && !this._config.chunk) {
710
+ this._completeResults.data = this._completeResults.data.concat(results.data);
711
+ this._completeResults.errors = this._completeResults.errors.concat(results.errors);
712
+ this._completeResults.meta = results.meta;
713
+ }
714
+
715
+ if (!this._completed && finishedIncludingPreview && isFunction(this._config.complete) && (!results || !results.meta.aborted)) {
716
+ this._config.complete(this._completeResults, this._input);
717
+ this._completed = true;
718
+ }
719
+
720
+ if (!finishedIncludingPreview && (!results || !results.meta.paused))
721
+ this._nextChunk();
722
+
723
+ return results;
724
+ };
725
+
726
+ this._sendError = function(error)
727
+ {
728
+ if (isFunction(this._config.error))
729
+ this._config.error(error);
730
+ else if (IS_PAPA_WORKER && this._config.error)
731
+ {
732
+ global.postMessage({
733
+ workerId: Papa.WORKER_ID,
734
+ error: error,
735
+ finished: false
736
+ });
737
+ }
738
+ };
739
+
740
+ function replaceConfig(config)
741
+ {
742
+ // Deep-copy the config so we can edit it
743
+ var configCopy = copy(config);
744
+ configCopy.chunkSize = parseInt(configCopy.chunkSize); // parseInt VERY important so we don't concatenate strings!
745
+ if (!config.step && !config.chunk)
746
+ configCopy.chunkSize = null; // disable Range header if not streaming; bad values break IIS - see issue #196
747
+ this._handle = new ParserHandle(configCopy);
748
+ this._handle.streamer = this;
749
+ this._config = configCopy; // persist the copy to the caller
750
+ }
751
+ }
752
+
753
+
754
+ function NetworkStreamer(config)
755
+ {
756
+ config = config || {};
757
+ if (!config.chunkSize)
758
+ config.chunkSize = Papa.RemoteChunkSize;
759
+ ChunkStreamer.call(this, config);
760
+
761
+ var xhr;
762
+
763
+ if (IS_WORKER)
764
+ {
765
+ this._nextChunk = function()
766
+ {
767
+ this._readChunk();
768
+ this._chunkLoaded();
769
+ };
770
+ }
771
+ else
772
+ {
773
+ this._nextChunk = function()
774
+ {
775
+ this._readChunk();
776
+ };
777
+ }
778
+
779
+ this.stream = function(url)
780
+ {
781
+ this._input = url;
782
+ this._nextChunk(); // Starts streaming
783
+ };
784
+
785
+ this._readChunk = function()
786
+ {
787
+ if (this._finished)
788
+ {
789
+ this._chunkLoaded();
790
+ return;
791
+ }
792
+
793
+ xhr = new XMLHttpRequest();
794
+
795
+ if (this._config.withCredentials)
796
+ {
797
+ xhr.withCredentials = this._config.withCredentials;
798
+ }
799
+
800
+ if (!IS_WORKER)
801
+ {
802
+ xhr.onload = bindFunction(this._chunkLoaded, this);
803
+ xhr.onerror = bindFunction(this._chunkError, this);
804
+ }
805
+
806
+ xhr.open(this._config.downloadRequestBody ? 'POST' : 'GET', this._input, !IS_WORKER);
807
+ // Headers can only be set when once the request state is OPENED
808
+ if (this._config.downloadRequestHeaders)
809
+ {
810
+ var headers = this._config.downloadRequestHeaders;
811
+
812
+ for (var headerName in headers)
813
+ {
814
+ xhr.setRequestHeader(headerName, headers[headerName]);
815
+ }
816
+ }
817
+
818
+ if (this._config.chunkSize)
819
+ {
820
+ var end = this._start + this._config.chunkSize - 1; // minus one because byte range is inclusive
821
+ xhr.setRequestHeader('Range', 'bytes=' + this._start + '-' + end);
822
+ }
823
+
824
+ try {
825
+ xhr.send(this._config.downloadRequestBody);
826
+ }
827
+ catch (err) {
828
+ this._chunkError(err.message);
829
+ }
830
+
831
+ if (IS_WORKER && xhr.status === 0)
832
+ this._chunkError();
833
+ };
834
+
835
+ this._chunkLoaded = function()
836
+ {
837
+ if (xhr.readyState !== 4)
838
+ return;
839
+
840
+ if (xhr.status < 200 || xhr.status >= 400)
841
+ {
842
+ this._chunkError();
843
+ return;
844
+ }
845
+
846
+ // Use chunckSize as it may be a diference on reponse lentgh due to characters with more than 1 byte
847
+ this._start += this._config.chunkSize ? this._config.chunkSize : xhr.responseText.length;
848
+ this._finished = !this._config.chunkSize || this._start >= getFileSize(xhr);
849
+ this.parseChunk(xhr.responseText);
850
+ };
851
+
852
+ this._chunkError = function(errorMessage)
853
+ {
854
+ var errorText = xhr.statusText || errorMessage;
855
+ this._sendError(new Error(errorText));
856
+ };
857
+
858
+ function getFileSize(xhr)
859
+ {
860
+ var contentRange = xhr.getResponseHeader('Content-Range');
861
+ if (contentRange === null) { // no content range, then finish!
862
+ return -1;
863
+ }
864
+ return parseInt(contentRange.substring(contentRange.lastIndexOf('/') + 1));
865
+ }
866
+ }
867
+ NetworkStreamer.prototype = Object.create(ChunkStreamer.prototype);
868
+ NetworkStreamer.prototype.constructor = NetworkStreamer;
869
+
870
+
871
+ function FileStreamer(config)
872
+ {
873
+ config = config || {};
874
+ if (!config.chunkSize)
875
+ config.chunkSize = Papa.LocalChunkSize;
876
+ ChunkStreamer.call(this, config);
877
+
878
+ var reader, slice;
879
+
880
+ // FileReader is better than FileReaderSync (even in worker) - see http://stackoverflow.com/q/24708649/1048862
881
+ // But Firefox is a pill, too - see issue #76: https://github.com/mholt/PapaParse/issues/76
882
+ var usingAsyncReader = typeof FileReader !== 'undefined'; // Safari doesn't consider it a function - see issue #105
883
+
884
+ this.stream = function(file)
885
+ {
886
+ this._input = file;
887
+ slice = file.slice || file.webkitSlice || file.mozSlice;
888
+
889
+ if (usingAsyncReader)
890
+ {
891
+ reader = new FileReader(); // Preferred method of reading files, even in workers
892
+ reader.onload = bindFunction(this._chunkLoaded, this);
893
+ reader.onerror = bindFunction(this._chunkError, this);
894
+ }
895
+ else
896
+ reader = new FileReaderSync(); // Hack for running in a web worker in Firefox
897
+
898
+ this._nextChunk(); // Starts streaming
899
+ };
900
+
901
+ this._nextChunk = function()
902
+ {
903
+ if (!this._finished && (!this._config.preview || this._rowCount < this._config.preview))
904
+ this._readChunk();
905
+ };
906
+
907
+ this._readChunk = function()
908
+ {
909
+ var input = this._input;
910
+ if (this._config.chunkSize)
911
+ {
912
+ var end = Math.min(this._start + this._config.chunkSize, this._input.size);
913
+ input = slice.call(input, this._start, end);
914
+ }
915
+ var txt = reader.readAsText(input, this._config.encoding);
916
+ if (!usingAsyncReader)
917
+ this._chunkLoaded({ target: { result: txt } }); // mimic the async signature
918
+ };
919
+
920
+ this._chunkLoaded = function(event)
921
+ {
922
+ // Very important to increment start each time before handling results
923
+ this._start += this._config.chunkSize;
924
+ this._finished = !this._config.chunkSize || this._start >= this._input.size;
925
+ this.parseChunk(event.target.result);
926
+ };
927
+
928
+ this._chunkError = function()
929
+ {
930
+ this._sendError(reader.error);
931
+ };
932
+
933
+ }
934
+ FileStreamer.prototype = Object.create(ChunkStreamer.prototype);
935
+ FileStreamer.prototype.constructor = FileStreamer;
936
+
937
+
938
+ function StringStreamer(config)
939
+ {
940
+ config = config || {};
941
+ ChunkStreamer.call(this, config);
942
+
943
+ var remaining;
944
+ this.stream = function(s)
945
+ {
946
+ remaining = s;
947
+ return this._nextChunk();
948
+ };
949
+ this._nextChunk = function()
950
+ {
951
+ if (this._finished) return;
952
+ var size = this._config.chunkSize;
953
+ var chunk;
954
+ if(size) {
955
+ chunk = remaining.substring(0, size);
956
+ remaining = remaining.substring(size);
957
+ } else {
958
+ chunk = remaining;
959
+ remaining = '';
960
+ }
961
+ this._finished = !remaining;
962
+ return this.parseChunk(chunk);
963
+ };
964
+ }
965
+ StringStreamer.prototype = Object.create(StringStreamer.prototype);
966
+ StringStreamer.prototype.constructor = StringStreamer;
967
+
968
+
969
+ function ReadableStreamStreamer(config)
970
+ {
971
+ config = config || {};
972
+
973
+ ChunkStreamer.call(this, config);
974
+
975
+ var queue = [];
976
+ var parseOnData = true;
977
+ var streamHasEnded = false;
978
+
979
+ this.pause = function()
980
+ {
981
+ ChunkStreamer.prototype.pause.apply(this, arguments);
982
+ this._input.pause();
983
+ };
984
+
985
+ this.resume = function()
986
+ {
987
+ ChunkStreamer.prototype.resume.apply(this, arguments);
988
+ this._input.resume();
989
+ };
990
+
991
+ this.stream = function(stream)
992
+ {
993
+ this._input = stream;
994
+
995
+ this._input.on('data', this._streamData);
996
+ this._input.on('end', this._streamEnd);
997
+ this._input.on('error', this._streamError);
998
+ };
999
+
1000
+ this._checkIsFinished = function()
1001
+ {
1002
+ if (streamHasEnded && queue.length === 1) {
1003
+ this._finished = true;
1004
+ }
1005
+ };
1006
+
1007
+ this._nextChunk = function()
1008
+ {
1009
+ this._checkIsFinished();
1010
+ if (queue.length)
1011
+ {
1012
+ this.parseChunk(queue.shift());
1013
+ }
1014
+ else
1015
+ {
1016
+ parseOnData = true;
1017
+ }
1018
+ };
1019
+
1020
+ this._streamData = bindFunction(function(chunk)
1021
+ {
1022
+ try
1023
+ {
1024
+ queue.push(typeof chunk === 'string' ? chunk : chunk.toString(this._config.encoding));
1025
+
1026
+ if (parseOnData)
1027
+ {
1028
+ parseOnData = false;
1029
+ this._checkIsFinished();
1030
+ this.parseChunk(queue.shift());
1031
+ }
1032
+ }
1033
+ catch (error)
1034
+ {
1035
+ this._streamError(error);
1036
+ }
1037
+ }, this);
1038
+
1039
+ this._streamError = bindFunction(function(error)
1040
+ {
1041
+ this._streamCleanUp();
1042
+ this._sendError(error);
1043
+ }, this);
1044
+
1045
+ this._streamEnd = bindFunction(function()
1046
+ {
1047
+ this._streamCleanUp();
1048
+ streamHasEnded = true;
1049
+ this._streamData('');
1050
+ }, this);
1051
+
1052
+ this._streamCleanUp = bindFunction(function()
1053
+ {
1054
+ this._input.removeListener('data', this._streamData);
1055
+ this._input.removeListener('end', this._streamEnd);
1056
+ this._input.removeListener('error', this._streamError);
1057
+ }, this);
1058
+ }
1059
+ ReadableStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
1060
+ ReadableStreamStreamer.prototype.constructor = ReadableStreamStreamer;
1061
+
1062
+
1063
+ function DuplexStreamStreamer(_config) {
1064
+ var Duplex = require$$0.Duplex;
1065
+ var config = copy(_config);
1066
+ var parseOnWrite = true;
1067
+ var writeStreamHasFinished = false;
1068
+ var parseCallbackQueue = [];
1069
+ var stream = null;
1070
+
1071
+ this._onCsvData = function(results)
1072
+ {
1073
+ var data = results.data;
1074
+ if (!stream.push(data) && !this._handle.paused()) {
1075
+ // the writeable consumer buffer has filled up
1076
+ // so we need to pause until more items
1077
+ // can be processed
1078
+ this._handle.pause();
1079
+ }
1080
+ };
1081
+
1082
+ this._onCsvComplete = function()
1083
+ {
1084
+ // node will finish the read stream when
1085
+ // null is pushed
1086
+ stream.push(null);
1087
+ };
1088
+
1089
+ config.step = bindFunction(this._onCsvData, this);
1090
+ config.complete = bindFunction(this._onCsvComplete, this);
1091
+ ChunkStreamer.call(this, config);
1092
+
1093
+ this._nextChunk = function()
1094
+ {
1095
+ if (writeStreamHasFinished && parseCallbackQueue.length === 1) {
1096
+ this._finished = true;
1097
+ }
1098
+ if (parseCallbackQueue.length) {
1099
+ parseCallbackQueue.shift()();
1100
+ } else {
1101
+ parseOnWrite = true;
1102
+ }
1103
+ };
1104
+
1105
+ this._addToParseQueue = function(chunk, callback)
1106
+ {
1107
+ // add to queue so that we can indicate
1108
+ // completion via callback
1109
+ // node will automatically pause the incoming stream
1110
+ // when too many items have been added without their
1111
+ // callback being invoked
1112
+ parseCallbackQueue.push(bindFunction(function() {
1113
+ this.parseChunk(typeof chunk === 'string' ? chunk : chunk.toString(config.encoding));
1114
+ if (isFunction(callback)) {
1115
+ return callback();
1116
+ }
1117
+ }, this));
1118
+ if (parseOnWrite) {
1119
+ parseOnWrite = false;
1120
+ this._nextChunk();
1121
+ }
1122
+ };
1123
+
1124
+ this._onRead = function()
1125
+ {
1126
+ if (this._handle.paused()) {
1127
+ // the writeable consumer can handle more data
1128
+ // so resume the chunk parsing
1129
+ this._handle.resume();
1130
+ }
1131
+ };
1132
+
1133
+ this._onWrite = function(chunk, encoding, callback)
1134
+ {
1135
+ this._addToParseQueue(chunk, callback);
1136
+ };
1137
+
1138
+ this._onWriteComplete = function()
1139
+ {
1140
+ writeStreamHasFinished = true;
1141
+ // have to write empty string
1142
+ // so parser knows its done
1143
+ this._addToParseQueue('');
1144
+ };
1145
+
1146
+ this.getStream = function()
1147
+ {
1148
+ return stream;
1149
+ };
1150
+ stream = new Duplex({
1151
+ readableObjectMode: true,
1152
+ decodeStrings: false,
1153
+ read: bindFunction(this._onRead, this),
1154
+ write: bindFunction(this._onWrite, this)
1155
+ });
1156
+ stream.once('finish', bindFunction(this._onWriteComplete, this));
1157
+ }
1158
+ if (typeof PAPA_BROWSER_CONTEXT === 'undefined') {
1159
+ DuplexStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
1160
+ DuplexStreamStreamer.prototype.constructor = DuplexStreamStreamer;
1161
+ }
1162
+
1163
+
1164
+ // Use one ParserHandle per entire CSV file or string
1165
+ function ParserHandle(_config)
1166
+ {
1167
+ // One goal is to minimize the use of regular expressions...
1168
+ var MAX_FLOAT = Math.pow(2, 53);
1169
+ var MIN_FLOAT = -MAX_FLOAT;
1170
+ var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/;
1171
+ 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)))$/;
1172
+ var self = this;
1173
+ var _stepCounter = 0; // Number of times step was called (number of rows parsed)
1174
+ var _rowCounter = 0; // Number of rows that have been parsed so far
1175
+ var _input; // The input being parsed
1176
+ var _parser; // The core parser being used
1177
+ var _paused = false; // Whether we are paused or not
1178
+ var _aborted = false; // Whether the parser has aborted or not
1179
+ var _delimiterError; // Temporary state between delimiter detection and processing results
1180
+ var _fields = []; // Fields are from the header row of the input, if there is one
1181
+ var _results = { // The last results returned from the parser
1182
+ data: [],
1183
+ errors: [],
1184
+ meta: {}
1185
+ };
1186
+
1187
+ if (isFunction(_config.step))
1188
+ {
1189
+ var userStep = _config.step;
1190
+ _config.step = function(results)
1191
+ {
1192
+ _results = results;
1193
+
1194
+ if (needsHeaderRow())
1195
+ processResults();
1196
+ else // only call user's step function after header row
1197
+ {
1198
+ processResults();
1199
+
1200
+ // It's possbile that this line was empty and there's no row here after all
1201
+ if (_results.data.length === 0)
1202
+ return;
1203
+
1204
+ _stepCounter += results.data.length;
1205
+ if (_config.preview && _stepCounter > _config.preview)
1206
+ _parser.abort();
1207
+ else {
1208
+ _results.data = _results.data[0];
1209
+ userStep(_results, self);
1210
+ }
1211
+ }
1212
+ };
1213
+ }
1214
+
1215
+ /**
1216
+ * Parses input. Most users won't need, and shouldn't mess with, the baseIndex
1217
+ * and ignoreLastRow parameters. They are used by streamers (wrapper functions)
1218
+ * when an input comes in multiple chunks, like from a file.
1219
+ */
1220
+ this.parse = function(input, baseIndex, ignoreLastRow)
1221
+ {
1222
+ var quoteChar = _config.quoteChar || '"';
1223
+ if (!_config.newline)
1224
+ _config.newline = this.guessLineEndings(input, quoteChar);
1225
+
1226
+ _delimiterError = false;
1227
+ if (!_config.delimiter)
1228
+ {
1229
+ var delimGuess = guessDelimiter(input, _config.newline, _config.skipEmptyLines, _config.comments, _config.delimitersToGuess);
1230
+ if (delimGuess.successful)
1231
+ _config.delimiter = delimGuess.bestDelimiter;
1232
+ else
1233
+ {
1234
+ _delimiterError = true; // add error after parsing (otherwise it would be overwritten)
1235
+ _config.delimiter = Papa.DefaultDelimiter;
1236
+ }
1237
+ _results.meta.delimiter = _config.delimiter;
1238
+ }
1239
+ else if(isFunction(_config.delimiter))
1240
+ {
1241
+ _config.delimiter = _config.delimiter(input);
1242
+ _results.meta.delimiter = _config.delimiter;
1243
+ }
1244
+
1245
+ var parserConfig = copy(_config);
1246
+ if (_config.preview && _config.header)
1247
+ parserConfig.preview++; // to compensate for header row
1248
+
1249
+ _input = input;
1250
+ _parser = new Parser(parserConfig);
1251
+ _results = _parser.parse(_input, baseIndex, ignoreLastRow);
1252
+ processResults();
1253
+ return _paused ? { meta: { paused: true } } : (_results || { meta: { paused: false } });
1254
+ };
1255
+
1256
+ this.paused = function()
1257
+ {
1258
+ return _paused;
1259
+ };
1260
+
1261
+ this.pause = function()
1262
+ {
1263
+ _paused = true;
1264
+ _parser.abort();
1265
+
1266
+ // If it is streaming via "chunking", the reader will start appending correctly already so no need to substring,
1267
+ // otherwise we can get duplicate content within a row
1268
+ _input = isFunction(_config.chunk) ? "" : _input.substring(_parser.getCharIndex());
1269
+ };
1270
+
1271
+ this.resume = function()
1272
+ {
1273
+ if(self.streamer._halted) {
1274
+ _paused = false;
1275
+ self.streamer.parseChunk(_input, true);
1276
+ } else {
1277
+ // Bugfix: #636 In case the processing hasn't halted yet
1278
+ // wait for it to halt in order to resume
1279
+ setTimeout(self.resume, 3);
1280
+ }
1281
+ };
1282
+
1283
+ this.aborted = function()
1284
+ {
1285
+ return _aborted;
1286
+ };
1287
+
1288
+ this.abort = function()
1289
+ {
1290
+ _aborted = true;
1291
+ _parser.abort();
1292
+ _results.meta.aborted = true;
1293
+ if (isFunction(_config.complete))
1294
+ _config.complete(_results);
1295
+ _input = '';
1296
+ };
1297
+
1298
+ this.guessLineEndings = function(input, quoteChar)
1299
+ {
1300
+ input = input.substring(0, 1024 * 1024); // max length 1 MB
1301
+ // Replace all the text inside quotes
1302
+ var re = new RegExp(escapeRegExp(quoteChar) + '([^]*?)' + escapeRegExp(quoteChar), 'gm');
1303
+ input = input.replace(re, '');
1304
+
1305
+ var r = input.split('\r');
1306
+
1307
+ var n = input.split('\n');
1308
+
1309
+ var nAppearsFirst = (n.length > 1 && n[0].length < r[0].length);
1310
+
1311
+ if (r.length === 1 || nAppearsFirst)
1312
+ return '\n';
1313
+
1314
+ var numWithN = 0;
1315
+ for (var i = 0; i < r.length; i++)
1316
+ {
1317
+ if (r[i][0] === '\n')
1318
+ numWithN++;
1319
+ }
1320
+
1321
+ return numWithN >= r.length / 2 ? '\r\n' : '\r';
1322
+ };
1323
+
1324
+ function testEmptyLine(s) {
1325
+ return _config.skipEmptyLines === 'greedy' ? s.join('').trim() === '' : s.length === 1 && s[0].length === 0;
1326
+ }
1327
+
1328
+ function testFloat(s) {
1329
+ if (FLOAT.test(s)) {
1330
+ var floatValue = parseFloat(s);
1331
+ if (floatValue > MIN_FLOAT && floatValue < MAX_FLOAT) {
1332
+ return true;
1333
+ }
1334
+ }
1335
+ return false;
1336
+ }
1337
+
1338
+ function processResults()
1339
+ {
1340
+ if (_results && _delimiterError)
1341
+ {
1342
+ addError('Delimiter', 'UndetectableDelimiter', 'Unable to auto-detect delimiting character; defaulted to \'' + Papa.DefaultDelimiter + '\'');
1343
+ _delimiterError = false;
1344
+ }
1345
+
1346
+ if (_config.skipEmptyLines)
1347
+ {
1348
+ _results.data = _results.data.filter(function(d) {
1349
+ return !testEmptyLine(d);
1350
+ });
1351
+ }
1352
+
1353
+ if (needsHeaderRow())
1354
+ fillHeaderFields();
1355
+
1356
+ return applyHeaderAndDynamicTypingAndTransformation();
1357
+ }
1358
+
1359
+ function needsHeaderRow()
1360
+ {
1361
+ return _config.header && _fields.length === 0;
1362
+ }
1363
+
1364
+ function fillHeaderFields()
1365
+ {
1366
+ if (!_results)
1367
+ return;
1368
+
1369
+ function addHeader(header, i)
1370
+ {
1371
+ if (isFunction(_config.transformHeader))
1372
+ header = _config.transformHeader(header, i);
1373
+
1374
+ _fields.push(header);
1375
+ }
1376
+
1377
+ if (Array.isArray(_results.data[0]))
1378
+ {
1379
+ for (var i = 0; needsHeaderRow() && i < _results.data.length; i++)
1380
+ _results.data[i].forEach(addHeader);
1381
+
1382
+ _results.data.splice(0, 1);
1383
+ }
1384
+ // if _results.data[0] is not an array, we are in a step where _results.data is the row.
1385
+ else
1386
+ _results.data.forEach(addHeader);
1387
+ }
1388
+
1389
+ function shouldApplyDynamicTyping(field) {
1390
+ // Cache function values to avoid calling it for each row
1391
+ if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) {
1392
+ _config.dynamicTyping[field] = _config.dynamicTypingFunction(field);
1393
+ }
1394
+ return (_config.dynamicTyping[field] || _config.dynamicTyping) === true;
1395
+ }
1396
+
1397
+ function parseDynamic(field, value)
1398
+ {
1399
+ if (shouldApplyDynamicTyping(field))
1400
+ {
1401
+ if (value === 'true' || value === 'TRUE')
1402
+ return true;
1403
+ else if (value === 'false' || value === 'FALSE')
1404
+ return false;
1405
+ else if (testFloat(value))
1406
+ return parseFloat(value);
1407
+ else if (ISO_DATE.test(value))
1408
+ return new Date(value);
1409
+ else
1410
+ return (value === '' ? null : value);
1411
+ }
1412
+ return value;
1413
+ }
1414
+
1415
+ function applyHeaderAndDynamicTypingAndTransformation()
1416
+ {
1417
+ if (!_results || (!_config.header && !_config.dynamicTyping && !_config.transform))
1418
+ return _results;
1419
+
1420
+ function processRow(rowSource, i)
1421
+ {
1422
+ var row = _config.header ? {} : [];
1423
+
1424
+ var j;
1425
+ for (j = 0; j < rowSource.length; j++)
1426
+ {
1427
+ var field = j;
1428
+ var value = rowSource[j];
1429
+
1430
+ if (_config.header)
1431
+ field = j >= _fields.length ? '__parsed_extra' : _fields[j];
1432
+
1433
+ if (_config.transform)
1434
+ value = _config.transform(value,field);
1435
+
1436
+ value = parseDynamic(field, value);
1437
+
1438
+ if (field === '__parsed_extra')
1439
+ {
1440
+ row[field] = row[field] || [];
1441
+ row[field].push(value);
1442
+ }
1443
+ else
1444
+ row[field] = value;
1445
+ }
1446
+
1447
+
1448
+ if (_config.header)
1449
+ {
1450
+ if (j > _fields.length)
1451
+ addError('FieldMismatch', 'TooManyFields', 'Too many fields: expected ' + _fields.length + ' fields but parsed ' + j, _rowCounter + i);
1452
+ else if (j < _fields.length)
1453
+ addError('FieldMismatch', 'TooFewFields', 'Too few fields: expected ' + _fields.length + ' fields but parsed ' + j, _rowCounter + i);
1454
+ }
1455
+
1456
+ return row;
1457
+ }
1458
+
1459
+ var incrementBy = 1;
1460
+ if (!_results.data.length || Array.isArray(_results.data[0]))
1461
+ {
1462
+ _results.data = _results.data.map(processRow);
1463
+ incrementBy = _results.data.length;
1464
+ }
1465
+ else
1466
+ _results.data = processRow(_results.data, 0);
1467
+
1468
+
1469
+ if (_config.header && _results.meta)
1470
+ _results.meta.fields = _fields;
1471
+
1472
+ _rowCounter += incrementBy;
1473
+ return _results;
1474
+ }
1475
+
1476
+ function guessDelimiter(input, newline, skipEmptyLines, comments, delimitersToGuess) {
1477
+ var bestDelim, bestDelta, fieldCountPrevRow, maxFieldCount;
1478
+
1479
+ delimitersToGuess = delimitersToGuess || [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP];
1480
+
1481
+ for (var i = 0; i < delimitersToGuess.length; i++) {
1482
+ var delim = delimitersToGuess[i];
1483
+ var delta = 0, avgFieldCount = 0, emptyLinesCount = 0;
1484
+ fieldCountPrevRow = undefined;
1485
+
1486
+ var preview = new Parser({
1487
+ comments: comments,
1488
+ delimiter: delim,
1489
+ newline: newline,
1490
+ preview: 10
1491
+ }).parse(input);
1492
+
1493
+ for (var j = 0; j < preview.data.length; j++) {
1494
+ if (skipEmptyLines && testEmptyLine(preview.data[j])) {
1495
+ emptyLinesCount++;
1496
+ continue;
1497
+ }
1498
+ var fieldCount = preview.data[j].length;
1499
+ avgFieldCount += fieldCount;
1500
+
1501
+ if (typeof fieldCountPrevRow === 'undefined') {
1502
+ fieldCountPrevRow = fieldCount;
1503
+ continue;
1504
+ }
1505
+ else if (fieldCount > 0) {
1506
+ delta += Math.abs(fieldCount - fieldCountPrevRow);
1507
+ fieldCountPrevRow = fieldCount;
1508
+ }
1509
+ }
1510
+
1511
+ if (preview.data.length > 0)
1512
+ avgFieldCount /= (preview.data.length - emptyLinesCount);
1513
+
1514
+ if ((typeof bestDelta === 'undefined' || delta <= bestDelta)
1515
+ && (typeof maxFieldCount === 'undefined' || avgFieldCount > maxFieldCount) && avgFieldCount > 1.99) {
1516
+ bestDelta = delta;
1517
+ bestDelim = delim;
1518
+ maxFieldCount = avgFieldCount;
1519
+ }
1520
+ }
1521
+
1522
+ _config.delimiter = bestDelim;
1523
+
1524
+ return {
1525
+ successful: !!bestDelim,
1526
+ bestDelimiter: bestDelim
1527
+ };
1528
+ }
1529
+
1530
+ function addError(type, code, msg, row)
1531
+ {
1532
+ var error = {
1533
+ type: type,
1534
+ code: code,
1535
+ message: msg
1536
+ };
1537
+ if(row !== undefined) {
1538
+ error.row = row;
1539
+ }
1540
+ _results.errors.push(error);
1541
+ }
1542
+ }
1543
+
1544
+ /** https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions */
1545
+ function escapeRegExp(string)
1546
+ {
1547
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
1548
+ }
1549
+
1550
+ /** The core parser implements speedy and correct CSV parsing */
1551
+ function Parser(config)
1552
+ {
1553
+ // Unpack the config object
1554
+ config = config || {};
1555
+ var delim = config.delimiter;
1556
+ var newline = config.newline;
1557
+ var comments = config.comments;
1558
+ var step = config.step;
1559
+ var preview = config.preview;
1560
+ var fastMode = config.fastMode;
1561
+ var quoteChar;
1562
+ var renamedHeaders = null;
1563
+ var headerParsed = false;
1564
+
1565
+ if (config.quoteChar === undefined || config.quoteChar === null) {
1566
+ quoteChar = '"';
1567
+ } else {
1568
+ quoteChar = config.quoteChar;
1569
+ }
1570
+ var escapeChar = quoteChar;
1571
+ if (config.escapeChar !== undefined) {
1572
+ escapeChar = config.escapeChar;
1573
+ }
1574
+
1575
+ // Delimiter must be valid
1576
+ if (typeof delim !== 'string'
1577
+ || Papa.BAD_DELIMITERS.indexOf(delim) > -1)
1578
+ delim = ',';
1579
+
1580
+ // Comment character must be valid
1581
+ if (comments === delim)
1582
+ throw new Error('Comment character same as delimiter');
1583
+ else if (comments === true)
1584
+ comments = '#';
1585
+ else if (typeof comments !== 'string'
1586
+ || Papa.BAD_DELIMITERS.indexOf(comments) > -1)
1587
+ comments = false;
1588
+
1589
+ // Newline must be valid: \r, \n, or \r\n
1590
+ if (newline !== '\n' && newline !== '\r' && newline !== '\r\n')
1591
+ newline = '\n';
1592
+
1593
+ // We're gonna need these at the Parser scope
1594
+ var cursor = 0;
1595
+ var aborted = false;
1596
+
1597
+ this.parse = function(input, baseIndex, ignoreLastRow)
1598
+ {
1599
+ // For some reason, in Chrome, this speeds things up (!?)
1600
+ if (typeof input !== 'string')
1601
+ throw new Error('Input must be a string');
1602
+
1603
+ // We don't need to compute some of these every time parse() is called,
1604
+ // but having them in a more local scope seems to perform better
1605
+ var inputLen = input.length,
1606
+ delimLen = delim.length,
1607
+ newlineLen = newline.length,
1608
+ commentsLen = comments.length;
1609
+ var stepIsFunction = isFunction(step);
1610
+
1611
+ // Establish starting state
1612
+ cursor = 0;
1613
+ var data = [], errors = [], row = [], lastCursor = 0;
1614
+
1615
+ if (!input)
1616
+ return returnable();
1617
+
1618
+ if (fastMode || (fastMode !== false && input.indexOf(quoteChar) === -1))
1619
+ {
1620
+ var rows = input.split(newline);
1621
+ for (var i = 0; i < rows.length; i++)
1622
+ {
1623
+ row = rows[i];
1624
+ cursor += row.length;
1625
+
1626
+ if (i !== rows.length - 1)
1627
+ cursor += newline.length;
1628
+ else if (ignoreLastRow)
1629
+ return returnable();
1630
+ if (comments && row.substring(0, commentsLen) === comments)
1631
+ continue;
1632
+ if (stepIsFunction)
1633
+ {
1634
+ data = [];
1635
+ pushRow(row.split(delim));
1636
+ doStep();
1637
+ if (aborted)
1638
+ return returnable();
1639
+ }
1640
+ else
1641
+ pushRow(row.split(delim));
1642
+ if (preview && i >= preview)
1643
+ {
1644
+ data = data.slice(0, preview);
1645
+ return returnable(true);
1646
+ }
1647
+ }
1648
+ return returnable();
1649
+ }
1650
+
1651
+ var nextDelim = input.indexOf(delim, cursor);
1652
+ var nextNewline = input.indexOf(newline, cursor);
1653
+ var quoteCharRegex = new RegExp(escapeRegExp(escapeChar) + escapeRegExp(quoteChar), 'g');
1654
+ var quoteSearch = input.indexOf(quoteChar, cursor);
1655
+
1656
+ // Parser loop
1657
+ for (;;)
1658
+ {
1659
+ // Field has opening quote
1660
+ if (input[cursor] === quoteChar)
1661
+ {
1662
+ // Start our search for the closing quote where the cursor is
1663
+ quoteSearch = cursor;
1664
+
1665
+ // Skip the opening quote
1666
+ cursor++;
1667
+
1668
+ for (;;)
1669
+ {
1670
+ // Find closing quote
1671
+ quoteSearch = input.indexOf(quoteChar, quoteSearch + 1);
1672
+
1673
+ //No other quotes are found - no other delimiters
1674
+ if (quoteSearch === -1)
1675
+ {
1676
+ if (!ignoreLastRow) {
1677
+ // No closing quote... what a pity
1678
+ errors.push({
1679
+ type: 'Quotes',
1680
+ code: 'MissingQuotes',
1681
+ message: 'Quoted field unterminated',
1682
+ row: data.length, // row has yet to be inserted
1683
+ index: cursor
1684
+ });
1685
+ }
1686
+ return finish();
1687
+ }
1688
+
1689
+ // Closing quote at EOF
1690
+ if (quoteSearch === inputLen - 1)
1691
+ {
1692
+ var value = input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar);
1693
+ return finish(value);
1694
+ }
1695
+
1696
+ // If this quote is escaped, it's part of the data; skip it
1697
+ // If the quote character is the escape character, then check if the next character is the escape character
1698
+ if (quoteChar === escapeChar && input[quoteSearch + 1] === escapeChar)
1699
+ {
1700
+ quoteSearch++;
1701
+ continue;
1702
+ }
1703
+
1704
+ // If the quote character is not the escape character, then check if the previous character was the escape character
1705
+ if (quoteChar !== escapeChar && quoteSearch !== 0 && input[quoteSearch - 1] === escapeChar)
1706
+ {
1707
+ continue;
1708
+ }
1709
+
1710
+ if(nextDelim !== -1 && nextDelim < (quoteSearch + 1)) {
1711
+ nextDelim = input.indexOf(delim, (quoteSearch + 1));
1712
+ }
1713
+ if(nextNewline !== -1 && nextNewline < (quoteSearch + 1)) {
1714
+ nextNewline = input.indexOf(newline, (quoteSearch + 1));
1715
+ }
1716
+ // Check up to nextDelim or nextNewline, whichever is closest
1717
+ var checkUpTo = nextNewline === -1 ? nextDelim : Math.min(nextDelim, nextNewline);
1718
+ var spacesBetweenQuoteAndDelimiter = extraSpaces(checkUpTo);
1719
+
1720
+ // Closing quote followed by delimiter or 'unnecessary spaces + delimiter'
1721
+ if (input.substr(quoteSearch + 1 + spacesBetweenQuoteAndDelimiter, delimLen) === delim)
1722
+ {
1723
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
1724
+ cursor = quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen;
1725
+
1726
+ // If char after following delimiter is not quoteChar, we find next quote char position
1727
+ if (input[quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen] !== quoteChar)
1728
+ {
1729
+ quoteSearch = input.indexOf(quoteChar, cursor);
1730
+ }
1731
+ nextDelim = input.indexOf(delim, cursor);
1732
+ nextNewline = input.indexOf(newline, cursor);
1733
+ break;
1734
+ }
1735
+
1736
+ var spacesBetweenQuoteAndNewLine = extraSpaces(nextNewline);
1737
+
1738
+ // Closing quote followed by newline or 'unnecessary spaces + newLine'
1739
+ if (input.substring(quoteSearch + 1 + spacesBetweenQuoteAndNewLine, quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen) === newline)
1740
+ {
1741
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
1742
+ saveRow(quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen);
1743
+ nextDelim = input.indexOf(delim, cursor); // because we may have skipped the nextDelim in the quoted field
1744
+ quoteSearch = input.indexOf(quoteChar, cursor); // we search for first quote in next line
1745
+
1746
+ if (stepIsFunction)
1747
+ {
1748
+ doStep();
1749
+ if (aborted)
1750
+ return returnable();
1751
+ }
1752
+
1753
+ if (preview && data.length >= preview)
1754
+ return returnable(true);
1755
+
1756
+ break;
1757
+ }
1758
+
1759
+
1760
+ // Checks for valid closing quotes are complete (escaped quotes or quote followed by EOF/delimiter/newline) -- assume these quotes are part of an invalid text string
1761
+ errors.push({
1762
+ type: 'Quotes',
1763
+ code: 'InvalidQuotes',
1764
+ message: 'Trailing quote on quoted field is malformed',
1765
+ row: data.length, // row has yet to be inserted
1766
+ index: cursor
1767
+ });
1768
+
1769
+ quoteSearch++;
1770
+ continue;
1771
+
1772
+ }
1773
+
1774
+ continue;
1775
+ }
1776
+
1777
+ // Comment found at start of new line
1778
+ if (comments && row.length === 0 && input.substring(cursor, cursor + commentsLen) === comments)
1779
+ {
1780
+ if (nextNewline === -1) // Comment ends at EOF
1781
+ return returnable();
1782
+ cursor = nextNewline + newlineLen;
1783
+ nextNewline = input.indexOf(newline, cursor);
1784
+ nextDelim = input.indexOf(delim, cursor);
1785
+ continue;
1786
+ }
1787
+
1788
+ // Next delimiter comes before next newline, so we've reached end of field
1789
+ if (nextDelim !== -1 && (nextDelim < nextNewline || nextNewline === -1))
1790
+ {
1791
+ row.push(input.substring(cursor, nextDelim));
1792
+ cursor = nextDelim + delimLen;
1793
+ // we look for next delimiter char
1794
+ nextDelim = input.indexOf(delim, cursor);
1795
+ continue;
1796
+ }
1797
+
1798
+ // End of row
1799
+ if (nextNewline !== -1)
1800
+ {
1801
+ row.push(input.substring(cursor, nextNewline));
1802
+ saveRow(nextNewline + newlineLen);
1803
+
1804
+ if (stepIsFunction)
1805
+ {
1806
+ doStep();
1807
+ if (aborted)
1808
+ return returnable();
1809
+ }
1810
+
1811
+ if (preview && data.length >= preview)
1812
+ return returnable(true);
1813
+
1814
+ continue;
1815
+ }
1816
+
1817
+ break;
1818
+ }
1819
+
1820
+ return finish();
1821
+
1822
+
1823
+ function pushRow(row)
1824
+ {
1825
+ data.push(row);
1826
+ lastCursor = cursor;
1827
+ }
1828
+
1829
+ /**
1830
+ * checks if there are extra spaces after closing quote and given index without any text
1831
+ * if Yes, returns the number of spaces
1832
+ */
1833
+ function extraSpaces(index) {
1834
+ var spaceLength = 0;
1835
+ if (index !== -1) {
1836
+ var textBetweenClosingQuoteAndIndex = input.substring(quoteSearch + 1, index);
1837
+ if (textBetweenClosingQuoteAndIndex && textBetweenClosingQuoteAndIndex.trim() === '') {
1838
+ spaceLength = textBetweenClosingQuoteAndIndex.length;
1839
+ }
1840
+ }
1841
+ return spaceLength;
1842
+ }
1843
+
1844
+ /**
1845
+ * Appends the remaining input from cursor to the end into
1846
+ * row, saves the row, calls step, and returns the results.
1847
+ */
1848
+ function finish(value)
1849
+ {
1850
+ if (ignoreLastRow)
1851
+ return returnable();
1852
+ if (typeof value === 'undefined')
1853
+ value = input.substring(cursor);
1854
+ row.push(value);
1855
+ cursor = inputLen; // important in case parsing is paused
1856
+ pushRow(row);
1857
+ if (stepIsFunction)
1858
+ doStep();
1859
+ return returnable();
1860
+ }
1861
+
1862
+ /**
1863
+ * Appends the current row to the results. It sets the cursor
1864
+ * to newCursor and finds the nextNewline. The caller should
1865
+ * take care to execute user's step function and check for
1866
+ * preview and end parsing if necessary.
1867
+ */
1868
+ function saveRow(newCursor)
1869
+ {
1870
+ cursor = newCursor;
1871
+ pushRow(row);
1872
+ row = [];
1873
+ nextNewline = input.indexOf(newline, cursor);
1874
+ }
1875
+
1876
+ /** Returns an object with the results, errors, and meta. */
1877
+ function returnable(stopped)
1878
+ {
1879
+ if (config.header && !baseIndex && data.length && !headerParsed)
1880
+ {
1881
+ const result = data[0];
1882
+ const headerCount = Object.create(null); // To track the count of each base header
1883
+ const usedHeaders = new Set(result); // To track used headers and avoid duplicates
1884
+ let duplicateHeaders = false;
1885
+
1886
+ for (let i = 0; i < result.length; i++) {
1887
+ let header = result[i];
1888
+ if (isFunction(config.transformHeader))
1889
+ header = config.transformHeader(header, i);
1890
+
1891
+ if (!headerCount[header]) {
1892
+ headerCount[header] = 1;
1893
+ result[i] = header;
1894
+ } else {
1895
+ let newHeader;
1896
+ let suffixCount = headerCount[header];
1897
+
1898
+ // Find a unique new header
1899
+ do {
1900
+ newHeader = `${header}_${suffixCount}`;
1901
+ suffixCount++;
1902
+ } while (usedHeaders.has(newHeader));
1903
+
1904
+ usedHeaders.add(newHeader); // Mark this new Header as used
1905
+ result[i] = newHeader;
1906
+ headerCount[header]++;
1907
+ duplicateHeaders = true;
1908
+ if (renamedHeaders === null) {
1909
+ renamedHeaders = {};
1910
+ }
1911
+ renamedHeaders[newHeader] = header;
1912
+ }
1913
+
1914
+ usedHeaders.add(header); // Ensure the original header is marked as used
1915
+ }
1916
+ if (duplicateHeaders) {
1917
+ console.warn('Duplicate headers found and renamed.');
1918
+ }
1919
+ headerParsed = true;
1920
+ }
1921
+ return {
1922
+ data: data,
1923
+ errors: errors,
1924
+ meta: {
1925
+ delimiter: delim,
1926
+ linebreak: newline,
1927
+ aborted: aborted,
1928
+ truncated: !!stopped,
1929
+ cursor: lastCursor + (baseIndex || 0),
1930
+ renamedHeaders: renamedHeaders
1931
+ }
1932
+ };
1933
+ }
1934
+
1935
+ /** Executes the user's step function and resets data & errors. */
1936
+ function doStep()
1937
+ {
1938
+ step(returnable());
1939
+ data = [];
1940
+ errors = [];
1941
+ }
1942
+ };
1943
+
1944
+ /** Sets the abort flag */
1945
+ this.abort = function()
1946
+ {
1947
+ aborted = true;
1948
+ };
1949
+
1950
+ /** Gets the cursor position */
1951
+ this.getCharIndex = function()
1952
+ {
1953
+ return cursor;
1954
+ };
1955
+ }
1956
+
1957
+
1958
+ function newWorker()
1959
+ {
1960
+ if (!Papa.WORKERS_SUPPORTED)
1961
+ return false;
1962
+
1963
+ var workerUrl = getWorkerBlob();
1964
+ var w = new global.Worker(workerUrl);
1965
+ w.onmessage = mainThreadReceivedMessage;
1966
+ w.id = workerIdCounter++;
1967
+ workers[w.id] = w;
1968
+ return w;
1969
+ }
1970
+
1971
+ /** Callback when main thread receives a message */
1972
+ function mainThreadReceivedMessage(e)
1973
+ {
1974
+ var msg = e.data;
1975
+ var worker = workers[msg.workerId];
1976
+ var aborted = false;
1977
+
1978
+ if (msg.error)
1979
+ worker.userError(msg.error, msg.file);
1980
+ else if (msg.results && msg.results.data)
1981
+ {
1982
+ var abort = function() {
1983
+ aborted = true;
1984
+ completeWorker(msg.workerId, { data: [], errors: [], meta: { aborted: true } });
1985
+ };
1986
+
1987
+ var handle = {
1988
+ abort: abort,
1989
+ pause: notImplemented,
1990
+ resume: notImplemented
1991
+ };
1992
+
1993
+ if (isFunction(worker.userStep))
1994
+ {
1995
+ for (var i = 0; i < msg.results.data.length; i++)
1996
+ {
1997
+ worker.userStep({
1998
+ data: msg.results.data[i],
1999
+ errors: msg.results.errors,
2000
+ meta: msg.results.meta
2001
+ }, handle);
2002
+ if (aborted)
2003
+ break;
2004
+ }
2005
+ delete msg.results; // free memory ASAP
2006
+ }
2007
+ else if (isFunction(worker.userChunk))
2008
+ {
2009
+ worker.userChunk(msg.results, handle, msg.file);
2010
+ delete msg.results;
2011
+ }
2012
+ }
2013
+
2014
+ if (msg.finished && !aborted)
2015
+ completeWorker(msg.workerId, msg.results);
2016
+ }
2017
+
2018
+ function completeWorker(workerId, results) {
2019
+ var worker = workers[workerId];
2020
+ if (isFunction(worker.userComplete))
2021
+ worker.userComplete(results);
2022
+ worker.terminate();
2023
+ delete workers[workerId];
2024
+ }
2025
+
2026
+ function notImplemented() {
2027
+ throw new Error('Not implemented.');
2028
+ }
2029
+
2030
+ /** Callback when worker thread receives a message */
2031
+ function workerThreadReceivedMessage(e)
2032
+ {
2033
+ var msg = e.data;
2034
+
2035
+ if (typeof Papa.WORKER_ID === 'undefined' && msg)
2036
+ Papa.WORKER_ID = msg.workerId;
2037
+
2038
+ if (typeof msg.input === 'string')
2039
+ {
2040
+ global.postMessage({
2041
+ workerId: Papa.WORKER_ID,
2042
+ results: Papa.parse(msg.input, msg.config),
2043
+ finished: true
2044
+ });
2045
+ }
2046
+ else if ((global.File && msg.input instanceof File) || msg.input instanceof Object) // thank you, Safari (see issue #106)
2047
+ {
2048
+ var results = Papa.parse(msg.input, msg.config);
2049
+ if (results)
2050
+ global.postMessage({
2051
+ workerId: Papa.WORKER_ID,
2052
+ results: results,
2053
+ finished: true
2054
+ });
2055
+ }
2056
+ }
2057
+
2058
+ /** Makes a deep copy of an array or object (mostly) */
2059
+ function copy(obj)
2060
+ {
2061
+ if (typeof obj !== 'object' || obj === null)
2062
+ return obj;
2063
+ var cpy = Array.isArray(obj) ? [] : {};
2064
+ for (var key in obj)
2065
+ cpy[key] = copy(obj[key]);
2066
+ return cpy;
2067
+ }
2068
+
2069
+ function bindFunction(f, self)
2070
+ {
2071
+ return function() { f.apply(self, arguments); };
2072
+ }
2073
+ function isFunction(func)
2074
+ {
2075
+ return typeof func === 'function';
2076
+ }
2077
+
2078
+ return Papa;
2079
+ }));
2080
+ } (papaparse));
2081
+
2082
+ var papaparseExports = papaparse.exports;
2083
+ var Papa = /*@__PURE__*/getDefaultExportFromCjs(papaparseExports);
2084
+
2085
+ var EMAIL_NOTIFICATIONS_BASE_URL = "neeto_email_notifications/email_notification";
2086
+ var RESET_EMAIL_NOTIFICATIONS_TO_DEFAULT_URL = "".concat(EMAIL_NOTIFICATIONS_BASE_URL, "/reset_to_default");
2087
+
2088
+ var fetch = function fetch(params) {
2089
+ return axios.get(EMAIL_NOTIFICATIONS_BASE_URL, {
2090
+ params: params
2091
+ });
2092
+ };
2093
+ var update = function update(payload) {
2094
+ return axios.put(EMAIL_NOTIFICATIONS_BASE_URL, payload);
2095
+ };
2096
+ var resetToDefault = function resetToDefault(params) {
2097
+ return axios.post(RESET_EMAIL_NOTIFICATIONS_TO_DEFAULT_URL, params);
2098
+ };
2099
+ var emailNotificationsApi = {
2100
+ fetch: fetch,
2101
+ update: update,
2102
+ resetToDefault: resetToDefault
2103
+ };
2104
+
2105
+ var QUERY_KEYS = {
2106
+ NEETO_EMAIL_NOTIFICATIONS: "neeto-email-notifications"
2107
+ };
2108
+
2109
+ var useFetchEmailNotifications = function useFetchEmailNotifications(params) {
2110
+ return useQuery({
2111
+ queryKey: [QUERY_KEYS.NEETO_EMAIL_NOTIFICATIONS, params["notificationHolderId"], params["customFields"]],
2112
+ queryFn: function queryFn() {
2113
+ return emailNotificationsApi.fetch(params);
2114
+ },
2115
+ staleTime: DEFAULT_STALE_TIME,
2116
+ select: prop("emailNotification"),
2117
+ enabled: isNotEmpty(params)
2118
+ });
2119
+ };
2120
+ var useUpdateEmailNotification = function useUpdateEmailNotification() {
2121
+ return useMutationWithInvalidation(function (params) {
2122
+ return emailNotificationsApi.update(params);
2123
+ }, {
2124
+ keysToInvalidate: [function (_, _ref) {
2125
+ var notificationHolderId = _ref.notificationHolderId;
2126
+ return [QUERY_KEYS.NEETO_EMAIL_NOTIFICATIONS, notificationHolderId];
2127
+ }]
2128
+ });
2129
+ };
2130
+ var useResetEmailNotificationToDefault = function useResetEmailNotificationToDefault() {
2131
+ return useMutationWithInvalidation(emailNotificationsApi.resetToDefault, {
2132
+ keysToInvalidate: [function (_, _ref2) {
2133
+ var notificationHolderId = _ref2.notificationHolderId,
2134
+ customFields = _ref2.customFields;
2135
+ return [QUERY_KEYS.NEETO_EMAIL_NOTIFICATIONS, notificationHolderId, customFields];
2136
+ }]
2137
+ });
2138
+ };
2139
+
2140
+ export { PropTypes as P, SvgAvatarPlaceholder as S, Papa as a, useUpdateEmailNotification as b, useResetEmailNotificationToDefault as c, useFetchEmailNotifications as u };
2141
+ //# sourceMappingURL=emailNotificationApi-rMt-NHkm.js.map