@bigbinary/neeto-molecules 5.1.18 → 5.1.20

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