@fleox-agent-crm/agentcrm 0.0.0-stage → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +143 -0
  2. package/README.md +223 -2
  3. package/changelog.json +76 -0
  4. package/dist/admin/admin-files.json +26 -0
  5. package/dist/admin/assets/chartsImpl-B45AAqnr.js +91 -0
  6. package/dist/admin/assets/firebase-C1x_l9P9.js +2 -0
  7. package/dist/admin/assets/gitJson-CAUSxl8d.js +3 -0
  8. package/dist/admin/assets/index-ChFauO8y.js +1181 -0
  9. package/dist/admin/assets/index-TcjySLVg.css +1 -0
  10. package/dist/admin/assets/index.esm-BFc7vwnl.js +400 -0
  11. package/dist/admin/assets/index.esm-CtEQZRb1.js +1651 -0
  12. package/dist/admin/assets/index.esm-Dum0J07z.js +16 -0
  13. package/dist/admin/assets/index.esm2017-EOzKbpUS.js +390 -0
  14. package/dist/admin/assets/lucide-react.min--rznIkmQ.js +6 -0
  15. package/dist/admin/assets/sdk-DgzLACmL.js +1717 -0
  16. package/dist/admin/config.js +3 -0
  17. package/dist/admin/favicon.svg +1 -0
  18. package/dist/admin/index.html +139 -0
  19. package/dist/admin/runtime/agentcrm-runtime.js +104 -0
  20. package/dist/admin/runtime/lucide-react.js +791 -0
  21. package/dist/admin/runtime/react-dom-client.js +17 -0
  22. package/dist/admin/runtime/react-dom.js +20 -0
  23. package/dist/admin/runtime/react-i18next.js +19 -0
  24. package/dist/admin/runtime/react-jsx-runtime.js +17 -0
  25. package/dist/admin/runtime/react.js +22 -0
  26. package/dist/agent/agentcrm.mjs +4057 -0
  27. package/dist/agent/chunks/_commonjsHelpers-ClciMIcB.mjs +14 -0
  28. package/dist/agent/chunks/activities-Cj_SIOay.mjs +227 -0
  29. package/dist/agent/chunks/api-Cz0Ubj-B.mjs +98 -0
  30. package/dist/agent/chunks/appearance-BloHbiLA.mjs +174 -0
  31. package/dist/agent/chunks/automations-DwWruxmu.mjs +698 -0
  32. package/dist/agent/chunks/backup-W3CjgkAJ.mjs +116 -0
  33. package/dist/agent/chunks/batch-CVETiJj5.mjs +142 -0
  34. package/dist/agent/chunks/compact-BGHI92tm.mjs +69 -0
  35. package/dist/agent/chunks/context-CxFfqS4D.mjs +65 -0
  36. package/dist/agent/chunks/core-Dy7vY9H6.mjs +255 -0
  37. package/dist/agent/chunks/dedupe-BepmsaHv.mjs +123 -0
  38. package/dist/agent/chunks/encoding-C9MzdP95.mjs +36 -0
  39. package/dist/agent/chunks/exportCsv-C6e6XEmB.mjs +130 -0
  40. package/dist/agent/chunks/extCheck-GgHG1dYB.mjs +200 -0
  41. package/dist/agent/chunks/extPackage-DuZ6GZhp.mjs +115 -0
  42. package/dist/agent/chunks/extScaffold-Aqyjf1nr.mjs +320 -0
  43. package/dist/agent/chunks/extensionActions-D2HtpQz4.mjs +48 -0
  44. package/dist/agent/chunks/extensions-Bp72uZ9a.mjs +164 -0
  45. package/dist/agent/chunks/featureRegistry-DSsZbhrh.mjs +149 -0
  46. package/dist/agent/chunks/fields-B0bitgmr.mjs +476 -0
  47. package/dist/agent/chunks/files-CjsPJSR6.mjs +158 -0
  48. package/dist/agent/chunks/files-D1daDgY0.mjs +367 -0
  49. package/dist/agent/chunks/firebase-DxGVQV9E.mjs +454 -0
  50. package/dist/agent/chunks/firebaseRules-iori-s7U.mjs +221 -0
  51. package/dist/agent/chunks/forms-BfuWaQjA.mjs +847 -0
  52. package/dist/agent/chunks/gitJson-fjr8mcHe.mjs +528 -0
  53. package/dist/agent/chunks/hosting-Bme7LxPc.mjs +144 -0
  54. package/dist/agent/chunks/http-Bk9ICb7I.mjs +127 -0
  55. package/dist/agent/chunks/ids-CvnmrMJX.mjs +59 -0
  56. package/dist/agent/chunks/ids-u-noYcy5.mjs +14 -0
  57. package/dist/agent/chunks/importCsv-LVmMTaWU.mjs +334 -0
  58. package/dist/agent/chunks/index-B-4W0-P4.mjs +535 -0
  59. package/dist/agent/chunks/index-BM8qeGOb.mjs +2489 -0
  60. package/dist/agent/chunks/index-Bnmav-Oh.mjs +311 -0
  61. package/dist/agent/chunks/index-CRkw3_iF.mjs +147 -0
  62. package/dist/agent/chunks/index-CWrrF1wl.mjs +111 -0
  63. package/dist/agent/chunks/index-DUSdTBkz.mjs +2988 -0
  64. package/dist/agent/chunks/index-RCmo-uld.mjs +26 -0
  65. package/dist/agent/chunks/index-w03ReRs4.mjs +9780 -0
  66. package/dist/agent/chunks/install-CbpD_7gd.mjs +188 -0
  67. package/dist/agent/chunks/jsx-runtime-Ca2uwGDr.mjs +76 -0
  68. package/dist/agent/chunks/loader-MPD9iAvh.mjs +184 -0
  69. package/dist/agent/chunks/lucide-react.min-Bt3gtepY.mjs +64 -0
  70. package/dist/agent/chunks/memory-WNR3VHUJ.mjs +56 -0
  71. package/dist/agent/chunks/migrate-CsClnnN8.mjs +182 -0
  72. package/dist/agent/chunks/modules-clWdE-K2.mjs +202 -0
  73. package/dist/agent/chunks/nodeImport-ylfRDvqt.mjs +38 -0
  74. package/dist/agent/chunks/package-B7mI6HGi.mjs +194 -0
  75. package/dist/agent/chunks/papaparse-Df7i1dHr.mjs +1309 -0
  76. package/dist/agent/chunks/pipelines-BAKpPk1w.mjs +234 -0
  77. package/dist/agent/chunks/plan-BmTat6-T.mjs +254 -0
  78. package/dist/agent/chunks/pluginRegistry-DyHtlkcr.mjs +83 -0
  79. package/dist/agent/chunks/query-C5nJB_3C.mjs +192 -0
  80. package/dist/agent/chunks/records-DcHFelq5.mjs +2195 -0
  81. package/dist/agent/chunks/registry-COfJrSmg.mjs +182 -0
  82. package/dist/agent/chunks/registry-DijAKZ24.mjs +431 -0
  83. package/dist/agent/chunks/relations-B9TynBmA.mjs +191 -0
  84. package/dist/agent/chunks/reports-BACHGccj.mjs +189 -0
  85. package/dist/agent/chunks/runtime-C0Xf0Axi.mjs +14873 -0
  86. package/dist/agent/chunks/runtimeConfig-CCOFg1RM.mjs +250 -0
  87. package/dist/agent/chunks/s3-Dz50-NuA.mjs +903 -0
  88. package/dist/agent/chunks/schema-C4lSslXv.mjs +373 -0
  89. package/dist/agent/chunks/schema-DnLj8dUO.mjs +213 -0
  90. package/dist/agent/chunks/sdk-whvfg786.mjs +43644 -0
  91. package/dist/agent/chunks/seed-6MRmQQBR.mjs +541 -0
  92. package/dist/agent/chunks/server-DC3t8r30.mjs +242 -0
  93. package/dist/agent/chunks/settings-Di8nzNEL.mjs +111 -0
  94. package/dist/agent/chunks/standardObjects-CheqfDqa.mjs +243 -0
  95. package/dist/agent/chunks/stats-BfuLWhVV.mjs +51 -0
  96. package/dist/agent/chunks/store-5gqRSKXg.mjs +122 -0
  97. package/dist/agent/chunks/themes-DPZFv3yc.mjs +43 -0
  98. package/dist/agent/chunks/tools-iSH-yMpl.mjs +884 -0
  99. package/dist/agent/chunks/types-BOy9PUl7.mjs +44 -0
  100. package/dist/agent/chunks/users-DI1BvS0f.mjs +107 -0
  101. package/dist/agent/chunks/utils-DmI8FtXP.mjs +83 -0
  102. package/dist/agent/chunks/views-DH1n9Lrt.mjs +109 -0
  103. package/dist/version.json +7 -0
  104. package/package.json +97 -4
  105. package/plugin/.claude-plugin/plugin.json +17 -0
  106. package/plugin/skills/agentcrm-admin/SKILL.md +191 -0
  107. package/plugin/skills/agentcrm-admin/references/appearance.md +26 -0
  108. package/plugin/skills/agentcrm-admin/references/import.md +16 -0
  109. package/plugin/skills/agentcrm-admin/references/records.md +30 -0
  110. package/plugin/skills/agentcrm-admin/references/schema.md +59 -0
  111. package/plugin/skills/agentcrm-extensions/SKILL.md +93 -0
  112. package/plugin/skills/agentcrm-extensions/references/module-recipes.md +213 -0
  113. package/plugin/skills/agentcrm-extensions/references/runtime-api.md +41 -0
  114. package/plugin/skills/agentcrm-extensions/references/testing.md +78 -0
  115. package/plugin/skills/agentcrm-extensions/references/theme-recipes.md +65 -0
  116. package/plugin/skills/agentcrm-install/SKILL.md +116 -0
  117. package/plugin/skills/agentcrm-install/references/firebase.md +18 -0
  118. package/plugin/skills/agentcrm-install/references/github.md +20 -0
  119. package/plugin/skills/agentcrm-install/references/mcp.md +17 -0
  120. package/plugin/skills/agentcrm-install/references/plans.md +45 -0
  121. package/plugin/skills/agentcrm-install/references/s3.md +24 -0
  122. package/plugin/skills/agentcrm-manage/SKILL.md +108 -0
  123. package/plugin/skills/agentcrm-manage/references/cron.md +11 -0
  124. package/plugin/skills/agentcrm-manage/references/doctor.md +18 -0
  125. package/plugin/skills/agentcrm-sales/SKILL.md +92 -0
  126. package/plugin/skills/agentcrm-sales/references/enrichment.md +13 -0
  127. package/plugin/skills/agentcrm-sales/references/playbooks.md +29 -0
  128. package/plugin/skills/agentcrm-sales/references/weekly-report.md +27 -0
  129. package/types/agentcrm-runtime.d.ts +894 -0
@@ -0,0 +1,1309 @@
1
+ import { createRequire as __acrmRequire } from "node:module";
2
+ import { fileURLToPath as __acrmPath } from "node:url";
3
+ import { dirname as __acrmDirname } from "node:path";
4
+ const require2 = __acrmRequire(import.meta.url);
5
+ const __filename = __acrmPath(import.meta.url);
6
+ const __dirname = __acrmDirname(__filename);
7
+ import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-ClciMIcB.mjs";
8
+ import require$$0 from "stream";
9
+ function _mergeNamespaces(n, m) {
10
+ for (var i = 0; i < m.length; i++) {
11
+ const e = m[i];
12
+ if (typeof e !== "string" && !Array.isArray(e)) {
13
+ for (const k in e) {
14
+ if (k !== "default" && !(k in n)) {
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
+ if (d) {
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: () => e[k]
20
+ });
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }));
27
+ }
28
+ var papaparse$2 = { exports: {} };
29
+ /* @license
30
+ Papa Parse
31
+ v5.7.0
32
+ https://github.com/mholt/PapaParse
33
+ License: MIT
34
+ */
35
+ var papaparse$1 = papaparse$2.exports;
36
+ var hasRequiredPapaparse;
37
+ function requirePapaparse() {
38
+ if (hasRequiredPapaparse) return papaparse$2.exports;
39
+ hasRequiredPapaparse = 1;
40
+ (function(module, exports) {
41
+ (function(root, factory) {
42
+ {
43
+ module.exports = factory();
44
+ }
45
+ })(papaparse$1, function moduleFactory() {
46
+ var global = (function() {
47
+ if (typeof self !== "undefined") {
48
+ return self;
49
+ }
50
+ if (typeof window !== "undefined") {
51
+ return window;
52
+ }
53
+ if (typeof global !== "undefined") {
54
+ return global;
55
+ }
56
+ return {};
57
+ })();
58
+ function getWorkerBlob() {
59
+ var URL = global.URL || global.webkitURL || null;
60
+ var code = moduleFactory.toString();
61
+ return Papa2.BLOB_URL || (Papa2.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" })));
62
+ }
63
+ var IS_WORKER = !global.document && !!global.postMessage, IS_PAPA_WORKER = global.IS_PAPA_WORKER || false;
64
+ var workers = {}, workerIdCounter = 0;
65
+ var Papa2 = {};
66
+ Papa2.parse = CsvToJson;
67
+ Papa2.unparse = JsonToCsv;
68
+ Papa2.RECORD_SEP = String.fromCharCode(30);
69
+ Papa2.UNIT_SEP = String.fromCharCode(31);
70
+ Papa2.BYTE_ORDER_MARK = "\uFEFF";
71
+ Papa2.BAD_DELIMITERS = ["\r", "\n", '"', Papa2.BYTE_ORDER_MARK];
72
+ Papa2.WORKERS_SUPPORTED = !IS_WORKER && !!global.Worker;
73
+ Papa2.NODE_STREAM_INPUT = 1;
74
+ Papa2.LocalChunkSize = 1024 * 1024 * 10;
75
+ Papa2.RemoteChunkSize = 1024 * 1024 * 5;
76
+ Papa2.DefaultDelimiter = ",";
77
+ Papa2.Parser = Parser;
78
+ Papa2.ParserHandle = ParserHandle;
79
+ Papa2.NetworkStreamer = NetworkStreamer;
80
+ Papa2.FileStreamer = FileStreamer;
81
+ Papa2.StringStreamer = StringStreamer;
82
+ Papa2.ReadableStreamStreamer = ReadableStreamStreamer;
83
+ if (typeof PAPA_BROWSER_CONTEXT === "undefined") {
84
+ Papa2.DuplexStreamStreamer = DuplexStreamStreamer;
85
+ }
86
+ if (IS_PAPA_WORKER) {
87
+ global.onmessage = workerThreadReceivedMessage;
88
+ }
89
+ function stripBom(string) {
90
+ if (string.charCodeAt(0) === 65279) {
91
+ return string.slice(1);
92
+ }
93
+ return string;
94
+ }
95
+ function CsvToJson(_input, _config) {
96
+ _config = _config || {};
97
+ var dynamicTyping = _config.dynamicTyping || false;
98
+ if (isFunction(dynamicTyping)) {
99
+ _config.dynamicTypingFunction = dynamicTyping;
100
+ dynamicTyping = {};
101
+ }
102
+ _config.dynamicTyping = dynamicTyping;
103
+ _config.transform = isFunction(_config.transform) ? _config.transform : false;
104
+ if (_config.downloadTimeout !== void 0) {
105
+ var downloadTimeout = parseInt(_config.downloadTimeout);
106
+ if (isNaN(downloadTimeout)) {
107
+ throw new Error("Config downloadTimeout value (" + _config.downloadTimeout + ") not parsable by parseInt(val).");
108
+ }
109
+ _config.downloadTimeout = downloadTimeout;
110
+ }
111
+ if (_config.worker && Papa2.WORKERS_SUPPORTED) {
112
+ var w = newWorker();
113
+ w.userStep = _config.step;
114
+ w.userChunk = _config.chunk;
115
+ w.userComplete = _config.complete;
116
+ w.userError = _config.error;
117
+ _config.step = isFunction(_config.step);
118
+ _config.chunk = isFunction(_config.chunk);
119
+ _config.complete = isFunction(_config.complete);
120
+ _config.error = isFunction(_config.error);
121
+ delete _config.worker;
122
+ w.postMessage({
123
+ input: _input,
124
+ config: _config,
125
+ workerId: w.id
126
+ });
127
+ return;
128
+ }
129
+ var streamer = null;
130
+ if (_input === Papa2.NODE_STREAM_INPUT && typeof PAPA_BROWSER_CONTEXT === "undefined") {
131
+ streamer = new DuplexStreamStreamer(_config);
132
+ return streamer.getStream();
133
+ } else if (typeof _input === "string") {
134
+ _input = stripBom(_input);
135
+ if (_config.download)
136
+ streamer = new NetworkStreamer(_config);
137
+ else
138
+ streamer = new StringStreamer(_config);
139
+ } else if (_input.readable === true && isFunction(_input.read) && isFunction(_input.on)) {
140
+ streamer = new ReadableStreamStreamer(_config);
141
+ } else if (global.File && _input instanceof File || _input instanceof Object)
142
+ streamer = new FileStreamer(_config);
143
+ return streamer.stream(_input);
144
+ }
145
+ function JsonToCsv(_input, _config) {
146
+ var _quotes = false;
147
+ var _writeHeader = true;
148
+ var _delimiter = ",";
149
+ var _newline = "\r\n";
150
+ var _quoteChar = '"';
151
+ var _escapedQuote = _quoteChar + _quoteChar;
152
+ var _skipEmptyLines = false;
153
+ var _columns = null;
154
+ var _escapeFormulae = false;
155
+ unpackConfig();
156
+ var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), "g");
157
+ if (typeof _input === "string")
158
+ _input = JSON.parse(_input);
159
+ if (Array.isArray(_input)) {
160
+ if (!_input.length || Array.isArray(_input[0]))
161
+ return serialize(null, _input, _skipEmptyLines);
162
+ else if (typeof _input[0] === "object")
163
+ return serialize(_columns || Object.keys(_input[0]), _input, _skipEmptyLines);
164
+ } else if (typeof _input === "object") {
165
+ if (typeof _input.data === "string")
166
+ _input.data = JSON.parse(_input.data);
167
+ if (Array.isArray(_input.data)) {
168
+ if (!_input.fields)
169
+ _input.fields = _input.meta && _input.meta.fields || _columns;
170
+ if (!_input.fields)
171
+ _input.fields = Array.isArray(_input.data[0]) ? _input.fields : typeof _input.data[0] === "object" ? Object.keys(_input.data[0]) : [];
172
+ if (!Array.isArray(_input.data[0]) && typeof _input.data[0] !== "object")
173
+ _input.data = [_input.data];
174
+ }
175
+ return serialize(_input.fields || [], _input.data || [], _skipEmptyLines);
176
+ }
177
+ throw new Error("Unable to serialize unrecognized input");
178
+ function unpackConfig() {
179
+ if (typeof _config !== "object")
180
+ return;
181
+ if (typeof _config.delimiter === "string" && !Papa2.BAD_DELIMITERS.filter(function(value) {
182
+ return _config.delimiter.indexOf(value) !== -1;
183
+ }).length) {
184
+ _delimiter = _config.delimiter;
185
+ }
186
+ if (typeof _config.quotes === "boolean" || typeof _config.quotes === "function" || Array.isArray(_config.quotes))
187
+ _quotes = _config.quotes;
188
+ if (typeof _config.skipEmptyLines === "boolean" || typeof _config.skipEmptyLines === "string")
189
+ _skipEmptyLines = _config.skipEmptyLines;
190
+ if (typeof _config.newline === "string")
191
+ _newline = _config.newline;
192
+ if (typeof _config.quoteChar === "string") {
193
+ _quoteChar = _config.quoteChar;
194
+ _escapedQuote = _quoteChar + _quoteChar;
195
+ }
196
+ if (typeof _config.header === "boolean")
197
+ _writeHeader = _config.header;
198
+ if (Array.isArray(_config.columns)) {
199
+ if (_config.columns.length === 0) throw new Error("Option columns is empty");
200
+ _columns = _config.columns;
201
+ }
202
+ if (_config.escapeChar !== void 0) {
203
+ _escapedQuote = _config.escapeChar + _quoteChar;
204
+ }
205
+ if (_config.escapeFormulae instanceof RegExp) {
206
+ _escapeFormulae = _config.escapeFormulae;
207
+ } else if (typeof _config.escapeFormulae === "boolean" && _config.escapeFormulae) {
208
+ _escapeFormulae = /^[=+\-@\t\r].*$/;
209
+ }
210
+ }
211
+ function serialize(fields, data, skipEmptyLines) {
212
+ var csv = "";
213
+ if (typeof fields === "string")
214
+ fields = JSON.parse(fields);
215
+ if (typeof data === "string")
216
+ data = JSON.parse(data);
217
+ var hasHeader = Array.isArray(fields) && fields.length > 0;
218
+ var dataKeyedByField = !Array.isArray(data[0]);
219
+ if (hasHeader && _writeHeader) {
220
+ for (var i = 0; i < fields.length; i++) {
221
+ if (i > 0)
222
+ csv += _delimiter;
223
+ csv += safe(fields[i], i);
224
+ }
225
+ if (data.length > 0)
226
+ csv += _newline;
227
+ }
228
+ for (var row = 0; row < data.length; row++) {
229
+ var maxCol = hasHeader ? fields.length : data[row].length;
230
+ var emptyLine = false;
231
+ var nullLine = hasHeader ? Object.keys(data[row]).length === 0 : data[row].length === 0;
232
+ if (skipEmptyLines && !hasHeader) {
233
+ emptyLine = skipEmptyLines === "greedy" ? data[row].join("").trim() === "" : data[row].length === 1 && data[row][0].length === 0;
234
+ }
235
+ if (skipEmptyLines === "greedy" && hasHeader) {
236
+ var line = [];
237
+ for (var c = 0; c < maxCol; c++) {
238
+ var cx = dataKeyedByField ? fields[c] : c;
239
+ line.push(data[row][cx]);
240
+ }
241
+ emptyLine = line.join("").trim() === "";
242
+ }
243
+ if (!emptyLine) {
244
+ for (var col = 0; col < maxCol; col++) {
245
+ if (col > 0 && !nullLine)
246
+ csv += _delimiter;
247
+ var colIdx = hasHeader && dataKeyedByField ? fields[col] : col;
248
+ csv += safe(data[row][colIdx], col);
249
+ }
250
+ if (row < data.length - 1 && (!skipEmptyLines || maxCol > 0 && !nullLine)) {
251
+ csv += _newline;
252
+ }
253
+ }
254
+ }
255
+ return csv;
256
+ }
257
+ function safe(str, col) {
258
+ if (typeof str === "undefined" || str === null)
259
+ return "";
260
+ if (str.constructor === Date) {
261
+ if (isNaN(str.getTime()))
262
+ return "";
263
+ return str.toISOString();
264
+ }
265
+ var needsQuotes = false;
266
+ if (_escapeFormulae && typeof str === "string" && _escapeFormulae.test(str)) {
267
+ str = "'" + str;
268
+ needsQuotes = true;
269
+ }
270
+ var strValue = str.toString();
271
+ var escapedQuoteStr = strValue.replace(quoteCharRegex, _escapedQuote);
272
+ needsQuotes = needsQuotes || _quotes === true || typeof _quotes === "function" && _quotes(str, col) || Array.isArray(_quotes) && _quotes[col] || hasAny(escapedQuoteStr, Papa2.BAD_DELIMITERS) || escapedQuoteStr.indexOf(_delimiter) > -1 || strValue.indexOf(_quoteChar) > -1 || escapedQuoteStr.charAt(0) === " " || escapedQuoteStr.charAt(escapedQuoteStr.length - 1) === " ";
273
+ return needsQuotes ? _quoteChar + escapedQuoteStr + _quoteChar : escapedQuoteStr;
274
+ }
275
+ function hasAny(str, substrings) {
276
+ for (var i = 0; i < substrings.length; i++)
277
+ if (str.indexOf(substrings[i]) > -1)
278
+ return true;
279
+ return false;
280
+ }
281
+ }
282
+ function ChunkStreamer(config) {
283
+ this._handle = null;
284
+ this._finished = false;
285
+ this._completed = false;
286
+ this._halted = false;
287
+ this._input = null;
288
+ this._baseIndex = 0;
289
+ this._partialLine = "";
290
+ this._rowCount = 0;
291
+ this._start = 0;
292
+ this._nextChunk = null;
293
+ this.isFirstChunk = true;
294
+ this._completeResults = {
295
+ data: [],
296
+ errors: [],
297
+ meta: {}
298
+ };
299
+ replaceConfig.call(this, config);
300
+ this.parseChunk = function(chunk, isFakeChunk) {
301
+ const skipFirstNLines = parseInt(this._config.skipFirstNLines) || 0;
302
+ if (this.isFirstChunk && skipFirstNLines > 0) {
303
+ let _newline = this._config.newline;
304
+ if (!_newline) {
305
+ const quoteChar = this._config.quoteChar || '"';
306
+ _newline = this._handle.guessLineEndings(chunk, quoteChar);
307
+ }
308
+ const splitChunk = chunk.split(_newline);
309
+ chunk = [...splitChunk.slice(skipFirstNLines)].join(_newline);
310
+ }
311
+ if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk)) {
312
+ var modifiedChunk = this._config.beforeFirstChunk(chunk);
313
+ if (modifiedChunk !== void 0)
314
+ chunk = modifiedChunk;
315
+ }
316
+ this.isFirstChunk = false;
317
+ this._halted = false;
318
+ var aggregate = this._partialLine + chunk;
319
+ this._partialLine = "";
320
+ var results = this._handle.parse(aggregate, this._baseIndex, !this._finished);
321
+ if (this._handle.paused() || this._handle.aborted()) {
322
+ this._halted = true;
323
+ return;
324
+ }
325
+ var lastIndex = results.meta.cursor;
326
+ if (!this._finished) {
327
+ this._partialLine = aggregate.substring(lastIndex - this._baseIndex);
328
+ this._baseIndex = lastIndex;
329
+ }
330
+ if (results && results.data)
331
+ this._rowCount += results.data.length;
332
+ var finishedIncludingPreview = this._finished || this._config.preview && this._rowCount >= this._config.preview;
333
+ if (IS_PAPA_WORKER) {
334
+ global.postMessage({
335
+ results,
336
+ workerId: Papa2.WORKER_ID,
337
+ finished: finishedIncludingPreview
338
+ });
339
+ } else if (isFunction(this._config.chunk) && !isFakeChunk) {
340
+ this._config.chunk(results, this._handle);
341
+ if (this._handle.paused() || this._handle.aborted()) {
342
+ this._halted = true;
343
+ return;
344
+ }
345
+ results = void 0;
346
+ this._completeResults = void 0;
347
+ }
348
+ if (!this._config.step && !this._config.chunk) {
349
+ this._completeResults.data = this._completeResults.data.concat(results.data);
350
+ this._completeResults.errors = this._completeResults.errors.concat(results.errors);
351
+ this._completeResults.meta = results.meta;
352
+ }
353
+ if (!this._completed && finishedIncludingPreview && isFunction(this._config.complete) && (!results || !results.meta.aborted)) {
354
+ this._config.complete(this._completeResults, this._input);
355
+ this._completed = true;
356
+ }
357
+ if (!finishedIncludingPreview && (!results || !results.meta.paused))
358
+ this._nextChunk();
359
+ return results;
360
+ };
361
+ this._sendError = function(error) {
362
+ if (isFunction(this._config.error))
363
+ this._config.error(error);
364
+ else if (IS_PAPA_WORKER && this._config.error) {
365
+ global.postMessage({
366
+ workerId: Papa2.WORKER_ID,
367
+ error,
368
+ finished: false
369
+ });
370
+ }
371
+ };
372
+ function replaceConfig(config2) {
373
+ var configCopy = copy(config2);
374
+ configCopy.chunkSize = parseInt(configCopy.chunkSize);
375
+ if (!config2.step && !config2.chunk)
376
+ configCopy.chunkSize = null;
377
+ this._handle = new ParserHandle(configCopy);
378
+ this._handle.streamer = this;
379
+ this._config = configCopy;
380
+ }
381
+ }
382
+ function NetworkStreamer(config) {
383
+ config = config || {};
384
+ if (!config.chunkSize)
385
+ config.chunkSize = Papa2.RemoteChunkSize;
386
+ ChunkStreamer.call(this, config);
387
+ var xhr;
388
+ if (IS_WORKER) {
389
+ this._nextChunk = function() {
390
+ this._readChunk();
391
+ this._chunkLoaded();
392
+ };
393
+ } else {
394
+ this._nextChunk = function() {
395
+ this._readChunk();
396
+ };
397
+ }
398
+ this.stream = function(url) {
399
+ this._input = url;
400
+ this._nextChunk();
401
+ };
402
+ this._readChunk = function() {
403
+ if (this._finished) {
404
+ this._chunkLoaded();
405
+ return;
406
+ }
407
+ xhr = new XMLHttpRequest();
408
+ if (this._config.withCredentials) {
409
+ xhr.withCredentials = this._config.withCredentials;
410
+ }
411
+ if (!IS_WORKER) {
412
+ xhr.onload = bindFunction(this._chunkLoaded, this);
413
+ xhr.onerror = bindFunction(this._chunkError, this);
414
+ }
415
+ xhr.ontimeout = bindFunction(this._chunkTimeout, this);
416
+ xhr.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !IS_WORKER);
417
+ if (this._config.downloadTimeout && !IS_WORKER) {
418
+ xhr.timeout = this._config.downloadTimeout;
419
+ }
420
+ if (this._config.downloadRequestHeaders) {
421
+ var headers = this._config.downloadRequestHeaders;
422
+ for (var headerName in headers) {
423
+ xhr.setRequestHeader(headerName, headers[headerName]);
424
+ }
425
+ }
426
+ if (this._config.chunkSize) {
427
+ var end = this._start + this._config.chunkSize - 1;
428
+ xhr.setRequestHeader("Range", "bytes=" + this._start + "-" + end);
429
+ }
430
+ try {
431
+ xhr.send(this._config.downloadRequestBody);
432
+ } catch (err) {
433
+ this._chunkError(err.message);
434
+ }
435
+ if (IS_WORKER && xhr.status === 0)
436
+ this._chunkError();
437
+ };
438
+ this._chunkLoaded = function() {
439
+ if (xhr.readyState !== 4)
440
+ return;
441
+ if (xhr.status < 200 || xhr.status >= 400) {
442
+ this._chunkError();
443
+ return;
444
+ }
445
+ this._start += this._config.chunkSize ? this._config.chunkSize : xhr.responseText.length;
446
+ this._finished = !this._config.chunkSize || this._start >= getFileSize(xhr);
447
+ this.parseChunk(xhr.responseText);
448
+ };
449
+ this._chunkError = function(errorMessage) {
450
+ var errorText = xhr.statusText || errorMessage;
451
+ this._sendError(new Error(errorText));
452
+ };
453
+ this._chunkTimeout = function() {
454
+ this._chunkError("Request timed out after " + this._config.downloadTimeout + "ms");
455
+ };
456
+ function getFileSize(xhr2) {
457
+ var contentRange = xhr2.getResponseHeader("Content-Range");
458
+ if (contentRange === null) {
459
+ return -1;
460
+ }
461
+ return parseInt(contentRange.substring(contentRange.lastIndexOf("/") + 1));
462
+ }
463
+ }
464
+ NetworkStreamer.prototype = Object.create(ChunkStreamer.prototype);
465
+ NetworkStreamer.prototype.constructor = NetworkStreamer;
466
+ function FileStreamer(config) {
467
+ config = config || {};
468
+ if (!config.chunkSize)
469
+ config.chunkSize = Papa2.LocalChunkSize;
470
+ ChunkStreamer.call(this, config);
471
+ var reader, slice;
472
+ var usingAsyncReader = typeof FileReader !== "undefined";
473
+ this.stream = function(file) {
474
+ this._input = file;
475
+ slice = file.slice || file.webkitSlice || file.mozSlice;
476
+ if (usingAsyncReader) {
477
+ reader = new FileReader();
478
+ reader.onload = bindFunction(this._chunkLoaded, this);
479
+ reader.onerror = bindFunction(this._chunkError, this);
480
+ } else
481
+ reader = new FileReaderSync();
482
+ this._nextChunk();
483
+ };
484
+ this._nextChunk = function() {
485
+ if (!this._finished && (!this._config.preview || this._rowCount < this._config.preview))
486
+ this._readChunk();
487
+ };
488
+ this._readChunk = function() {
489
+ var input = this._input;
490
+ if (this._config.chunkSize) {
491
+ var end = Math.min(this._start + this._config.chunkSize, this._input.size);
492
+ input = slice.call(input, this._start, end);
493
+ }
494
+ var txt = reader.readAsText(input, this._config.encoding);
495
+ if (!usingAsyncReader)
496
+ this._chunkLoaded({ target: { result: txt } });
497
+ };
498
+ this._chunkLoaded = function(event) {
499
+ this._start += this._config.chunkSize;
500
+ this._finished = !this._config.chunkSize || this._start >= this._input.size;
501
+ this.parseChunk(event.target.result);
502
+ };
503
+ this._chunkError = function() {
504
+ this._sendError(reader.error);
505
+ };
506
+ }
507
+ FileStreamer.prototype = Object.create(ChunkStreamer.prototype);
508
+ FileStreamer.prototype.constructor = FileStreamer;
509
+ function StringStreamer(config) {
510
+ config = config || {};
511
+ ChunkStreamer.call(this, config);
512
+ var remaining;
513
+ this.stream = function(s) {
514
+ remaining = s;
515
+ return this._nextChunk();
516
+ };
517
+ this._nextChunk = function() {
518
+ if (this._finished) return;
519
+ var size = this._config.chunkSize;
520
+ var chunk;
521
+ if (size) {
522
+ chunk = remaining.substring(0, size);
523
+ remaining = remaining.substring(size);
524
+ } else {
525
+ chunk = remaining;
526
+ remaining = "";
527
+ }
528
+ this._finished = !remaining;
529
+ return this.parseChunk(chunk);
530
+ };
531
+ }
532
+ StringStreamer.prototype = Object.create(StringStreamer.prototype);
533
+ StringStreamer.prototype.constructor = StringStreamer;
534
+ function ReadableStreamStreamer(config) {
535
+ config = config || {};
536
+ ChunkStreamer.call(this, config);
537
+ var queue = [];
538
+ var parseOnData = true;
539
+ var streamHasEnded = false;
540
+ this.pause = function() {
541
+ ChunkStreamer.prototype.pause.apply(this, arguments);
542
+ this._input.pause();
543
+ };
544
+ this.resume = function() {
545
+ ChunkStreamer.prototype.resume.apply(this, arguments);
546
+ this._input.resume();
547
+ };
548
+ this.stream = function(stream) {
549
+ this._input = stream;
550
+ this._input.on("data", this._streamData);
551
+ this._input.on("end", this._streamEnd);
552
+ this._input.on("error", this._streamError);
553
+ };
554
+ this._checkIsFinished = function() {
555
+ if (streamHasEnded && queue.length === 1) {
556
+ this._finished = true;
557
+ }
558
+ };
559
+ this._nextChunk = function() {
560
+ this._checkIsFinished();
561
+ if (queue.length) {
562
+ this.parseChunk(queue.shift());
563
+ } else {
564
+ parseOnData = true;
565
+ }
566
+ };
567
+ this._streamData = bindFunction(function(chunk) {
568
+ try {
569
+ queue.push(typeof chunk === "string" ? chunk : chunk.toString(this._config.encoding));
570
+ if (parseOnData) {
571
+ parseOnData = false;
572
+ this._checkIsFinished();
573
+ this.parseChunk(queue.shift());
574
+ }
575
+ } catch (error) {
576
+ this._streamError(error);
577
+ }
578
+ }, this);
579
+ this._streamError = bindFunction(function(error) {
580
+ this._streamCleanUp();
581
+ this._sendError(error);
582
+ }, this);
583
+ this._streamEnd = bindFunction(function() {
584
+ this._streamCleanUp();
585
+ streamHasEnded = true;
586
+ this._streamData("");
587
+ }, this);
588
+ this._streamCleanUp = bindFunction(function() {
589
+ this._input.removeListener("data", this._streamData);
590
+ this._input.removeListener("end", this._streamEnd);
591
+ this._input.removeListener("error", this._streamError);
592
+ }, this);
593
+ }
594
+ ReadableStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
595
+ ReadableStreamStreamer.prototype.constructor = ReadableStreamStreamer;
596
+ function DuplexStreamStreamer(_config) {
597
+ var Duplex = require$$0.Duplex;
598
+ var config = copy(_config);
599
+ var parseOnWrite = true;
600
+ var writeStreamHasFinished = false;
601
+ var parseCallbackQueue = [];
602
+ var stream = null;
603
+ this._onCsvData = function(results) {
604
+ var data = results.data;
605
+ if (!stream.push(data) && !this._handle.paused()) {
606
+ this._handle.pause();
607
+ }
608
+ };
609
+ this._onCsvComplete = function() {
610
+ stream.push(null);
611
+ };
612
+ config.step = bindFunction(this._onCsvData, this);
613
+ config.complete = bindFunction(this._onCsvComplete, this);
614
+ ChunkStreamer.call(this, config);
615
+ this._nextChunk = function() {
616
+ if (writeStreamHasFinished && parseCallbackQueue.length === 1) {
617
+ this._finished = true;
618
+ }
619
+ if (parseCallbackQueue.length) {
620
+ parseCallbackQueue.shift()();
621
+ } else {
622
+ parseOnWrite = true;
623
+ }
624
+ };
625
+ this._addToParseQueue = function(chunk, callback) {
626
+ parseCallbackQueue.push(bindFunction(function() {
627
+ this.parseChunk(typeof chunk === "string" ? chunk : chunk.toString(config.encoding));
628
+ if (isFunction(callback)) {
629
+ return callback();
630
+ }
631
+ }, this));
632
+ if (parseOnWrite) {
633
+ parseOnWrite = false;
634
+ this._nextChunk();
635
+ }
636
+ };
637
+ this._onRead = function() {
638
+ if (this._handle.paused()) {
639
+ this._handle.resume();
640
+ }
641
+ };
642
+ this._onWrite = function(chunk, encoding, callback) {
643
+ this._addToParseQueue(chunk, callback);
644
+ };
645
+ this._onWriteComplete = function() {
646
+ writeStreamHasFinished = true;
647
+ this._addToParseQueue("");
648
+ };
649
+ this.getStream = function() {
650
+ return stream;
651
+ };
652
+ stream = new Duplex({
653
+ readableObjectMode: true,
654
+ decodeStrings: false,
655
+ read: bindFunction(this._onRead, this),
656
+ write: bindFunction(this._onWrite, this)
657
+ });
658
+ stream.once("finish", bindFunction(this._onWriteComplete, this));
659
+ }
660
+ if (typeof PAPA_BROWSER_CONTEXT === "undefined") {
661
+ DuplexStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
662
+ DuplexStreamStreamer.prototype.constructor = DuplexStreamStreamer;
663
+ }
664
+ function ParserHandle(_config) {
665
+ var MAX_FLOAT = Math.pow(2, 53);
666
+ var MIN_FLOAT = -MAX_FLOAT;
667
+ var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/;
668
+ 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)))$/;
669
+ var self2 = this;
670
+ var _stepCounter = 0;
671
+ var _rowCounter = 0;
672
+ var _input;
673
+ var _parser;
674
+ var _paused = false;
675
+ var _aborted = false;
676
+ var _delimiterError;
677
+ var _fields = [];
678
+ var _results = {
679
+ // The last results returned from the parser
680
+ data: [],
681
+ errors: [],
682
+ meta: {}
683
+ };
684
+ if (isFunction(_config.step)) {
685
+ var userStep = _config.step;
686
+ _config.step = function(results) {
687
+ _results = results;
688
+ if (needsHeaderRow())
689
+ processResults();
690
+ else {
691
+ processResults();
692
+ if (_results.data.length === 0)
693
+ return;
694
+ _stepCounter += results.data.length;
695
+ if (_config.preview && _stepCounter > _config.preview)
696
+ _parser.abort();
697
+ else {
698
+ _results.data = _results.data[0];
699
+ userStep(_results, self2);
700
+ }
701
+ }
702
+ };
703
+ }
704
+ this.parse = function(input, baseIndex, ignoreLastRow) {
705
+ var quoteChar = _config.quoteChar || '"';
706
+ if (!_config.newline)
707
+ _config.newline = this.guessLineEndings(input, quoteChar);
708
+ _delimiterError = false;
709
+ if (!_config.delimiter) {
710
+ var delimGuess = guessDelimiter(input, _config.newline, _config.skipEmptyLines, _config.comments, _config.delimitersToGuess);
711
+ if (delimGuess.successful)
712
+ _config.delimiter = delimGuess.bestDelimiter;
713
+ else {
714
+ _delimiterError = true;
715
+ _config.delimiter = Papa2.DefaultDelimiter;
716
+ }
717
+ _results.meta.delimiter = _config.delimiter;
718
+ } else if (isFunction(_config.delimiter)) {
719
+ _config.delimiter = _config.delimiter(input);
720
+ _results.meta.delimiter = _config.delimiter;
721
+ }
722
+ var parserConfig = copy(_config);
723
+ parserConfig.header = needsHeaderRow();
724
+ if (_config.preview && _config.header)
725
+ parserConfig.preview++;
726
+ _input = input;
727
+ _parser = new Parser(parserConfig);
728
+ _results = _parser.parse(_input, baseIndex, ignoreLastRow);
729
+ processResults();
730
+ return _paused ? { meta: { paused: true } } : _results || { meta: { paused: false } };
731
+ };
732
+ this.paused = function() {
733
+ return _paused;
734
+ };
735
+ this.pause = function() {
736
+ _paused = true;
737
+ _parser.abort();
738
+ _input = isFunction(_config.chunk) ? "" : _input.substring(_parser.getCharIndex());
739
+ };
740
+ this.resume = function() {
741
+ if (self2.streamer._halted) {
742
+ _paused = false;
743
+ self2.streamer.parseChunk(_input, true);
744
+ } else {
745
+ setTimeout(self2.resume, 3);
746
+ }
747
+ };
748
+ this.aborted = function() {
749
+ return _aborted;
750
+ };
751
+ this.abort = function() {
752
+ _aborted = true;
753
+ _parser.abort();
754
+ _results.meta.aborted = true;
755
+ if (isFunction(_config.complete))
756
+ _config.complete(_results);
757
+ _input = "";
758
+ };
759
+ this.guessLineEndings = function(input, quoteChar) {
760
+ input = input.substring(0, 1024 * 1024);
761
+ var re = new RegExp(escapeRegExp(quoteChar) + "([^]*?)" + escapeRegExp(quoteChar), "gm");
762
+ input = input.replace(re, "");
763
+ var r = input.split("\r");
764
+ var n = input.split("\n");
765
+ var nAppearsFirst = n.length > 1 && n[0].length < r[0].length;
766
+ if (r.length === 1 || nAppearsFirst)
767
+ return "\n";
768
+ var numWithN = 0;
769
+ for (var i = 0; i < r.length; i++) {
770
+ if (r[i][0] === "\n")
771
+ numWithN++;
772
+ }
773
+ return numWithN >= r.length / 2 ? "\r\n" : "\r";
774
+ };
775
+ function testEmptyLine(s) {
776
+ return _config.skipEmptyLines === "greedy" ? s.join("").trim() === "" : s.length === 1 && s[0].length === 0;
777
+ }
778
+ function testFloat(s) {
779
+ if (FLOAT.test(s)) {
780
+ var floatValue = parseFloat(s);
781
+ if (floatValue > MIN_FLOAT && floatValue < MAX_FLOAT) {
782
+ return true;
783
+ }
784
+ }
785
+ return false;
786
+ }
787
+ function processResults() {
788
+ if (_results && _delimiterError) {
789
+ addError("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + Papa2.DefaultDelimiter + "'");
790
+ _delimiterError = false;
791
+ }
792
+ if (_config.skipEmptyLines) {
793
+ _results.data = _results.data.filter(function(d) {
794
+ return !testEmptyLine(d);
795
+ });
796
+ }
797
+ if (needsHeaderRow())
798
+ fillHeaderFields();
799
+ return applyHeaderAndDynamicTypingAndTransformation();
800
+ }
801
+ function needsHeaderRow() {
802
+ return _config.header && _fields.length === 0;
803
+ }
804
+ function fillHeaderFields() {
805
+ if (!_results)
806
+ return;
807
+ function addHeader(header) {
808
+ _fields.push(header);
809
+ }
810
+ if (Array.isArray(_results.data[0])) {
811
+ for (var i = 0; needsHeaderRow() && i < _results.data.length; i++)
812
+ _results.data[i].forEach(addHeader);
813
+ _results.data.splice(0, 1);
814
+ } else
815
+ _results.data.forEach(addHeader);
816
+ }
817
+ function shouldApplyDynamicTyping(field) {
818
+ if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === void 0) {
819
+ _config.dynamicTyping[field] = _config.dynamicTypingFunction(field);
820
+ }
821
+ return (_config.dynamicTyping[field] || _config.dynamicTyping) === true;
822
+ }
823
+ function parseDynamic(field, value) {
824
+ if (shouldApplyDynamicTyping(field)) {
825
+ if (value === "true" || value === "TRUE")
826
+ return true;
827
+ else if (value === "false" || value === "FALSE")
828
+ return false;
829
+ else if (testFloat(value))
830
+ return parseFloat(value);
831
+ else if (ISO_DATE.test(value))
832
+ return new Date(value);
833
+ else
834
+ return value === "" ? null : value;
835
+ }
836
+ return value;
837
+ }
838
+ function applyHeaderAndDynamicTypingAndTransformation() {
839
+ if (!_results || !_config.header && !_config.dynamicTyping && !_config.transform)
840
+ return _results;
841
+ function processRow(rowSource, i) {
842
+ var row = _config.header ? {} : [];
843
+ var j;
844
+ for (j = 0; j < rowSource.length; j++) {
845
+ var field = j;
846
+ var value = rowSource[j];
847
+ if (_config.header)
848
+ field = j >= _fields.length ? "__parsed_extra" : _fields[j];
849
+ if (_config.transform)
850
+ value = _config.transform(value, field);
851
+ value = parseDynamic(field, value);
852
+ if (field === "__parsed_extra") {
853
+ row[field] = row[field] || [];
854
+ row[field].push(value);
855
+ } else
856
+ row[field] = value;
857
+ }
858
+ if (_config.header) {
859
+ if (j > _fields.length)
860
+ addError("FieldMismatch", "TooManyFields", "Too many fields: expected " + _fields.length + " fields but parsed " + j, _rowCounter + i);
861
+ else if (j < _fields.length)
862
+ addError("FieldMismatch", "TooFewFields", "Too few fields: expected " + _fields.length + " fields but parsed " + j, _rowCounter + i);
863
+ }
864
+ return row;
865
+ }
866
+ var incrementBy = 1;
867
+ if (!_results.data.length || Array.isArray(_results.data[0])) {
868
+ _results.data = _results.data.map(processRow);
869
+ incrementBy = _results.data.length;
870
+ } else
871
+ _results.data = processRow(_results.data, 0);
872
+ if (_config.header && _results.meta)
873
+ _results.meta.fields = _fields;
874
+ _rowCounter += incrementBy;
875
+ return _results;
876
+ }
877
+ function guessDelimiter(input, newline, skipEmptyLines, comments, delimitersToGuess) {
878
+ var bestDelim, bestDelta, fieldCountPrevRow, maxFieldCount;
879
+ delimitersToGuess = delimitersToGuess || [",", " ", "|", ";", Papa2.RECORD_SEP, Papa2.UNIT_SEP];
880
+ for (var i = 0; i < delimitersToGuess.length; i++) {
881
+ var delim = delimitersToGuess[i];
882
+ var delta = 0, avgFieldCount = 0, emptyLinesCount = 0;
883
+ fieldCountPrevRow = void 0;
884
+ var preview = new Parser({
885
+ comments,
886
+ delimiter: delim,
887
+ newline,
888
+ preview: 10
889
+ }).parse(input);
890
+ for (var j = 0; j < preview.data.length; j++) {
891
+ if (skipEmptyLines && testEmptyLine(preview.data[j])) {
892
+ emptyLinesCount++;
893
+ continue;
894
+ }
895
+ var fieldCount = preview.data[j].length;
896
+ avgFieldCount += fieldCount;
897
+ if (typeof fieldCountPrevRow === "undefined") {
898
+ fieldCountPrevRow = fieldCount;
899
+ continue;
900
+ } else if (fieldCount > 0) {
901
+ delta += Math.abs(fieldCount - fieldCountPrevRow);
902
+ fieldCountPrevRow = fieldCount;
903
+ }
904
+ }
905
+ if (preview.data.length > 0)
906
+ avgFieldCount /= preview.data.length - emptyLinesCount;
907
+ if (avgFieldCount > 1.99 && (typeof bestDelta === "undefined" || delta < bestDelta || delta === bestDelta && avgFieldCount > maxFieldCount)) {
908
+ bestDelta = delta;
909
+ bestDelim = delim;
910
+ maxFieldCount = avgFieldCount;
911
+ }
912
+ }
913
+ _config.delimiter = bestDelim;
914
+ return {
915
+ successful: !!bestDelim,
916
+ bestDelimiter: bestDelim
917
+ };
918
+ }
919
+ function addError(type, code, msg, row) {
920
+ var error = {
921
+ type,
922
+ code,
923
+ message: msg
924
+ };
925
+ if (row !== void 0) {
926
+ error.row = row;
927
+ }
928
+ _results.errors.push(error);
929
+ }
930
+ }
931
+ function escapeRegExp(string) {
932
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
933
+ }
934
+ function Parser(config) {
935
+ config = config || {};
936
+ var delim = config.delimiter;
937
+ var newline = config.newline;
938
+ var comments = config.comments;
939
+ var step = config.step;
940
+ var preview = config.preview;
941
+ var fastMode = config.fastMode;
942
+ var quoteChar;
943
+ var renamedHeaders = null;
944
+ var headerParsed = false;
945
+ if (config.quoteChar === void 0 || config.quoteChar === null) {
946
+ quoteChar = '"';
947
+ } else {
948
+ quoteChar = config.quoteChar;
949
+ }
950
+ var escapeChar = quoteChar;
951
+ if (config.escapeChar !== void 0) {
952
+ escapeChar = config.escapeChar;
953
+ }
954
+ if (typeof delim !== "string" || Papa2.BAD_DELIMITERS.indexOf(delim) > -1)
955
+ delim = ",";
956
+ if (comments === delim)
957
+ throw new Error("Comment character same as delimiter");
958
+ else if (comments === true)
959
+ comments = "#";
960
+ else if (typeof comments !== "string" || Papa2.BAD_DELIMITERS.indexOf(comments) > -1)
961
+ comments = false;
962
+ if (newline !== "\n" && newline !== "\r" && newline !== "\r\n")
963
+ newline = "\n";
964
+ var cursor = 0;
965
+ var aborted = false;
966
+ this.parse = function(input, baseIndex, ignoreLastRow) {
967
+ if (typeof input !== "string")
968
+ throw new Error("Input must be a string");
969
+ var inputLen = input.length, delimLen = delim.length, newlineLen = newline.length, commentsLen = comments.length;
970
+ var stepIsFunction = isFunction(step);
971
+ cursor = 0;
972
+ var data = [], errors = [], row = [], lastCursor = 0;
973
+ if (!input)
974
+ return returnable();
975
+ if (fastMode || fastMode !== false && input.indexOf(quoteChar) === -1) {
976
+ var rows = input.split(newline);
977
+ for (var i = 0; i < rows.length; i++) {
978
+ row = rows[i];
979
+ cursor += row.length;
980
+ if (i !== rows.length - 1)
981
+ cursor += newline.length;
982
+ else if (ignoreLastRow)
983
+ return returnable();
984
+ if (comments && row.substring(0, commentsLen) === comments)
985
+ continue;
986
+ if (stepIsFunction) {
987
+ data = [];
988
+ pushRow(row.split(delim));
989
+ doStep();
990
+ if (aborted)
991
+ return returnable();
992
+ } else
993
+ pushRow(row.split(delim));
994
+ if (preview && i >= preview) {
995
+ data = data.slice(0, preview);
996
+ return returnable(true);
997
+ }
998
+ }
999
+ return returnable();
1000
+ }
1001
+ var nextDelim = input.indexOf(delim, cursor);
1002
+ var nextNewline = input.indexOf(newline, cursor);
1003
+ var quoteCharRegex = new RegExp(escapeRegExp(escapeChar) + escapeRegExp(quoteChar), "g");
1004
+ var quoteSearch = input.indexOf(quoteChar, cursor);
1005
+ for (; ; ) {
1006
+ if (input[cursor] === quoteChar) {
1007
+ quoteSearch = cursor;
1008
+ cursor++;
1009
+ for (; ; ) {
1010
+ quoteSearch = input.indexOf(quoteChar, quoteSearch + 1);
1011
+ if (quoteSearch === -1) {
1012
+ if (!ignoreLastRow) {
1013
+ errors.push({
1014
+ type: "Quotes",
1015
+ code: "MissingQuotes",
1016
+ message: "Quoted field unterminated",
1017
+ row: data.length,
1018
+ // row has yet to be inserted
1019
+ index: cursor
1020
+ });
1021
+ }
1022
+ return finish();
1023
+ }
1024
+ if (quoteSearch === inputLen - 1) {
1025
+ var value = input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar);
1026
+ return finish(value);
1027
+ }
1028
+ if (quoteChar === escapeChar && input[quoteSearch + 1] === escapeChar) {
1029
+ quoteSearch++;
1030
+ continue;
1031
+ }
1032
+ if (quoteChar !== escapeChar && quoteSearch !== 0 && input[quoteSearch - 1] === escapeChar) {
1033
+ continue;
1034
+ }
1035
+ if (nextDelim !== -1 && nextDelim < quoteSearch + 1) {
1036
+ nextDelim = input.indexOf(delim, quoteSearch + 1);
1037
+ }
1038
+ if (nextNewline !== -1 && nextNewline < quoteSearch + 1) {
1039
+ nextNewline = input.indexOf(newline, quoteSearch + 1);
1040
+ }
1041
+ var checkUpTo = nextNewline === -1 ? nextDelim : Math.min(nextDelim, nextNewline);
1042
+ var spacesBetweenQuoteAndDelimiter = extraSpaces(checkUpTo);
1043
+ if (input.substr(quoteSearch + 1 + spacesBetweenQuoteAndDelimiter, delimLen) === delim) {
1044
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
1045
+ cursor = quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen;
1046
+ if (input[quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen] !== quoteChar) {
1047
+ quoteSearch = input.indexOf(quoteChar, cursor);
1048
+ }
1049
+ nextDelim = input.indexOf(delim, cursor);
1050
+ nextNewline = input.indexOf(newline, cursor);
1051
+ break;
1052
+ }
1053
+ var spacesBetweenQuoteAndNewLine = extraSpaces(nextNewline);
1054
+ if (input.substring(quoteSearch + 1 + spacesBetweenQuoteAndNewLine, quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen) === newline) {
1055
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
1056
+ saveRow(quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen);
1057
+ nextDelim = input.indexOf(delim, cursor);
1058
+ quoteSearch = input.indexOf(quoteChar, cursor);
1059
+ if (stepIsFunction) {
1060
+ doStep();
1061
+ if (aborted)
1062
+ return returnable();
1063
+ }
1064
+ if (preview && data.length >= preview)
1065
+ return returnable(true);
1066
+ break;
1067
+ }
1068
+ errors.push({
1069
+ type: "Quotes",
1070
+ code: "InvalidQuotes",
1071
+ message: "Trailing quote on quoted field is malformed",
1072
+ row: data.length,
1073
+ // row has yet to be inserted
1074
+ index: cursor
1075
+ });
1076
+ quoteSearch++;
1077
+ continue;
1078
+ }
1079
+ continue;
1080
+ }
1081
+ if (comments && row.length === 0 && input.substring(cursor, cursor + commentsLen) === comments) {
1082
+ if (nextNewline === -1)
1083
+ return returnable();
1084
+ cursor = nextNewline + newlineLen;
1085
+ nextNewline = input.indexOf(newline, cursor);
1086
+ nextDelim = input.indexOf(delim, cursor);
1087
+ continue;
1088
+ }
1089
+ if (nextDelim !== -1 && (nextDelim < nextNewline || nextNewline === -1)) {
1090
+ row.push(input.substring(cursor, nextDelim));
1091
+ cursor = nextDelim + delimLen;
1092
+ nextDelim = input.indexOf(delim, cursor);
1093
+ continue;
1094
+ }
1095
+ if (nextNewline !== -1) {
1096
+ row.push(input.substring(cursor, nextNewline));
1097
+ saveRow(nextNewline + newlineLen);
1098
+ if (stepIsFunction) {
1099
+ doStep();
1100
+ if (aborted)
1101
+ return returnable();
1102
+ }
1103
+ if (preview && data.length >= preview)
1104
+ return returnable(true);
1105
+ continue;
1106
+ }
1107
+ break;
1108
+ }
1109
+ return finish();
1110
+ function pushRow(row2) {
1111
+ data.push(row2);
1112
+ lastCursor = cursor;
1113
+ }
1114
+ function extraSpaces(index) {
1115
+ var spaceLength = 0;
1116
+ if (index !== -1) {
1117
+ var textBetweenClosingQuoteAndIndex = input.substring(quoteSearch + 1, index);
1118
+ if (textBetweenClosingQuoteAndIndex && textBetweenClosingQuoteAndIndex.trim() === "") {
1119
+ spaceLength = textBetweenClosingQuoteAndIndex.length;
1120
+ }
1121
+ }
1122
+ return spaceLength;
1123
+ }
1124
+ function finish(value2) {
1125
+ if (ignoreLastRow)
1126
+ return returnable();
1127
+ if (typeof value2 === "undefined")
1128
+ value2 = input.substring(cursor);
1129
+ row.push(value2);
1130
+ cursor = inputLen;
1131
+ pushRow(row);
1132
+ if (stepIsFunction)
1133
+ doStep();
1134
+ return returnable();
1135
+ }
1136
+ function saveRow(newCursor) {
1137
+ cursor = newCursor;
1138
+ pushRow(row);
1139
+ row = [];
1140
+ nextNewline = input.indexOf(newline, cursor);
1141
+ }
1142
+ function returnable(stopped) {
1143
+ if (config.header && !baseIndex && data.length && !headerParsed) {
1144
+ const result = data[0];
1145
+ const headerCount = /* @__PURE__ */ Object.create(null);
1146
+ const usedHeaders = new Set(result);
1147
+ let duplicateHeaders = false;
1148
+ for (let i2 = 0; i2 < result.length; i2++) {
1149
+ let header = stripBom(result[i2]);
1150
+ if (isFunction(config.transformHeader))
1151
+ header = config.transformHeader(header, i2);
1152
+ if (!headerCount[header]) {
1153
+ headerCount[header] = 1;
1154
+ result[i2] = header;
1155
+ } else {
1156
+ let newHeader;
1157
+ let suffixCount = headerCount[header];
1158
+ do {
1159
+ newHeader = `${header}_${suffixCount}`;
1160
+ suffixCount++;
1161
+ } while (usedHeaders.has(newHeader));
1162
+ usedHeaders.add(newHeader);
1163
+ result[i2] = newHeader;
1164
+ headerCount[header]++;
1165
+ duplicateHeaders = true;
1166
+ if (renamedHeaders === null) {
1167
+ renamedHeaders = {};
1168
+ }
1169
+ renamedHeaders[newHeader] = header;
1170
+ }
1171
+ usedHeaders.add(header);
1172
+ }
1173
+ if (duplicateHeaders) {
1174
+ console.warn("Duplicate headers found and renamed.");
1175
+ }
1176
+ headerParsed = true;
1177
+ }
1178
+ return {
1179
+ data,
1180
+ errors,
1181
+ meta: {
1182
+ delimiter: delim,
1183
+ linebreak: newline,
1184
+ aborted,
1185
+ truncated: !!stopped,
1186
+ cursor: lastCursor + (baseIndex || 0),
1187
+ renamedHeaders
1188
+ }
1189
+ };
1190
+ }
1191
+ function doStep() {
1192
+ step(returnable());
1193
+ data = [];
1194
+ errors = [];
1195
+ }
1196
+ };
1197
+ this.abort = function() {
1198
+ aborted = true;
1199
+ };
1200
+ this.getCharIndex = function() {
1201
+ return cursor;
1202
+ };
1203
+ }
1204
+ function newWorker() {
1205
+ if (!Papa2.WORKERS_SUPPORTED)
1206
+ return false;
1207
+ var workerUrl = getWorkerBlob();
1208
+ var w = new global.Worker(workerUrl);
1209
+ w.onmessage = mainThreadReceivedMessage;
1210
+ w.id = workerIdCounter++;
1211
+ workers[w.id] = w;
1212
+ return w;
1213
+ }
1214
+ function mainThreadReceivedMessage(e) {
1215
+ var msg = e.data;
1216
+ var worker = workers[msg.workerId];
1217
+ var aborted = false;
1218
+ if (msg.error)
1219
+ worker.userError(msg.error, msg.file);
1220
+ else if (msg.results && msg.results.data) {
1221
+ var abort = function() {
1222
+ aborted = true;
1223
+ completeWorker(msg.workerId, { data: [], errors: [], meta: { aborted: true } });
1224
+ };
1225
+ var handle = {
1226
+ abort,
1227
+ pause: notImplemented,
1228
+ resume: notImplemented
1229
+ };
1230
+ if (isFunction(worker.userStep)) {
1231
+ for (var i = 0; i < msg.results.data.length; i++) {
1232
+ worker.userStep({
1233
+ data: msg.results.data[i],
1234
+ errors: msg.results.errors,
1235
+ meta: msg.results.meta
1236
+ }, handle);
1237
+ if (aborted)
1238
+ break;
1239
+ }
1240
+ delete msg.results;
1241
+ } else if (isFunction(worker.userChunk)) {
1242
+ worker.userChunk(msg.results, handle, msg.file);
1243
+ delete msg.results;
1244
+ }
1245
+ }
1246
+ if (msg.finished && !aborted)
1247
+ completeWorker(msg.workerId, msg.results);
1248
+ }
1249
+ function completeWorker(workerId, results) {
1250
+ var worker = workers[workerId];
1251
+ if (isFunction(worker.userComplete))
1252
+ worker.userComplete(results);
1253
+ worker.terminate();
1254
+ delete workers[workerId];
1255
+ }
1256
+ function notImplemented() {
1257
+ throw new Error("Not implemented.");
1258
+ }
1259
+ function workerThreadReceivedMessage(e) {
1260
+ var msg = e.data;
1261
+ if (typeof Papa2.WORKER_ID === "undefined" && msg)
1262
+ Papa2.WORKER_ID = msg.workerId;
1263
+ if (typeof msg.input === "string") {
1264
+ global.postMessage({
1265
+ workerId: Papa2.WORKER_ID,
1266
+ results: Papa2.parse(msg.input, msg.config),
1267
+ finished: true
1268
+ });
1269
+ } else if (global.File && msg.input instanceof File || msg.input instanceof Object) {
1270
+ var results = Papa2.parse(msg.input, msg.config);
1271
+ if (results)
1272
+ global.postMessage({
1273
+ workerId: Papa2.WORKER_ID,
1274
+ results,
1275
+ finished: true
1276
+ });
1277
+ }
1278
+ }
1279
+ function copy(obj) {
1280
+ if (typeof obj !== "object" || obj === null)
1281
+ return obj;
1282
+ var cpy = Array.isArray(obj) ? [] : {};
1283
+ for (var key in obj)
1284
+ cpy[key] = copy(obj[key]);
1285
+ return cpy;
1286
+ }
1287
+ function bindFunction(f, self2) {
1288
+ return function() {
1289
+ f.apply(self2, arguments);
1290
+ };
1291
+ }
1292
+ function isFunction(func) {
1293
+ return typeof func === "function";
1294
+ }
1295
+ return Papa2;
1296
+ });
1297
+ })(papaparse$2);
1298
+ return papaparse$2.exports;
1299
+ }
1300
+ var papaparseExports = requirePapaparse();
1301
+ const Papa = /* @__PURE__ */ getDefaultExportFromCjs(papaparseExports);
1302
+ const papaparse = /* @__PURE__ */ _mergeNamespaces({
1303
+ __proto__: null,
1304
+ default: Papa
1305
+ }, [papaparseExports]);
1306
+ export {
1307
+ Papa as P,
1308
+ papaparse as p
1309
+ };