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