@lingk/sync 0.1.80 → 0.1.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/main.js CHANGED
@@ -355,7 +355,7 @@ module.exports =
355
355
  joinKeyResourceName = rsc.joinKeyResource;
356
356
 
357
357
  // joinKeyName coming from field on this resource
358
- if (rsc.resourceLabel === rsc.joinKeyResource) {
358
+ if (rsc.resourceName === rsc.joinKeyResource) {
359
359
  var joinKeyResource = dataSourceMetadata.find(function (r) {
360
360
  return r.type === rsc.joinKeyResource;
361
361
  });
@@ -400,9 +400,7 @@ module.exports =
400
400
  joinType: rsc.joinType || 'LEFT JOIN'
401
401
  }, rscResource.parentRef && { parentRef: rscResource.parentRef }, rsc.parameterFilters && { parameterFilters: rsc.parameterFilters }, {
402
402
  level: rsc.level || (rscIndex === 0 ? 0 : 1)
403
- }, primaryKeyResourceName && {
404
- parentNameAndProvider: primaryKeyResourceName + '_' + resourceProvider
405
- }));
403
+ }, rsc.parentNameAndProvider && { parentNameAndProvider: rsc.parentNameAndProvider }));
406
404
  }
407
405
  }); // end bundle.resource.forEach
408
406
 
@@ -801,7 +799,7 @@ module.exports =
801
799
  isSelected = selectedValues && selectedValues.length > 0 && selectedValues.some(function (rsc) {
802
800
  return rsc[fieldPropLabel] === entity[fieldPropLabel] && (!(parents && rsc.parents) || JSON.stringify(rsc.parents) === JSON.stringify(parents)) && (!rsc.section || sectionLabel === rsc.section);
803
801
  });
804
-
802
+ //console.log(entity.name)
805
803
  sectionValues.push(Object.assign({}, entity, {
806
804
  title: title,
807
805
  section: sectionLabel,
@@ -819,11 +817,11 @@ module.exports =
819
817
  return sectionValues;
820
818
  }.bind(this);
821
819
 
822
- var vals = [].concat(_toConsumableArray(values));
820
+ var vals = values && [].concat(_toConsumableArray(values));
823
821
  if (sectionLabels) {
824
822
  var v = [];
825
823
  sectionLabels.forEach(function (s, i) {
826
- if (values[i] && values[i].length > 0) {
824
+ if (values && values[i] && values[i].length > 0) {
827
825
  (function () {
828
826
  v = v.concat(sectionLabels[i]);
829
827
  var sectionValues = [];
@@ -838,7 +836,7 @@ module.exports =
838
836
  } else {
839
837
  (function () {
840
838
  var sectionValues = [];
841
- values.forEach(function (entity) {
839
+ values && values.forEach(function (entity) {
842
840
  iterator(sectionValues, entity, '', 0, []);
843
841
  });
844
842
  vals = sectionValues;
@@ -1529,7 +1527,7 @@ module.exports =
1529
1527
  } else {
1530
1528
  // By explicitly using `prop-types` you are opting into new production behavior.
1531
1529
  // http://fb.me/prop-types-in-prod
1532
- module.exports = __webpack_require__(177)();
1530
+ module.exports = __webpack_require__(178)();
1533
1531
  }
1534
1532
 
1535
1533
 
@@ -1551,11 +1549,11 @@ module.exports =
1551
1549
 
1552
1550
  var _propTypes2 = _interopRequireDefault(_propTypes);
1553
1551
 
1554
- var _TransitionGroup = __webpack_require__(205);
1552
+ var _TransitionGroup = __webpack_require__(206);
1555
1553
 
1556
1554
  var _TransitionGroup2 = _interopRequireDefault(_TransitionGroup);
1557
1555
 
1558
- var _CSSTransitionGroupChild = __webpack_require__(204);
1556
+ var _CSSTransitionGroupChild = __webpack_require__(205);
1559
1557
 
1560
1558
  var _CSSTransitionGroupChild2 = _interopRequireDefault(_CSSTransitionGroupChild);
1561
1559
 
@@ -5104,6 +5102,7 @@ module.exports =
5104
5102
  value: true
5105
5103
  });
5106
5104
  exports.callGetMetadata = callGetMetadata;
5105
+ exports.setCsvFields = setCsvFields;
5107
5106
  exports.tryCheckConnection = tryCheckConnection;
5108
5107
  exports.callGetProviderMetadata = callGetProviderMetadata;
5109
5108
  exports.getOauthUrl = getOauthUrl;
@@ -5192,6 +5191,13 @@ module.exports =
5192
5191
  };
5193
5192
  }
5194
5193
 
5194
+ function setCsvFields(metadata, mode, providerType) {
5195
+ return {
5196
+ type: types.FINISH_WIZARD_ENV_CHECK,
5197
+ data: { metadata: metadata, mode: mode, code: '200 OK', providerType: providerType }
5198
+ };
5199
+ }
5200
+
5195
5201
  // "fake" credentials for demo purposes
5196
5202
  function isDemoCreds(creds, providerType) {
5197
5203
  if (creds && providerType) {
@@ -6863,16 +6869,22 @@ module.exports =
6863
6869
 
6864
6870
  var _reduxForm = __webpack_require__(2);
6865
6871
 
6866
- var _reactDropzone = __webpack_require__(202);
6872
+ var _reactDropzone = __webpack_require__(203);
6867
6873
 
6868
6874
  var _reactDropzone2 = _interopRequireDefault(_reactDropzone);
6869
6875
 
6876
+ var _papaparse = __webpack_require__(177);
6877
+
6878
+ var _papaparse2 = _interopRequireDefault(_papaparse);
6879
+
6870
6880
  var _clipboard = __webpack_require__(122);
6871
6881
 
6872
6882
  var _clipboard2 = _interopRequireDefault(_clipboard);
6873
6883
 
6874
6884
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6875
6885
 
6886
+ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
6887
+
6876
6888
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6877
6889
 
6878
6890
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -6892,23 +6904,10 @@ module.exports =
6892
6904
  checking = props.checking,
6893
6905
  generateNewAdapterSecret = props.generateNewAdapterSecret,
6894
6906
  tenantKey = props.tenantKey,
6895
- accountKey = props.accountKey;
6907
+ accountKey = props.accountKey,
6908
+ setCsvFields = props.setCsvFields;
6896
6909
 
6897
6910
 
6898
- if (config.skipEnvStep) return _react2.default.createElement(
6899
- 'div',
6900
- { className: 'env-section-body', style: { paddingBottom: 11 } },
6901
- wizard[mode + 'Metadata'] ? _react2.default.createElement(
6902
- 'span',
6903
- null,
6904
- 'Your Salesforce Org is connected. Click Inspect to explore your available Salesforce resources.'
6905
- ) : _react2.default.createElement(
6906
- 'span',
6907
- null,
6908
- 'Your Salesforce Org is not connected. Please revoke all Oauth grants and reauthorize this managed package.'
6909
- )
6910
- );
6911
-
6912
6911
  var Button = inputs.Button;
6913
6912
  var Spinner = inputs.Spinner;
6914
6913
 
@@ -6960,7 +6959,7 @@ module.exports =
6960
6959
  return getOauthUrl(urlType, mode);
6961
6960
  },
6962
6961
  mode: mode, inputs: inputs, checking: checking }) : isSFTP ? _react2.default.createElement(SFTP, { step: step, wizard: wizard, onCheck: check,
6963
- mode: mode, checking: checking }) : _react2.default.createElement(
6962
+ mode: mode, checking: checking, setCsvFields: setCsvFields }) : _react2.default.createElement(
6964
6963
  'div',
6965
6964
  null,
6966
6965
  _react2.default.createElement(
@@ -7051,6 +7050,9 @@ module.exports =
7051
7050
  var SFTP = function (_Component) {
7052
7051
  _inherits(SFTP, _Component);
7053
7052
 
7053
+ // react-dropzone
7054
+ // papaparse
7055
+
7054
7056
  function SFTP() {
7055
7057
  _classCallCheck(this, SFTP);
7056
7058
 
@@ -7064,9 +7066,42 @@ module.exports =
7064
7066
 
7065
7067
  _createClass(SFTP, [{
7066
7068
  key: 'onDrop',
7067
- value: function onDrop(files) {
7068
- console.log(files);
7069
- this.setState({ files: files });
7069
+ value: function onDrop(fs) {
7070
+ var _this2 = this;
7071
+
7072
+ var _props = this.props,
7073
+ setCsvFields = _props.setCsvFields,
7074
+ mode = _props.mode,
7075
+ step = _props.step,
7076
+ wizard = _props.wizard;
7077
+
7078
+ var m = wizard[mode + 'Metadata'] || [];
7079
+ var files = [].concat(_toConsumableArray(this.state.files));
7080
+ var counter = 0;
7081
+ fs.forEach(function (file) {
7082
+ _papaparse2.default.parse(file, {
7083
+ header: true,
7084
+ complete: function complete(result) {
7085
+ m = m.concat({
7086
+ name: file.name.split('.')[0],
7087
+ type: file.name.split('.')[0],
7088
+ properties: result.meta.fields.map(function (f) {
7089
+ return {
7090
+ label: f,
7091
+ name: f,
7092
+ type: 'string'
7093
+ };
7094
+ })
7095
+ });
7096
+ files = files.concat(file);
7097
+ counter += 1;
7098
+ if (counter === fs.length) {
7099
+ _this2.setState({ files: files });
7100
+ setCsvFields(m, mode, step[mode + 'Provider']);
7101
+ }
7102
+ }
7103
+ });
7104
+ });
7070
7105
  }
7071
7106
  }, {
7072
7107
  key: 'render',
@@ -7091,9 +7126,9 @@ module.exports =
7091
7126
  )
7092
7127
  )
7093
7128
  ),
7094
- _react2.default.createElement(
7129
+ files && files.length > 0 && _react2.default.createElement(
7095
7130
  'aside',
7096
- { style: { marginLeft: 30 } },
7131
+ { style: { marginLeft: 30, display: 'inline-block' } },
7097
7132
  _react2.default.createElement(
7098
7133
  'h3',
7099
7134
  { style: { marginTop: 10 } },
@@ -7102,10 +7137,10 @@ module.exports =
7102
7137
  _react2.default.createElement(
7103
7138
  'ul',
7104
7139
  null,
7105
- files.map(function (f) {
7140
+ files.map(function (f, i) {
7106
7141
  return _react2.default.createElement(
7107
7142
  'li',
7108
- { key: f.name },
7143
+ { key: i },
7109
7144
  f.name,
7110
7145
  ' - ',
7111
7146
  f.size,
@@ -7254,42 +7289,42 @@ module.exports =
7254
7289
  function AdapterSecret() {
7255
7290
  _classCallCheck(this, AdapterSecret);
7256
7291
 
7257
- var _this2 = _possibleConstructorReturn(this, (AdapterSecret.__proto__ || Object.getPrototypeOf(AdapterSecret)).call(this));
7292
+ var _this3 = _possibleConstructorReturn(this, (AdapterSecret.__proto__ || Object.getPrototypeOf(AdapterSecret)).call(this));
7258
7293
 
7259
- _this2.copy = function () {
7260
- var _this2$props = _this2.props,
7261
- wizard = _this2$props.wizard,
7262
- mode = _this2$props.mode;
7294
+ _this3.copy = function () {
7295
+ var _this3$props = _this3.props,
7296
+ wizard = _this3$props.wizard,
7297
+ mode = _this3$props.mode;
7263
7298
 
7264
7299
  var secret = wizard.savedCredentials && wizard.savedCredentials[mode + 'AdapterSecret'];
7265
7300
  _clipboard2.default.copy({
7266
7301
  'text/plain': secret.credentials
7267
7302
  });
7268
- _this2.setState({ secretCopied: true });
7303
+ _this3.setState({ secretCopied: true });
7269
7304
  setTimeout(function () {
7270
- _this2.setState({ secretCopied: false });
7305
+ _this3.setState({ secretCopied: false });
7271
7306
  }, 4000);
7272
7307
  };
7273
7308
 
7274
- _this2.state = {
7309
+ _this3.state = {
7275
7310
  generating: false,
7276
7311
  secretCopied: false
7277
7312
  };
7278
- return _this2;
7313
+ return _this3;
7279
7314
  }
7280
7315
 
7281
7316
  _createClass(AdapterSecret, [{
7282
7317
  key: 'render',
7283
7318
  value: function render() {
7284
- var _this3 = this;
7319
+ var _this4 = this;
7285
7320
 
7286
- var _props = this.props,
7287
- wizard = _props.wizard,
7288
- mode = _props.mode,
7289
- inputs = _props.inputs,
7290
- generateNewAdapterSecret = _props.generateNewAdapterSecret,
7291
- tenantKey = _props.tenantKey,
7292
- accountKey = _props.accountKey;
7321
+ var _props2 = this.props,
7322
+ wizard = _props2.wizard,
7323
+ mode = _props2.mode,
7324
+ inputs = _props2.inputs,
7325
+ generateNewAdapterSecret = _props2.generateNewAdapterSecret,
7326
+ tenantKey = _props2.tenantKey,
7327
+ accountKey = _props2.accountKey;
7293
7328
 
7294
7329
  var secret = wizard.savedCredentials && wizard.savedCredentials[mode + 'AdapterSecret'];
7295
7330
  var Button = inputs.Button;
@@ -7357,7 +7392,7 @@ module.exports =
7357
7392
  icon: 'sync',
7358
7393
  iconAlign: 'left',
7359
7394
  onClick: function onClick() {
7360
- _this3.setState({ generating: true });
7395
+ _this4.setState({ generating: true });
7361
7396
  generateNewAdapterSecret(mode);
7362
7397
  },
7363
7398
  style: { margin: '0 8px', marginBottom: 2, height: 30, lineHeight: '10px' } },
@@ -7378,12 +7413,12 @@ module.exports =
7378
7413
  function CustomSalesforceSettings() {
7379
7414
  _classCallCheck(this, CustomSalesforceSettings);
7380
7415
 
7381
- var _this4 = _possibleConstructorReturn(this, (CustomSalesforceSettings.__proto__ || Object.getPrototypeOf(CustomSalesforceSettings)).call(this));
7416
+ var _this5 = _possibleConstructorReturn(this, (CustomSalesforceSettings.__proto__ || Object.getPrototypeOf(CustomSalesforceSettings)).call(this));
7382
7417
 
7383
- _this4.state = {
7418
+ _this5.state = {
7384
7419
  custom: false
7385
7420
  };
7386
- return _this4;
7421
+ return _this5;
7387
7422
  }
7388
7423
 
7389
7424
  _createClass(CustomSalesforceSettings, [{
@@ -7398,7 +7433,7 @@ module.exports =
7398
7433
  }, {
7399
7434
  key: 'render',
7400
7435
  value: function render() {
7401
- var _this5 = this;
7436
+ var _this6 = this;
7402
7437
 
7403
7438
  var inputs = this.props.inputs;
7404
7439
  var Radio = inputs.Radio;
@@ -7414,7 +7449,7 @@ module.exports =
7414
7449
  ),
7415
7450
  _react2.default.createElement('br', null),
7416
7451
  _react2.default.createElement(Radio, { onChange: function onChange() {
7417
- return _this5.setState({ custom: false });
7452
+ return _this6.setState({ custom: false });
7418
7453
  },
7419
7454
  label: 'Default Batch Size (10,000)',
7420
7455
  checked: this.state.custom === false,
@@ -7422,7 +7457,7 @@ module.exports =
7422
7457
  }),
7423
7458
  _react2.default.createElement('br', null),
7424
7459
  _react2.default.createElement(Radio, { onChange: function onChange() {
7425
- return _this5.setState({ custom: true });
7460
+ return _this6.setState({ custom: true });
7426
7461
  },
7427
7462
  label: 'Custom Batch Size',
7428
7463
  checked: this.state.custom === true,
@@ -8941,7 +8976,8 @@ module.exports =
8941
8976
  fieldPropLabel: 'label',
8942
8977
  selectedValues: [{
8943
8978
  label: rsc.primaryKeyName,
8944
- parents: rsc.primaryKeyParents
8979
+ parents: rsc.primaryKeyParents,
8980
+ section: rsc.primaryKeyResource
8945
8981
  }],
8946
8982
  sectionLabelSuffix: 'Fields'
8947
8983
  })
@@ -9904,11 +9940,11 @@ module.exports =
9904
9940
 
9905
9941
  var _moment2 = _interopRequireDefault(_moment);
9906
9942
 
9907
- __webpack_require__(213);
9943
+ __webpack_require__(214);
9908
9944
 
9909
9945
  __webpack_require__(172);
9910
9946
 
9911
- var _rcTimePicker = __webpack_require__(193);
9947
+ var _rcTimePicker = __webpack_require__(194);
9912
9948
 
9913
9949
  var _rcTimePicker2 = _interopRequireDefault(_rcTimePicker);
9914
9950
 
@@ -10399,9 +10435,13 @@ module.exports =
10399
10435
  formValues = _props8.formValues;
10400
10436
 
10401
10437
  var envName = formValues['environment'];
10402
- console.log('gen gen', mode);
10403
10438
  actions.generateNewAdapterSecret(tenantId, accountId, envName, mode);
10404
10439
  }
10440
+ }, {
10441
+ key: 'setCsvFields',
10442
+ value: function setCsvFields(metadata, mode, providerType) {
10443
+ this.props.actions.setCsvFields(metadata, mode, providerType);
10444
+ }
10405
10445
  }, {
10406
10446
  key: 'render',
10407
10447
  value: function render() {
@@ -10571,7 +10611,8 @@ module.exports =
10571
10611
  generateNewAdapterSecret: _this5.generateNewAdapterSecret.bind(_this5),
10572
10612
  clickDirection: _this5.clickDirection.bind(_this5),
10573
10613
  seeFields: _this5.seeFields.bind(_this5), check: _this5.check,
10574
- tenantKey: tenantKey, accountKey: accountKey })
10614
+ tenantKey: tenantKey, accountKey: accountKey,
10615
+ setCsvFields: _this5.setCsvFields.bind(_this5) })
10575
10616
  )
10576
10617
  )
10577
10618
  );
@@ -12406,6 +12447,8 @@ module.exports =
12406
12447
  _createClass(SchemaStep, [{
12407
12448
  key: 'componentDidMount',
12408
12449
  value: function componentDidMount() {
12450
+ var _this2 = this;
12451
+
12409
12452
  var _props = this.props,
12410
12453
  step = _props.step,
12411
12454
  wizard = _props.wizard,
@@ -12417,6 +12460,10 @@ module.exports =
12417
12460
  if (!wizard.dataLoaded) {
12418
12461
  (0, _loadData2.default)(step, wizard, change, formValues, actions, isReverse);
12419
12462
  }
12463
+ var resourceGroups = [].concat(_toConsumableArray(formValues['resourceGroups']));
12464
+ resourceGroups.forEach(function (rg, i) {
12465
+ _this2.assignAllParents(i);
12466
+ });
12420
12467
  }
12421
12468
  }, {
12422
12469
  key: 'openConnectionModal',
@@ -12637,6 +12684,8 @@ module.exports =
12637
12684
  break;
12638
12685
  }
12639
12686
  }
12687
+ console.log(eachR.parentNameAndProvider);
12688
+ //console.log(`${newParent}_${newParentProvider}`.toLowerCase())
12640
12689
  if (newParent && newParentProvider && (newParent + '_' + newParentProvider).toLowerCase() !== (eachR.parentNameAndProvider && eachR.parentNameAndProvider.toLowerCase())) {
12641
12690
  eachR.primaryKeyResource = newParent;
12642
12691
  eachR.parentNameAndProvider = newParent + '_' + newParentProvider;
@@ -12714,7 +12763,7 @@ module.exports =
12714
12763
  }, {
12715
12764
  key: 'render',
12716
12765
  value: function render() {
12717
- var _this2 = this;
12766
+ var _this3 = this;
12718
12767
 
12719
12768
  var _props14 = this.props,
12720
12769
  inputs = _props14.inputs,
@@ -12804,7 +12853,7 @@ module.exports =
12804
12853
  bundleIndex: this.state.selectedBundleIndex,
12805
12854
  sourceSchema: sourceSchema, destinationSchema: destinationSchema,
12806
12855
  update: function update() {
12807
- return _this2.forceUpdate();
12856
+ return _this3.forceUpdate();
12808
12857
  },
12809
12858
  direction: formValues.direction
12810
12859
  })
@@ -13959,7 +14008,7 @@ module.exports =
13959
14008
 
13960
14009
  var _react2 = _interopRequireDefault(_react);
13961
14010
 
13962
- var _redux = __webpack_require__(214);
14011
+ var _redux = __webpack_require__(215);
13963
14012
 
13964
14013
  var _reactRedux = __webpack_require__(65);
13965
14014
 
@@ -15501,6 +15550,1601 @@ module.exports =
15501
15550
 
15502
15551
  /***/ },
15503
15552
  /* 177 */
15553
+ /***/ function(module, exports, __webpack_require__) {
15554
+
15555
+ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
15556
+ Papa Parse
15557
+ v4.3.6
15558
+ https://github.com/mholt/PapaParse
15559
+ License: MIT
15560
+ */
15561
+ (function(root, factory)
15562
+ {
15563
+ if (true)
15564
+ {
15565
+ // AMD. Register as an anonymous module.
15566
+ !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
15567
+ }
15568
+ else if (typeof module === 'object' && typeof exports !== 'undefined')
15569
+ {
15570
+ // Node. Does not work with strict CommonJS, but
15571
+ // only CommonJS-like environments that support module.exports,
15572
+ // like Node.
15573
+ module.exports = factory();
15574
+ }
15575
+ else
15576
+ {
15577
+ // Browser globals (root is window)
15578
+ root.Papa = factory();
15579
+ }
15580
+ }(this, function()
15581
+ {
15582
+ 'use strict';
15583
+
15584
+ var global = (function () {
15585
+ // alternative method, similar to `Function('return this')()`
15586
+ // but without using `eval` (which is disabled when
15587
+ // using Content Security Policy).
15588
+
15589
+ if (typeof self !== 'undefined') { return self; }
15590
+ if (typeof window !== 'undefined') { return window; }
15591
+ if (typeof global !== 'undefined') { return global; }
15592
+
15593
+ // When running tests none of the above have been defined
15594
+ return {};
15595
+ })();
15596
+
15597
+
15598
+ var IS_WORKER = !global.document && !!global.postMessage,
15599
+ IS_PAPA_WORKER = IS_WORKER && /(\?|&)papaworker(=|&|$)/.test(global.location.search),
15600
+ LOADED_SYNC = false, AUTO_SCRIPT_PATH;
15601
+ var workers = {}, workerIdCounter = 0;
15602
+
15603
+ var Papa = {};
15604
+
15605
+ Papa.parse = CsvToJson;
15606
+ Papa.unparse = JsonToCsv;
15607
+
15608
+ Papa.RECORD_SEP = String.fromCharCode(30);
15609
+ Papa.UNIT_SEP = String.fromCharCode(31);
15610
+ Papa.BYTE_ORDER_MARK = '\ufeff';
15611
+ Papa.BAD_DELIMITERS = ['\r', '\n', '"', Papa.BYTE_ORDER_MARK];
15612
+ Papa.WORKERS_SUPPORTED = !IS_WORKER && !!global.Worker;
15613
+ Papa.SCRIPT_PATH = null; // Must be set by your code if you use workers and this lib is loaded asynchronously
15614
+
15615
+ // Configurable chunk sizes for local and remote files, respectively
15616
+ Papa.LocalChunkSize = 1024 * 1024 * 10; // 10 MB
15617
+ Papa.RemoteChunkSize = 1024 * 1024 * 5; // 5 MB
15618
+ Papa.DefaultDelimiter = ','; // Used if not specified and detection fails
15619
+
15620
+ // Exposed for testing and development only
15621
+ Papa.Parser = Parser;
15622
+ Papa.ParserHandle = ParserHandle;
15623
+ Papa.NetworkStreamer = NetworkStreamer;
15624
+ Papa.FileStreamer = FileStreamer;
15625
+ Papa.StringStreamer = StringStreamer;
15626
+ Papa.ReadableStreamStreamer = ReadableStreamStreamer;
15627
+
15628
+ if (global.jQuery)
15629
+ {
15630
+ var $ = global.jQuery;
15631
+ $.fn.parse = function(options)
15632
+ {
15633
+ var config = options.config || {};
15634
+ var queue = [];
15635
+
15636
+ this.each(function(idx)
15637
+ {
15638
+ var supported = $(this).prop('tagName').toUpperCase() === 'INPUT'
15639
+ && $(this).attr('type').toLowerCase() === 'file'
15640
+ && global.FileReader;
15641
+
15642
+ if (!supported || !this.files || this.files.length === 0)
15643
+ return true; // continue to next input element
15644
+
15645
+ for (var i = 0; i < this.files.length; i++)
15646
+ {
15647
+ queue.push({
15648
+ file: this.files[i],
15649
+ inputElem: this,
15650
+ instanceConfig: $.extend({}, config)
15651
+ });
15652
+ }
15653
+ });
15654
+
15655
+ parseNextFile(); // begin parsing
15656
+ return this; // maintains chainability
15657
+
15658
+
15659
+ function parseNextFile()
15660
+ {
15661
+ if (queue.length === 0)
15662
+ {
15663
+ if (isFunction(options.complete))
15664
+ options.complete();
15665
+ return;
15666
+ }
15667
+
15668
+ var f = queue[0];
15669
+
15670
+ if (isFunction(options.before))
15671
+ {
15672
+ var returned = options.before(f.file, f.inputElem);
15673
+
15674
+ if (typeof returned === 'object')
15675
+ {
15676
+ if (returned.action === 'abort')
15677
+ {
15678
+ error('AbortError', f.file, f.inputElem, returned.reason);
15679
+ return; // Aborts all queued files immediately
15680
+ }
15681
+ else if (returned.action === 'skip')
15682
+ {
15683
+ fileComplete(); // parse the next file in the queue, if any
15684
+ return;
15685
+ }
15686
+ else if (typeof returned.config === 'object')
15687
+ f.instanceConfig = $.extend(f.instanceConfig, returned.config);
15688
+ }
15689
+ else if (returned === 'skip')
15690
+ {
15691
+ fileComplete(); // parse the next file in the queue, if any
15692
+ return;
15693
+ }
15694
+ }
15695
+
15696
+ // Wrap up the user's complete callback, if any, so that ours also gets executed
15697
+ var userCompleteFunc = f.instanceConfig.complete;
15698
+ f.instanceConfig.complete = function(results)
15699
+ {
15700
+ if (isFunction(userCompleteFunc))
15701
+ userCompleteFunc(results, f.file, f.inputElem);
15702
+ fileComplete();
15703
+ };
15704
+
15705
+ Papa.parse(f.file, f.instanceConfig);
15706
+ }
15707
+
15708
+ function error(name, file, elem, reason)
15709
+ {
15710
+ if (isFunction(options.error))
15711
+ options.error({name: name}, file, elem, reason);
15712
+ }
15713
+
15714
+ function fileComplete()
15715
+ {
15716
+ queue.splice(0, 1);
15717
+ parseNextFile();
15718
+ }
15719
+ }
15720
+ }
15721
+
15722
+
15723
+ if (IS_PAPA_WORKER)
15724
+ {
15725
+ global.onmessage = workerThreadReceivedMessage;
15726
+ }
15727
+ else if (Papa.WORKERS_SUPPORTED)
15728
+ {
15729
+ AUTO_SCRIPT_PATH = getScriptPath();
15730
+
15731
+ // Check if the script was loaded synchronously
15732
+ if (!document.body)
15733
+ {
15734
+ // Body doesn't exist yet, must be synchronous
15735
+ LOADED_SYNC = true;
15736
+ }
15737
+ else
15738
+ {
15739
+ document.addEventListener('DOMContentLoaded', function () {
15740
+ LOADED_SYNC = true;
15741
+ }, true);
15742
+ }
15743
+ }
15744
+
15745
+
15746
+
15747
+
15748
+ function CsvToJson(_input, _config)
15749
+ {
15750
+ _config = _config || {};
15751
+ var dynamicTyping = _config.dynamicTyping || false;
15752
+ if (isFunction(dynamicTyping)) {
15753
+ _config.dynamicTypingFunction = dynamicTyping;
15754
+ // Will be filled on first row call
15755
+ dynamicTyping = {};
15756
+ }
15757
+ _config.dynamicTyping = dynamicTyping;
15758
+
15759
+ if (_config.worker && Papa.WORKERS_SUPPORTED)
15760
+ {
15761
+ var w = newWorker();
15762
+
15763
+ w.userStep = _config.step;
15764
+ w.userChunk = _config.chunk;
15765
+ w.userComplete = _config.complete;
15766
+ w.userError = _config.error;
15767
+
15768
+ _config.step = isFunction(_config.step);
15769
+ _config.chunk = isFunction(_config.chunk);
15770
+ _config.complete = isFunction(_config.complete);
15771
+ _config.error = isFunction(_config.error);
15772
+ delete _config.worker; // prevent infinite loop
15773
+
15774
+ w.postMessage({
15775
+ input: _input,
15776
+ config: _config,
15777
+ workerId: w.id
15778
+ });
15779
+
15780
+ return;
15781
+ }
15782
+
15783
+ var streamer = null;
15784
+ if (typeof _input === 'string')
15785
+ {
15786
+ if (_config.download)
15787
+ streamer = new NetworkStreamer(_config);
15788
+ else
15789
+ streamer = new StringStreamer(_config);
15790
+ }
15791
+ else if (_input.readable === true && isFunction(_input.read) && isFunction(_input.on))
15792
+ {
15793
+ streamer = new ReadableStreamStreamer(_config);
15794
+ }
15795
+ else if ((global.File && _input instanceof File) || _input instanceof Object) // ...Safari. (see issue #106)
15796
+ streamer = new FileStreamer(_config);
15797
+
15798
+ return streamer.stream(_input);
15799
+ }
15800
+
15801
+
15802
+
15803
+
15804
+
15805
+
15806
+ function JsonToCsv(_input, _config)
15807
+ {
15808
+ var _output = '';
15809
+ var _fields = [];
15810
+
15811
+ // Default configuration
15812
+
15813
+ /** whether to surround every datum with quotes */
15814
+ var _quotes = false;
15815
+
15816
+ /** whether to write headers */
15817
+ var _writeHeader = true;
15818
+
15819
+ /** delimiting character */
15820
+ var _delimiter = ',';
15821
+
15822
+ /** newline character(s) */
15823
+ var _newline = '\r\n';
15824
+
15825
+ /** quote character */
15826
+ var _quoteChar = '"';
15827
+
15828
+ unpackConfig();
15829
+
15830
+ var quoteCharRegex = new RegExp(_quoteChar, 'g');
15831
+
15832
+ if (typeof _input === 'string')
15833
+ _input = JSON.parse(_input);
15834
+
15835
+ if (_input instanceof Array)
15836
+ {
15837
+ if (!_input.length || _input[0] instanceof Array)
15838
+ return serialize(null, _input);
15839
+ else if (typeof _input[0] === 'object')
15840
+ return serialize(objectKeys(_input[0]), _input);
15841
+ }
15842
+ else if (typeof _input === 'object')
15843
+ {
15844
+ if (typeof _input.data === 'string')
15845
+ _input.data = JSON.parse(_input.data);
15846
+
15847
+ if (_input.data instanceof Array)
15848
+ {
15849
+ if (!_input.fields)
15850
+ _input.fields = _input.meta && _input.meta.fields;
15851
+
15852
+ if (!_input.fields)
15853
+ _input.fields = _input.data[0] instanceof Array
15854
+ ? _input.fields
15855
+ : objectKeys(_input.data[0]);
15856
+
15857
+ if (!(_input.data[0] instanceof Array) && typeof _input.data[0] !== 'object')
15858
+ _input.data = [_input.data]; // handles input like [1,2,3] or ['asdf']
15859
+ }
15860
+
15861
+ return serialize(_input.fields || [], _input.data || []);
15862
+ }
15863
+
15864
+ // Default (any valid paths should return before this)
15865
+ throw 'exception: Unable to serialize unrecognized input';
15866
+
15867
+
15868
+ function unpackConfig()
15869
+ {
15870
+ if (typeof _config !== 'object')
15871
+ return;
15872
+
15873
+ if (typeof _config.delimiter === 'string'
15874
+ && _config.delimiter.length === 1
15875
+ && Papa.BAD_DELIMITERS.indexOf(_config.delimiter) === -1)
15876
+ {
15877
+ _delimiter = _config.delimiter;
15878
+ }
15879
+
15880
+ if (typeof _config.quotes === 'boolean'
15881
+ || _config.quotes instanceof Array)
15882
+ _quotes = _config.quotes;
15883
+
15884
+ if (typeof _config.newline === 'string')
15885
+ _newline = _config.newline;
15886
+
15887
+ if (typeof _config.quoteChar === 'string')
15888
+ _quoteChar = _config.quoteChar;
15889
+
15890
+ if (typeof _config.header === 'boolean')
15891
+ _writeHeader = _config.header;
15892
+ }
15893
+
15894
+
15895
+ /** Turns an object's keys into an array */
15896
+ function objectKeys(obj)
15897
+ {
15898
+ if (typeof obj !== 'object')
15899
+ return [];
15900
+ var keys = [];
15901
+ for (var key in obj)
15902
+ keys.push(key);
15903
+ return keys;
15904
+ }
15905
+
15906
+ /** The double for loop that iterates the data and writes out a CSV string including header row */
15907
+ function serialize(fields, data)
15908
+ {
15909
+ var csv = '';
15910
+
15911
+ if (typeof fields === 'string')
15912
+ fields = JSON.parse(fields);
15913
+ if (typeof data === 'string')
15914
+ data = JSON.parse(data);
15915
+
15916
+ var hasHeader = fields instanceof Array && fields.length > 0;
15917
+ var dataKeyedByField = !(data[0] instanceof Array);
15918
+
15919
+ // If there a header row, write it first
15920
+ if (hasHeader && _writeHeader)
15921
+ {
15922
+ for (var i = 0; i < fields.length; i++)
15923
+ {
15924
+ if (i > 0)
15925
+ csv += _delimiter;
15926
+ csv += safe(fields[i], i);
15927
+ }
15928
+ if (data.length > 0)
15929
+ csv += _newline;
15930
+ }
15931
+
15932
+ // Then write out the data
15933
+ for (var row = 0; row < data.length; row++)
15934
+ {
15935
+ var maxCol = hasHeader ? fields.length : data[row].length;
15936
+
15937
+ for (var col = 0; col < maxCol; col++)
15938
+ {
15939
+ if (col > 0)
15940
+ csv += _delimiter;
15941
+ var colIdx = hasHeader && dataKeyedByField ? fields[col] : col;
15942
+ csv += safe(data[row][colIdx], col);
15943
+ }
15944
+
15945
+ if (row < data.length - 1)
15946
+ csv += _newline;
15947
+ }
15948
+
15949
+ return csv;
15950
+ }
15951
+
15952
+ /** Encloses a value around quotes if needed (makes a value safe for CSV insertion) */
15953
+ function safe(str, col)
15954
+ {
15955
+ if (typeof str === 'undefined' || str === null)
15956
+ return '';
15957
+
15958
+ str = str.toString().replace(quoteCharRegex, _quoteChar+_quoteChar);
15959
+
15960
+ var needsQuotes = (typeof _quotes === 'boolean' && _quotes)
15961
+ || (_quotes instanceof Array && _quotes[col])
15962
+ || hasAny(str, Papa.BAD_DELIMITERS)
15963
+ || str.indexOf(_delimiter) > -1
15964
+ || str.charAt(0) === ' '
15965
+ || str.charAt(str.length - 1) === ' ';
15966
+
15967
+ return needsQuotes ? _quoteChar + str + _quoteChar : str;
15968
+ }
15969
+
15970
+ function hasAny(str, substrings)
15971
+ {
15972
+ for (var i = 0; i < substrings.length; i++)
15973
+ if (str.indexOf(substrings[i]) > -1)
15974
+ return true;
15975
+ return false;
15976
+ }
15977
+ }
15978
+
15979
+ /** ChunkStreamer is the base prototype for various streamer implementations. */
15980
+ function ChunkStreamer(config)
15981
+ {
15982
+ this._handle = null;
15983
+ this._paused = false;
15984
+ this._finished = false;
15985
+ this._input = null;
15986
+ this._baseIndex = 0;
15987
+ this._partialLine = '';
15988
+ this._rowCount = 0;
15989
+ this._start = 0;
15990
+ this._nextChunk = null;
15991
+ this.isFirstChunk = true;
15992
+ this._completeResults = {
15993
+ data: [],
15994
+ errors: [],
15995
+ meta: {}
15996
+ };
15997
+ replaceConfig.call(this, config);
15998
+
15999
+ this.parseChunk = function(chunk)
16000
+ {
16001
+ // First chunk pre-processing
16002
+ if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk))
16003
+ {
16004
+ var modifiedChunk = this._config.beforeFirstChunk(chunk);
16005
+ if (modifiedChunk !== undefined)
16006
+ chunk = modifiedChunk;
16007
+ }
16008
+ this.isFirstChunk = false;
16009
+
16010
+ // Rejoin the line we likely just split in two by chunking the file
16011
+ var aggregate = this._partialLine + chunk;
16012
+ this._partialLine = '';
16013
+
16014
+ var results = this._handle.parse(aggregate, this._baseIndex, !this._finished);
16015
+
16016
+ if (this._handle.paused() || this._handle.aborted())
16017
+ return;
16018
+
16019
+ var lastIndex = results.meta.cursor;
16020
+
16021
+ if (!this._finished)
16022
+ {
16023
+ this._partialLine = aggregate.substring(lastIndex - this._baseIndex);
16024
+ this._baseIndex = lastIndex;
16025
+ }
16026
+
16027
+ if (results && results.data)
16028
+ this._rowCount += results.data.length;
16029
+
16030
+ var finishedIncludingPreview = this._finished || (this._config.preview && this._rowCount >= this._config.preview);
16031
+
16032
+ if (IS_PAPA_WORKER)
16033
+ {
16034
+ global.postMessage({
16035
+ results: results,
16036
+ workerId: Papa.WORKER_ID,
16037
+ finished: finishedIncludingPreview
16038
+ });
16039
+ }
16040
+ else if (isFunction(this._config.chunk))
16041
+ {
16042
+ this._config.chunk(results, this._handle);
16043
+ if (this._paused)
16044
+ return;
16045
+ results = undefined;
16046
+ this._completeResults = undefined;
16047
+ }
16048
+
16049
+ if (!this._config.step && !this._config.chunk) {
16050
+ this._completeResults.data = this._completeResults.data.concat(results.data);
16051
+ this._completeResults.errors = this._completeResults.errors.concat(results.errors);
16052
+ this._completeResults.meta = results.meta;
16053
+ }
16054
+
16055
+ if (finishedIncludingPreview && isFunction(this._config.complete) && (!results || !results.meta.aborted))
16056
+ this._config.complete(this._completeResults, this._input);
16057
+
16058
+ if (!finishedIncludingPreview && (!results || !results.meta.paused))
16059
+ this._nextChunk();
16060
+
16061
+ return results;
16062
+ };
16063
+
16064
+ this._sendError = function(error)
16065
+ {
16066
+ if (isFunction(this._config.error))
16067
+ this._config.error(error);
16068
+ else if (IS_PAPA_WORKER && this._config.error)
16069
+ {
16070
+ global.postMessage({
16071
+ workerId: Papa.WORKER_ID,
16072
+ error: error,
16073
+ finished: false
16074
+ });
16075
+ }
16076
+ };
16077
+
16078
+ function replaceConfig(config)
16079
+ {
16080
+ // Deep-copy the config so we can edit it
16081
+ var configCopy = copy(config);
16082
+ configCopy.chunkSize = parseInt(configCopy.chunkSize); // parseInt VERY important so we don't concatenate strings!
16083
+ if (!config.step && !config.chunk)
16084
+ configCopy.chunkSize = null; // disable Range header if not streaming; bad values break IIS - see issue #196
16085
+ this._handle = new ParserHandle(configCopy);
16086
+ this._handle.streamer = this;
16087
+ this._config = configCopy; // persist the copy to the caller
16088
+ }
16089
+ }
16090
+
16091
+
16092
+ function NetworkStreamer(config)
16093
+ {
16094
+ config = config || {};
16095
+ if (!config.chunkSize)
16096
+ config.chunkSize = Papa.RemoteChunkSize;
16097
+ ChunkStreamer.call(this, config);
16098
+
16099
+ var xhr;
16100
+
16101
+ if (IS_WORKER)
16102
+ {
16103
+ this._nextChunk = function()
16104
+ {
16105
+ this._readChunk();
16106
+ this._chunkLoaded();
16107
+ };
16108
+ }
16109
+ else
16110
+ {
16111
+ this._nextChunk = function()
16112
+ {
16113
+ this._readChunk();
16114
+ };
16115
+ }
16116
+
16117
+ this.stream = function(url)
16118
+ {
16119
+ this._input = url;
16120
+ this._nextChunk(); // Starts streaming
16121
+ };
16122
+
16123
+ this._readChunk = function()
16124
+ {
16125
+ if (this._finished)
16126
+ {
16127
+ this._chunkLoaded();
16128
+ return;
16129
+ }
16130
+
16131
+ xhr = new XMLHttpRequest();
16132
+
16133
+ if (this._config.withCredentials)
16134
+ {
16135
+ xhr.withCredentials = this._config.withCredentials;
16136
+ }
16137
+
16138
+ if (!IS_WORKER)
16139
+ {
16140
+ xhr.onload = bindFunction(this._chunkLoaded, this);
16141
+ xhr.onerror = bindFunction(this._chunkError, this);
16142
+ }
16143
+
16144
+ xhr.open('GET', this._input, !IS_WORKER);
16145
+ // Headers can only be set when once the request state is OPENED
16146
+ if (this._config.downloadRequestHeaders)
16147
+ {
16148
+ var headers = this._config.downloadRequestHeaders;
16149
+
16150
+ for (var headerName in headers)
16151
+ {
16152
+ xhr.setRequestHeader(headerName, headers[headerName]);
16153
+ }
16154
+ }
16155
+
16156
+ if (this._config.chunkSize)
16157
+ {
16158
+ var end = this._start + this._config.chunkSize - 1; // minus one because byte range is inclusive
16159
+ xhr.setRequestHeader('Range', 'bytes='+this._start+'-'+end);
16160
+ xhr.setRequestHeader('If-None-Match', 'webkit-no-cache'); // https://bugs.webkit.org/show_bug.cgi?id=82672
16161
+ }
16162
+
16163
+ try {
16164
+ xhr.send();
16165
+ }
16166
+ catch (err) {
16167
+ this._chunkError(err.message);
16168
+ }
16169
+
16170
+ if (IS_WORKER && xhr.status === 0)
16171
+ this._chunkError();
16172
+ else
16173
+ this._start += this._config.chunkSize;
16174
+ }
16175
+
16176
+ this._chunkLoaded = function()
16177
+ {
16178
+ if (xhr.readyState != 4)
16179
+ return;
16180
+
16181
+ if (xhr.status < 200 || xhr.status >= 400)
16182
+ {
16183
+ this._chunkError();
16184
+ return;
16185
+ }
16186
+
16187
+ this._finished = !this._config.chunkSize || this._start > getFileSize(xhr);
16188
+ this.parseChunk(xhr.responseText);
16189
+ }
16190
+
16191
+ this._chunkError = function(errorMessage)
16192
+ {
16193
+ var errorText = xhr.statusText || errorMessage;
16194
+ this._sendError(errorText);
16195
+ }
16196
+
16197
+ function getFileSize(xhr)
16198
+ {
16199
+ var contentRange = xhr.getResponseHeader('Content-Range');
16200
+ if (contentRange === null) { // no content range, then finish!
16201
+ return -1;
16202
+ }
16203
+ return parseInt(contentRange.substr(contentRange.lastIndexOf('/') + 1));
16204
+ }
16205
+ }
16206
+ NetworkStreamer.prototype = Object.create(ChunkStreamer.prototype);
16207
+ NetworkStreamer.prototype.constructor = NetworkStreamer;
16208
+
16209
+
16210
+ function FileStreamer(config)
16211
+ {
16212
+ config = config || {};
16213
+ if (!config.chunkSize)
16214
+ config.chunkSize = Papa.LocalChunkSize;
16215
+ ChunkStreamer.call(this, config);
16216
+
16217
+ var reader, slice;
16218
+
16219
+ // FileReader is better than FileReaderSync (even in worker) - see http://stackoverflow.com/q/24708649/1048862
16220
+ // But Firefox is a pill, too - see issue #76: https://github.com/mholt/PapaParse/issues/76
16221
+ var usingAsyncReader = typeof FileReader !== 'undefined'; // Safari doesn't consider it a function - see issue #105
16222
+
16223
+ this.stream = function(file)
16224
+ {
16225
+ this._input = file;
16226
+ slice = file.slice || file.webkitSlice || file.mozSlice;
16227
+
16228
+ if (usingAsyncReader)
16229
+ {
16230
+ reader = new FileReader(); // Preferred method of reading files, even in workers
16231
+ reader.onload = bindFunction(this._chunkLoaded, this);
16232
+ reader.onerror = bindFunction(this._chunkError, this);
16233
+ }
16234
+ else
16235
+ reader = new FileReaderSync(); // Hack for running in a web worker in Firefox
16236
+
16237
+ this._nextChunk(); // Starts streaming
16238
+ };
16239
+
16240
+ this._nextChunk = function()
16241
+ {
16242
+ if (!this._finished && (!this._config.preview || this._rowCount < this._config.preview))
16243
+ this._readChunk();
16244
+ }
16245
+
16246
+ this._readChunk = function()
16247
+ {
16248
+ var input = this._input;
16249
+ if (this._config.chunkSize)
16250
+ {
16251
+ var end = Math.min(this._start + this._config.chunkSize, this._input.size);
16252
+ input = slice.call(input, this._start, end);
16253
+ }
16254
+ var txt = reader.readAsText(input, this._config.encoding);
16255
+ if (!usingAsyncReader)
16256
+ this._chunkLoaded({ target: { result: txt } }); // mimic the async signature
16257
+ }
16258
+
16259
+ this._chunkLoaded = function(event)
16260
+ {
16261
+ // Very important to increment start each time before handling results
16262
+ this._start += this._config.chunkSize;
16263
+ this._finished = !this._config.chunkSize || this._start >= this._input.size;
16264
+ this.parseChunk(event.target.result);
16265
+ }
16266
+
16267
+ this._chunkError = function()
16268
+ {
16269
+ this._sendError(reader.error);
16270
+ }
16271
+
16272
+ }
16273
+ FileStreamer.prototype = Object.create(ChunkStreamer.prototype);
16274
+ FileStreamer.prototype.constructor = FileStreamer;
16275
+
16276
+
16277
+ function StringStreamer(config)
16278
+ {
16279
+ config = config || {};
16280
+ ChunkStreamer.call(this, config);
16281
+
16282
+ var string;
16283
+ var remaining;
16284
+ this.stream = function(s)
16285
+ {
16286
+ string = s;
16287
+ remaining = s;
16288
+ return this._nextChunk();
16289
+ }
16290
+ this._nextChunk = function()
16291
+ {
16292
+ if (this._finished) return;
16293
+ var size = this._config.chunkSize;
16294
+ var chunk = size ? remaining.substr(0, size) : remaining;
16295
+ remaining = size ? remaining.substr(size) : '';
16296
+ this._finished = !remaining;
16297
+ return this.parseChunk(chunk);
16298
+ }
16299
+ }
16300
+ StringStreamer.prototype = Object.create(StringStreamer.prototype);
16301
+ StringStreamer.prototype.constructor = StringStreamer;
16302
+
16303
+
16304
+ function ReadableStreamStreamer(config)
16305
+ {
16306
+ config = config || {};
16307
+
16308
+ ChunkStreamer.call(this, config);
16309
+
16310
+ var queue = [];
16311
+ var parseOnData = true;
16312
+
16313
+ this.stream = function(stream)
16314
+ {
16315
+ this._input = stream;
16316
+
16317
+ this._input.on('data', this._streamData);
16318
+ this._input.on('end', this._streamEnd);
16319
+ this._input.on('error', this._streamError);
16320
+ }
16321
+
16322
+ this._nextChunk = function()
16323
+ {
16324
+ if (queue.length)
16325
+ {
16326
+ this.parseChunk(queue.shift());
16327
+ }
16328
+ else
16329
+ {
16330
+ parseOnData = true;
16331
+ }
16332
+ }
16333
+
16334
+ this._streamData = bindFunction(function(chunk)
16335
+ {
16336
+ try
16337
+ {
16338
+ queue.push(typeof chunk === 'string' ? chunk : chunk.toString(this._config.encoding));
16339
+
16340
+ if (parseOnData)
16341
+ {
16342
+ parseOnData = false;
16343
+ this.parseChunk(queue.shift());
16344
+ }
16345
+ }
16346
+ catch (error)
16347
+ {
16348
+ this._streamError(error);
16349
+ }
16350
+ }, this);
16351
+
16352
+ this._streamError = bindFunction(function(error)
16353
+ {
16354
+ this._streamCleanUp();
16355
+ this._sendError(error.message);
16356
+ }, this);
16357
+
16358
+ this._streamEnd = bindFunction(function()
16359
+ {
16360
+ this._streamCleanUp();
16361
+ this._finished = true;
16362
+ this._streamData('');
16363
+ }, this);
16364
+
16365
+ this._streamCleanUp = bindFunction(function()
16366
+ {
16367
+ this._input.removeListener('data', this._streamData);
16368
+ this._input.removeListener('end', this._streamEnd);
16369
+ this._input.removeListener('error', this._streamError);
16370
+ }, this);
16371
+ }
16372
+ ReadableStreamStreamer.prototype = Object.create(ChunkStreamer.prototype);
16373
+ ReadableStreamStreamer.prototype.constructor = ReadableStreamStreamer;
16374
+
16375
+
16376
+ // Use one ParserHandle per entire CSV file or string
16377
+ function ParserHandle(_config)
16378
+ {
16379
+ // One goal is to minimize the use of regular expressions...
16380
+ var FLOAT = /^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i;
16381
+
16382
+ var self = this;
16383
+ var _stepCounter = 0; // Number of times step was called (number of rows parsed)
16384
+ var _input; // The input being parsed
16385
+ var _parser; // The core parser being used
16386
+ var _paused = false; // Whether we are paused or not
16387
+ var _aborted = false; // Whether the parser has aborted or not
16388
+ var _delimiterError; // Temporary state between delimiter detection and processing results
16389
+ var _fields = []; // Fields are from the header row of the input, if there is one
16390
+ var _results = { // The last results returned from the parser
16391
+ data: [],
16392
+ errors: [],
16393
+ meta: {}
16394
+ };
16395
+
16396
+ if (isFunction(_config.step))
16397
+ {
16398
+ var userStep = _config.step;
16399
+ _config.step = function(results)
16400
+ {
16401
+ _results = results;
16402
+
16403
+ if (needsHeaderRow())
16404
+ processResults();
16405
+ else // only call user's step function after header row
16406
+ {
16407
+ processResults();
16408
+
16409
+ // It's possbile that this line was empty and there's no row here after all
16410
+ if (_results.data.length === 0)
16411
+ return;
16412
+
16413
+ _stepCounter += results.data.length;
16414
+ if (_config.preview && _stepCounter > _config.preview)
16415
+ _parser.abort();
16416
+ else
16417
+ userStep(_results, self);
16418
+ }
16419
+ };
16420
+ }
16421
+
16422
+ /**
16423
+ * Parses input. Most users won't need, and shouldn't mess with, the baseIndex
16424
+ * and ignoreLastRow parameters. They are used by streamers (wrapper functions)
16425
+ * when an input comes in multiple chunks, like from a file.
16426
+ */
16427
+ this.parse = function(input, baseIndex, ignoreLastRow)
16428
+ {
16429
+ if (!_config.newline)
16430
+ _config.newline = guessLineEndings(input);
16431
+
16432
+ _delimiterError = false;
16433
+ if (!_config.delimiter)
16434
+ {
16435
+ var delimGuess = guessDelimiter(input, _config.newline, _config.skipEmptyLines);
16436
+ if (delimGuess.successful)
16437
+ _config.delimiter = delimGuess.bestDelimiter;
16438
+ else
16439
+ {
16440
+ _delimiterError = true; // add error after parsing (otherwise it would be overwritten)
16441
+ _config.delimiter = Papa.DefaultDelimiter;
16442
+ }
16443
+ _results.meta.delimiter = _config.delimiter;
16444
+ }
16445
+ else if(isFunction(_config.delimiter))
16446
+ {
16447
+ _config.delimiter = _config.delimiter(input);
16448
+ _results.meta.delimiter = _config.delimiter;
16449
+ }
16450
+
16451
+ var parserConfig = copy(_config);
16452
+ if (_config.preview && _config.header)
16453
+ parserConfig.preview++; // to compensate for header row
16454
+
16455
+ _input = input;
16456
+ _parser = new Parser(parserConfig);
16457
+ _results = _parser.parse(_input, baseIndex, ignoreLastRow);
16458
+ processResults();
16459
+ return _paused ? { meta: { paused: true } } : (_results || { meta: { paused: false } });
16460
+ };
16461
+
16462
+ this.paused = function()
16463
+ {
16464
+ return _paused;
16465
+ };
16466
+
16467
+ this.pause = function()
16468
+ {
16469
+ _paused = true;
16470
+ _parser.abort();
16471
+ _input = _input.substr(_parser.getCharIndex());
16472
+ };
16473
+
16474
+ this.resume = function()
16475
+ {
16476
+ _paused = false;
16477
+ self.streamer.parseChunk(_input);
16478
+ };
16479
+
16480
+ this.aborted = function ()
16481
+ {
16482
+ return _aborted;
16483
+ };
16484
+
16485
+ this.abort = function()
16486
+ {
16487
+ _aborted = true;
16488
+ _parser.abort();
16489
+ _results.meta.aborted = true;
16490
+ if (isFunction(_config.complete))
16491
+ _config.complete(_results);
16492
+ _input = '';
16493
+ };
16494
+
16495
+ function processResults()
16496
+ {
16497
+ if (_results && _delimiterError)
16498
+ {
16499
+ addError('Delimiter', 'UndetectableDelimiter', 'Unable to auto-detect delimiting character; defaulted to \''+Papa.DefaultDelimiter+'\'');
16500
+ _delimiterError = false;
16501
+ }
16502
+
16503
+ if (_config.skipEmptyLines)
16504
+ {
16505
+ for (var i = 0; i < _results.data.length; i++)
16506
+ if (_results.data[i].length === 1 && _results.data[i][0] === '')
16507
+ _results.data.splice(i--, 1);
16508
+ }
16509
+
16510
+ if (needsHeaderRow())
16511
+ fillHeaderFields();
16512
+
16513
+ return applyHeaderAndDynamicTyping();
16514
+ }
16515
+
16516
+ function needsHeaderRow()
16517
+ {
16518
+ return _config.header && _fields.length === 0;
16519
+ }
16520
+
16521
+ function fillHeaderFields()
16522
+ {
16523
+ if (!_results)
16524
+ return;
16525
+ for (var i = 0; needsHeaderRow() && i < _results.data.length; i++)
16526
+ for (var j = 0; j < _results.data[i].length; j++)
16527
+ _fields.push(_results.data[i][j]);
16528
+ _results.data.splice(0, 1);
16529
+ }
16530
+
16531
+ function shouldApplyDynamicTyping(field) {
16532
+ // Cache function values to avoid calling it for each row
16533
+ if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) {
16534
+ _config.dynamicTyping[field] = _config.dynamicTypingFunction(field);
16535
+ }
16536
+ return (_config.dynamicTyping[field] || _config.dynamicTyping) === true
16537
+ }
16538
+
16539
+ function parseDynamic(field, value)
16540
+ {
16541
+ if (shouldApplyDynamicTyping(field))
16542
+ {
16543
+ if (value === 'true' || value === 'TRUE')
16544
+ return true;
16545
+ else if (value === 'false' || value === 'FALSE')
16546
+ return false;
16547
+ else
16548
+ return tryParseFloat(value);
16549
+ }
16550
+ return value;
16551
+ }
16552
+
16553
+ function applyHeaderAndDynamicTyping()
16554
+ {
16555
+ if (!_results || (!_config.header && !_config.dynamicTyping))
16556
+ return _results;
16557
+
16558
+ for (var i = 0; i < _results.data.length; i++)
16559
+ {
16560
+ var row = _config.header ? {} : [];
16561
+
16562
+ for (var j = 0; j < _results.data[i].length; j++)
16563
+ {
16564
+ var field = j;
16565
+ var value = _results.data[i][j];
16566
+
16567
+ if (_config.header)
16568
+ field = j >= _fields.length ? '__parsed_extra' : _fields[j];
16569
+
16570
+ value = parseDynamic(field, value);
16571
+
16572
+ if (field === '__parsed_extra')
16573
+ {
16574
+ row[field] = row[field] || [];
16575
+ row[field].push(value);
16576
+ }
16577
+ else
16578
+ row[field] = value;
16579
+ }
16580
+
16581
+ _results.data[i] = row;
16582
+
16583
+ if (_config.header)
16584
+ {
16585
+ if (j > _fields.length)
16586
+ addError('FieldMismatch', 'TooManyFields', 'Too many fields: expected ' + _fields.length + ' fields but parsed ' + j, i);
16587
+ else if (j < _fields.length)
16588
+ addError('FieldMismatch', 'TooFewFields', 'Too few fields: expected ' + _fields.length + ' fields but parsed ' + j, i);
16589
+ }
16590
+ }
16591
+
16592
+ if (_config.header && _results.meta)
16593
+ _results.meta.fields = _fields;
16594
+ return _results;
16595
+ }
16596
+
16597
+ function guessDelimiter(input, newline, skipEmptyLines)
16598
+ {
16599
+ var delimChoices = [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP];
16600
+ var bestDelim, bestDelta, fieldCountPrevRow;
16601
+
16602
+ for (var i = 0; i < delimChoices.length; i++)
16603
+ {
16604
+ var delim = delimChoices[i];
16605
+ var delta = 0, avgFieldCount = 0, emptyLinesCount = 0;
16606
+ fieldCountPrevRow = undefined;
16607
+
16608
+ var preview = new Parser({
16609
+ delimiter: delim,
16610
+ newline: newline,
16611
+ preview: 10
16612
+ }).parse(input);
16613
+
16614
+ for (var j = 0; j < preview.data.length; j++)
16615
+ {
16616
+ if (skipEmptyLines && preview.data[j].length === 1 && preview.data[j][0].length === 0) {
16617
+ emptyLinesCount++
16618
+ continue
16619
+ }
16620
+ var fieldCount = preview.data[j].length;
16621
+ avgFieldCount += fieldCount;
16622
+
16623
+ if (typeof fieldCountPrevRow === 'undefined')
16624
+ {
16625
+ fieldCountPrevRow = fieldCount;
16626
+ continue;
16627
+ }
16628
+ else if (fieldCount > 1)
16629
+ {
16630
+ delta += Math.abs(fieldCount - fieldCountPrevRow);
16631
+ fieldCountPrevRow = fieldCount;
16632
+ }
16633
+ }
16634
+
16635
+ if (preview.data.length > 0)
16636
+ avgFieldCount /= (preview.data.length - emptyLinesCount);
16637
+
16638
+ if ((typeof bestDelta === 'undefined' || delta < bestDelta)
16639
+ && avgFieldCount > 1.99)
16640
+ {
16641
+ bestDelta = delta;
16642
+ bestDelim = delim;
16643
+ }
16644
+ }
16645
+
16646
+ _config.delimiter = bestDelim;
16647
+
16648
+ return {
16649
+ successful: !!bestDelim,
16650
+ bestDelimiter: bestDelim
16651
+ }
16652
+ }
16653
+
16654
+ function guessLineEndings(input)
16655
+ {
16656
+ input = input.substr(0, 1024*1024); // max length 1 MB
16657
+
16658
+ var r = input.split('\r');
16659
+
16660
+ var n = input.split('\n');
16661
+
16662
+ var nAppearsFirst = (n.length > 1 && n[0].length < r[0].length);
16663
+
16664
+ if (r.length === 1 || nAppearsFirst)
16665
+ return '\n';
16666
+
16667
+ var numWithN = 0;
16668
+ for (var i = 0; i < r.length; i++)
16669
+ {
16670
+ if (r[i][0] === '\n')
16671
+ numWithN++;
16672
+ }
16673
+
16674
+ return numWithN >= r.length / 2 ? '\r\n' : '\r';
16675
+ }
16676
+
16677
+ function tryParseFloat(val)
16678
+ {
16679
+ var isNumber = FLOAT.test(val);
16680
+ return isNumber ? parseFloat(val) : val;
16681
+ }
16682
+
16683
+ function addError(type, code, msg, row)
16684
+ {
16685
+ _results.errors.push({
16686
+ type: type,
16687
+ code: code,
16688
+ message: msg,
16689
+ row: row
16690
+ });
16691
+ }
16692
+ }
16693
+
16694
+
16695
+
16696
+
16697
+
16698
+ /** The core parser implements speedy and correct CSV parsing */
16699
+ function Parser(config)
16700
+ {
16701
+ // Unpack the config object
16702
+ config = config || {};
16703
+ var delim = config.delimiter;
16704
+ var newline = config.newline;
16705
+ var comments = config.comments;
16706
+ var step = config.step;
16707
+ var preview = config.preview;
16708
+ var fastMode = config.fastMode;
16709
+ var quoteChar = config.quoteChar || '"';
16710
+
16711
+ // Delimiter must be valid
16712
+ if (typeof delim !== 'string'
16713
+ || Papa.BAD_DELIMITERS.indexOf(delim) > -1)
16714
+ delim = ',';
16715
+
16716
+ // Comment character must be valid
16717
+ if (comments === delim)
16718
+ throw 'Comment character same as delimiter';
16719
+ else if (comments === true)
16720
+ comments = '#';
16721
+ else if (typeof comments !== 'string'
16722
+ || Papa.BAD_DELIMITERS.indexOf(comments) > -1)
16723
+ comments = false;
16724
+
16725
+ // Newline must be valid: \r, \n, or \r\n
16726
+ if (newline != '\n' && newline != '\r' && newline != '\r\n')
16727
+ newline = '\n';
16728
+
16729
+ // We're gonna need these at the Parser scope
16730
+ var cursor = 0;
16731
+ var aborted = false;
16732
+
16733
+ this.parse = function(input, baseIndex, ignoreLastRow)
16734
+ {
16735
+ // For some reason, in Chrome, this speeds things up (!?)
16736
+ if (typeof input !== 'string')
16737
+ throw 'Input must be a string';
16738
+
16739
+ // We don't need to compute some of these every time parse() is called,
16740
+ // but having them in a more local scope seems to perform better
16741
+ var inputLen = input.length,
16742
+ delimLen = delim.length,
16743
+ newlineLen = newline.length,
16744
+ commentsLen = comments.length;
16745
+ var stepIsFunction = isFunction(step);
16746
+
16747
+ // Establish starting state
16748
+ cursor = 0;
16749
+ var data = [], errors = [], row = [], lastCursor = 0;
16750
+
16751
+ if (!input)
16752
+ return returnable();
16753
+
16754
+ if (fastMode || (fastMode !== false && input.indexOf(quoteChar) === -1))
16755
+ {
16756
+ var rows = input.split(newline);
16757
+ for (var i = 0; i < rows.length; i++)
16758
+ {
16759
+ var row = rows[i];
16760
+ cursor += row.length;
16761
+ if (i !== rows.length - 1)
16762
+ cursor += newline.length;
16763
+ else if (ignoreLastRow)
16764
+ return returnable();
16765
+ if (comments && row.substr(0, commentsLen) === comments)
16766
+ continue;
16767
+ if (stepIsFunction)
16768
+ {
16769
+ data = [];
16770
+ pushRow(row.split(delim));
16771
+ doStep();
16772
+ if (aborted)
16773
+ return returnable();
16774
+ }
16775
+ else
16776
+ pushRow(row.split(delim));
16777
+ if (preview && i >= preview)
16778
+ {
16779
+ data = data.slice(0, preview);
16780
+ return returnable(true);
16781
+ }
16782
+ }
16783
+ return returnable();
16784
+ }
16785
+
16786
+ var nextDelim = input.indexOf(delim, cursor);
16787
+ var nextNewline = input.indexOf(newline, cursor);
16788
+ var quoteCharRegex = new RegExp(quoteChar+quoteChar, 'g');
16789
+
16790
+ // Parser loop
16791
+ for (;;)
16792
+ {
16793
+ // Field has opening quote
16794
+ if (input[cursor] === quoteChar)
16795
+ {
16796
+ // Start our search for the closing quote where the cursor is
16797
+ var quoteSearch = cursor;
16798
+
16799
+ // Skip the opening quote
16800
+ cursor++;
16801
+
16802
+ for (;;)
16803
+ {
16804
+ // Find closing quote
16805
+ var quoteSearch = input.indexOf(quoteChar, quoteSearch+1);
16806
+
16807
+ //No other quotes are found - no other delimiters
16808
+ if (quoteSearch === -1)
16809
+ {
16810
+ if (!ignoreLastRow) {
16811
+ // No closing quote... what a pity
16812
+ errors.push({
16813
+ type: 'Quotes',
16814
+ code: 'MissingQuotes',
16815
+ message: 'Quoted field unterminated',
16816
+ row: data.length, // row has yet to be inserted
16817
+ index: cursor
16818
+ });
16819
+ }
16820
+ return finish();
16821
+ }
16822
+
16823
+ // Closing quote at EOF
16824
+ if (quoteSearch === inputLen-1)
16825
+ {
16826
+ var value = input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar);
16827
+ return finish(value);
16828
+ }
16829
+
16830
+ // If this quote is escaped, it's part of the data; skip it
16831
+ if (input[quoteSearch+1] === quoteChar)
16832
+ {
16833
+ quoteSearch++;
16834
+ continue;
16835
+ }
16836
+
16837
+ // Closing quote followed by delimiter
16838
+ if (input[quoteSearch+1] === delim)
16839
+ {
16840
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
16841
+ cursor = quoteSearch + 1 + delimLen;
16842
+ nextDelim = input.indexOf(delim, cursor);
16843
+ nextNewline = input.indexOf(newline, cursor);
16844
+ break;
16845
+ }
16846
+
16847
+ // Closing quote followed by newline
16848
+ if (input.substr(quoteSearch+1, newlineLen) === newline)
16849
+ {
16850
+ row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
16851
+ saveRow(quoteSearch + 1 + newlineLen);
16852
+ nextDelim = input.indexOf(delim, cursor); // because we may have skipped the nextDelim in the quoted field
16853
+
16854
+ if (stepIsFunction)
16855
+ {
16856
+ doStep();
16857
+ if (aborted)
16858
+ return returnable();
16859
+ }
16860
+
16861
+ if (preview && data.length >= preview)
16862
+ return returnable(true);
16863
+
16864
+ break;
16865
+ }
16866
+
16867
+
16868
+ // 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
16869
+ errors.push({
16870
+ type: 'Quotes',
16871
+ code: 'InvalidQuotes',
16872
+ message: 'Trailing quote on quoted field is malformed',
16873
+ row: data.length, // row has yet to be inserted
16874
+ index: cursor
16875
+ });
16876
+
16877
+ quoteSearch++;
16878
+ continue;
16879
+
16880
+ }
16881
+
16882
+ continue;
16883
+ }
16884
+
16885
+ // Comment found at start of new line
16886
+ if (comments && row.length === 0 && input.substr(cursor, commentsLen) === comments)
16887
+ {
16888
+ if (nextNewline === -1) // Comment ends at EOF
16889
+ return returnable();
16890
+ cursor = nextNewline + newlineLen;
16891
+ nextNewline = input.indexOf(newline, cursor);
16892
+ nextDelim = input.indexOf(delim, cursor);
16893
+ continue;
16894
+ }
16895
+
16896
+ // Next delimiter comes before next newline, so we've reached end of field
16897
+ if (nextDelim !== -1 && (nextDelim < nextNewline || nextNewline === -1))
16898
+ {
16899
+ row.push(input.substring(cursor, nextDelim));
16900
+ cursor = nextDelim + delimLen;
16901
+ nextDelim = input.indexOf(delim, cursor);
16902
+ continue;
16903
+ }
16904
+
16905
+ // End of row
16906
+ if (nextNewline !== -1)
16907
+ {
16908
+ row.push(input.substring(cursor, nextNewline));
16909
+ saveRow(nextNewline + newlineLen);
16910
+
16911
+ if (stepIsFunction)
16912
+ {
16913
+ doStep();
16914
+ if (aborted)
16915
+ return returnable();
16916
+ }
16917
+
16918
+ if (preview && data.length >= preview)
16919
+ return returnable(true);
16920
+
16921
+ continue;
16922
+ }
16923
+
16924
+ break;
16925
+ }
16926
+
16927
+
16928
+ return finish();
16929
+
16930
+
16931
+ function pushRow(row)
16932
+ {
16933
+ data.push(row);
16934
+ lastCursor = cursor;
16935
+ }
16936
+
16937
+ /**
16938
+ * Appends the remaining input from cursor to the end into
16939
+ * row, saves the row, calls step, and returns the results.
16940
+ */
16941
+ function finish(value)
16942
+ {
16943
+ if (ignoreLastRow)
16944
+ return returnable();
16945
+ if (typeof value === 'undefined')
16946
+ value = input.substr(cursor);
16947
+ row.push(value);
16948
+ cursor = inputLen; // important in case parsing is paused
16949
+ pushRow(row);
16950
+ if (stepIsFunction)
16951
+ doStep();
16952
+ return returnable();
16953
+ }
16954
+
16955
+ /**
16956
+ * Appends the current row to the results. It sets the cursor
16957
+ * to newCursor and finds the nextNewline. The caller should
16958
+ * take care to execute user's step function and check for
16959
+ * preview and end parsing if necessary.
16960
+ */
16961
+ function saveRow(newCursor)
16962
+ {
16963
+ cursor = newCursor;
16964
+ pushRow(row);
16965
+ row = [];
16966
+ nextNewline = input.indexOf(newline, cursor);
16967
+ }
16968
+
16969
+ /** Returns an object with the results, errors, and meta. */
16970
+ function returnable(stopped)
16971
+ {
16972
+ return {
16973
+ data: data,
16974
+ errors: errors,
16975
+ meta: {
16976
+ delimiter: delim,
16977
+ linebreak: newline,
16978
+ aborted: aborted,
16979
+ truncated: !!stopped,
16980
+ cursor: lastCursor + (baseIndex || 0)
16981
+ }
16982
+ };
16983
+ }
16984
+
16985
+ /** Executes the user's step function and resets data & errors. */
16986
+ function doStep()
16987
+ {
16988
+ step(returnable());
16989
+ data = [], errors = [];
16990
+ }
16991
+ };
16992
+
16993
+ /** Sets the abort flag */
16994
+ this.abort = function()
16995
+ {
16996
+ aborted = true;
16997
+ };
16998
+
16999
+ /** Gets the cursor position */
17000
+ this.getCharIndex = function()
17001
+ {
17002
+ return cursor;
17003
+ };
17004
+ }
17005
+
17006
+
17007
+ // If you need to load Papa Parse asynchronously and you also need worker threads, hard-code
17008
+ // the script path here. See: https://github.com/mholt/PapaParse/issues/87#issuecomment-57885358
17009
+ function getScriptPath()
17010
+ {
17011
+ var scripts = document.getElementsByTagName('script');
17012
+ return scripts.length ? scripts[scripts.length - 1].src : '';
17013
+ }
17014
+
17015
+ function newWorker()
17016
+ {
17017
+ if (!Papa.WORKERS_SUPPORTED)
17018
+ return false;
17019
+ if (!LOADED_SYNC && Papa.SCRIPT_PATH === null)
17020
+ throw new Error(
17021
+ 'Script path cannot be determined automatically when Papa Parse is loaded asynchronously. ' +
17022
+ 'You need to set Papa.SCRIPT_PATH manually.'
17023
+ );
17024
+ var workerUrl = Papa.SCRIPT_PATH || AUTO_SCRIPT_PATH;
17025
+ // Append 'papaworker' to the search string to tell papaparse that this is our worker.
17026
+ workerUrl += (workerUrl.indexOf('?') !== -1 ? '&' : '?') + 'papaworker';
17027
+ var w = new global.Worker(workerUrl);
17028
+ w.onmessage = mainThreadReceivedMessage;
17029
+ w.id = workerIdCounter++;
17030
+ workers[w.id] = w;
17031
+ return w;
17032
+ }
17033
+
17034
+ /** Callback when main thread receives a message */
17035
+ function mainThreadReceivedMessage(e)
17036
+ {
17037
+ var msg = e.data;
17038
+ var worker = workers[msg.workerId];
17039
+ var aborted = false;
17040
+
17041
+ if (msg.error)
17042
+ worker.userError(msg.error, msg.file);
17043
+ else if (msg.results && msg.results.data)
17044
+ {
17045
+ var abort = function() {
17046
+ aborted = true;
17047
+ completeWorker(msg.workerId, { data: [], errors: [], meta: { aborted: true } });
17048
+ };
17049
+
17050
+ var handle = {
17051
+ abort: abort,
17052
+ pause: notImplemented,
17053
+ resume: notImplemented
17054
+ };
17055
+
17056
+ if (isFunction(worker.userStep))
17057
+ {
17058
+ for (var i = 0; i < msg.results.data.length; i++)
17059
+ {
17060
+ worker.userStep({
17061
+ data: [msg.results.data[i]],
17062
+ errors: msg.results.errors,
17063
+ meta: msg.results.meta
17064
+ }, handle);
17065
+ if (aborted)
17066
+ break;
17067
+ }
17068
+ delete msg.results; // free memory ASAP
17069
+ }
17070
+ else if (isFunction(worker.userChunk))
17071
+ {
17072
+ worker.userChunk(msg.results, handle, msg.file);
17073
+ delete msg.results;
17074
+ }
17075
+ }
17076
+
17077
+ if (msg.finished && !aborted)
17078
+ completeWorker(msg.workerId, msg.results);
17079
+ }
17080
+
17081
+ function completeWorker(workerId, results) {
17082
+ var worker = workers[workerId];
17083
+ if (isFunction(worker.userComplete))
17084
+ worker.userComplete(results);
17085
+ worker.terminate();
17086
+ delete workers[workerId];
17087
+ }
17088
+
17089
+ function notImplemented() {
17090
+ throw 'Not implemented.';
17091
+ }
17092
+
17093
+ /** Callback when worker thread receives a message */
17094
+ function workerThreadReceivedMessage(e)
17095
+ {
17096
+ var msg = e.data;
17097
+
17098
+ if (typeof Papa.WORKER_ID === 'undefined' && msg)
17099
+ Papa.WORKER_ID = msg.workerId;
17100
+
17101
+ if (typeof msg.input === 'string')
17102
+ {
17103
+ global.postMessage({
17104
+ workerId: Papa.WORKER_ID,
17105
+ results: Papa.parse(msg.input, msg.config),
17106
+ finished: true
17107
+ });
17108
+ }
17109
+ else if ((global.File && msg.input instanceof File) || msg.input instanceof Object) // thank you, Safari (see issue #106)
17110
+ {
17111
+ var results = Papa.parse(msg.input, msg.config);
17112
+ if (results)
17113
+ global.postMessage({
17114
+ workerId: Papa.WORKER_ID,
17115
+ results: results,
17116
+ finished: true
17117
+ });
17118
+ }
17119
+ }
17120
+
17121
+ /** Makes a deep copy of an array or object (mostly) */
17122
+ function copy(obj)
17123
+ {
17124
+ if (typeof obj !== 'object')
17125
+ return obj;
17126
+ var cpy = obj instanceof Array ? [] : {};
17127
+ for (var key in obj)
17128
+ cpy[key] = copy(obj[key]);
17129
+ return cpy;
17130
+ }
17131
+
17132
+ function bindFunction(f, self)
17133
+ {
17134
+ return function() { f.apply(self, arguments); };
17135
+ }
17136
+
17137
+ function isFunction(func)
17138
+ {
17139
+ return typeof func === 'function';
17140
+ }
17141
+
17142
+ return Papa;
17143
+ }));
17144
+
17145
+
17146
+ /***/ },
17147
+ /* 178 */
15504
17148
  /***/ function(module, exports, __webpack_require__) {
15505
17149
 
15506
17150
  /**
@@ -15514,9 +17158,9 @@ module.exports =
15514
17158
 
15515
17159
  'use strict';
15516
17160
 
15517
- var emptyFunction = __webpack_require__(179);
15518
- var invariant = __webpack_require__(180);
15519
- var ReactPropTypesSecret = __webpack_require__(178);
17161
+ var emptyFunction = __webpack_require__(180);
17162
+ var invariant = __webpack_require__(181);
17163
+ var ReactPropTypesSecret = __webpack_require__(179);
15520
17164
 
15521
17165
  module.exports = function() {
15522
17166
  function shim(props, propName, componentName, location, propFullName, secret) {
@@ -15565,7 +17209,7 @@ module.exports =
15565
17209
 
15566
17210
 
15567
17211
  /***/ },
15568
- /* 178 */
17212
+ /* 179 */
15569
17213
  /***/ function(module, exports) {
15570
17214
 
15571
17215
  /**
@@ -15585,7 +17229,7 @@ module.exports =
15585
17229
 
15586
17230
 
15587
17231
  /***/ },
15588
- /* 179 */
17232
+ /* 180 */
15589
17233
  /***/ function(module, exports) {
15590
17234
 
15591
17235
  "use strict";
@@ -15628,7 +17272,7 @@ module.exports =
15628
17272
  module.exports = emptyFunction;
15629
17273
 
15630
17274
  /***/ },
15631
- /* 180 */
17275
+ /* 181 */
15632
17276
  /***/ function(module, exports, __webpack_require__) {
15633
17277
 
15634
17278
  /**
@@ -15688,7 +17332,7 @@ module.exports =
15688
17332
  module.exports = invariant;
15689
17333
 
15690
17334
  /***/ },
15691
- /* 181 */
17335
+ /* 182 */
15692
17336
  /***/ function(module, exports, __webpack_require__) {
15693
17337
 
15694
17338
  'use strict';
@@ -15713,7 +17357,7 @@ module.exports =
15713
17357
 
15714
17358
  var _addEventListener2 = _interopRequireDefault(_addEventListener);
15715
17359
 
15716
- var _isWindow = __webpack_require__(183);
17360
+ var _isWindow = __webpack_require__(184);
15717
17361
 
15718
17362
  var _isWindow2 = _interopRequireDefault(_isWindow);
15719
17363
 
@@ -15847,7 +17491,7 @@ module.exports =
15847
17491
  module.exports = exports['default'];
15848
17492
 
15849
17493
  /***/ },
15850
- /* 182 */
17494
+ /* 183 */
15851
17495
  /***/ function(module, exports, __webpack_require__) {
15852
17496
 
15853
17497
  'use strict';
@@ -15856,7 +17500,7 @@ module.exports =
15856
17500
  value: true
15857
17501
  });
15858
17502
 
15859
- var _Align = __webpack_require__(181);
17503
+ var _Align = __webpack_require__(182);
15860
17504
 
15861
17505
  var _Align2 = _interopRequireDefault(_Align);
15862
17506
 
@@ -15867,7 +17511,7 @@ module.exports =
15867
17511
  module.exports = exports['default'];
15868
17512
 
15869
17513
  /***/ },
15870
- /* 183 */
17514
+ /* 184 */
15871
17515
  /***/ function(module, exports) {
15872
17516
 
15873
17517
  "use strict";
@@ -15884,7 +17528,7 @@ module.exports =
15884
17528
  module.exports = exports['default'];
15885
17529
 
15886
17530
  /***/ },
15887
- /* 184 */
17531
+ /* 185 */
15888
17532
  /***/ function(module, exports, __webpack_require__) {
15889
17533
 
15890
17534
  'use strict';
@@ -15899,9 +17543,9 @@ module.exports =
15899
17543
 
15900
17544
  var _react2 = _interopRequireDefault(_react);
15901
17545
 
15902
- var _ChildrenUtils = __webpack_require__(186);
17546
+ var _ChildrenUtils = __webpack_require__(187);
15903
17547
 
15904
- var _AnimateChild = __webpack_require__(185);
17548
+ var _AnimateChild = __webpack_require__(186);
15905
17549
 
15906
17550
  var _AnimateChild2 = _interopRequireDefault(_AnimateChild);
15907
17551
 
@@ -16220,7 +17864,7 @@ module.exports =
16220
17864
  module.exports = exports['default'];
16221
17865
 
16222
17866
  /***/ },
16223
- /* 185 */
17867
+ /* 186 */
16224
17868
  /***/ function(module, exports, __webpack_require__) {
16225
17869
 
16226
17870
  'use strict';
@@ -16331,7 +17975,7 @@ module.exports =
16331
17975
  module.exports = exports['default'];
16332
17976
 
16333
17977
  /***/ },
16334
- /* 186 */
17978
+ /* 187 */
16335
17979
  /***/ function(module, exports, __webpack_require__) {
16336
17980
 
16337
17981
  'use strict';
@@ -16453,16 +18097,16 @@ module.exports =
16453
18097
  }
16454
18098
 
16455
18099
  /***/ },
16456
- /* 187 */
18100
+ /* 188 */
16457
18101
  /***/ function(module, exports, __webpack_require__) {
16458
18102
 
16459
18103
  'use strict';
16460
18104
 
16461
18105
  // export this package's api
16462
- module.exports = __webpack_require__(184);
18106
+ module.exports = __webpack_require__(185);
16463
18107
 
16464
18108
  /***/ },
16465
- /* 188 */
18109
+ /* 189 */
16466
18110
  /***/ function(module, exports, __webpack_require__) {
16467
18111
 
16468
18112
  'use strict';
@@ -16475,7 +18119,7 @@ module.exports =
16475
18119
 
16476
18120
  var _react2 = _interopRequireDefault(_react);
16477
18121
 
16478
- var _Select = __webpack_require__(191);
18122
+ var _Select = __webpack_require__(192);
16479
18123
 
16480
18124
  var _Select2 = _interopRequireDefault(_Select);
16481
18125
 
@@ -16699,7 +18343,7 @@ module.exports =
16699
18343
  module.exports = exports['default'];
16700
18344
 
16701
18345
  /***/ },
16702
- /* 189 */
18346
+ /* 190 */
16703
18347
  /***/ function(module, exports, __webpack_require__) {
16704
18348
 
16705
18349
  'use strict';
@@ -16895,7 +18539,7 @@ module.exports =
16895
18539
  module.exports = exports['default'];
16896
18540
 
16897
18541
  /***/ },
16898
- /* 190 */
18542
+ /* 191 */
16899
18543
  /***/ function(module, exports, __webpack_require__) {
16900
18544
 
16901
18545
  'use strict';
@@ -16912,11 +18556,11 @@ module.exports =
16912
18556
 
16913
18557
  var _react2 = _interopRequireDefault(_react);
16914
18558
 
16915
- var _Header = __webpack_require__(189);
18559
+ var _Header = __webpack_require__(190);
16916
18560
 
16917
18561
  var _Header2 = _interopRequireDefault(_Header);
16918
18562
 
16919
- var _Combobox = __webpack_require__(188);
18563
+ var _Combobox = __webpack_require__(189);
16920
18564
 
16921
18565
  var _Combobox2 = _interopRequireDefault(_Combobox);
16922
18566
 
@@ -17089,7 +18733,7 @@ module.exports =
17089
18733
  module.exports = exports['default'];
17090
18734
 
17091
18735
  /***/ },
17092
- /* 191 */
18736
+ /* 192 */
17093
18737
  /***/ function(module, exports, __webpack_require__) {
17094
18738
 
17095
18739
  'use strict';
@@ -17250,7 +18894,7 @@ module.exports =
17250
18894
  module.exports = exports['default'];
17251
18895
 
17252
18896
  /***/ },
17253
- /* 192 */
18897
+ /* 193 */
17254
18898
  /***/ function(module, exports, __webpack_require__) {
17255
18899
 
17256
18900
  'use strict';
@@ -17263,15 +18907,15 @@ module.exports =
17263
18907
 
17264
18908
  var _react2 = _interopRequireDefault(_react);
17265
18909
 
17266
- var _rcTrigger = __webpack_require__(198);
18910
+ var _rcTrigger = __webpack_require__(199);
17267
18911
 
17268
18912
  var _rcTrigger2 = _interopRequireDefault(_rcTrigger);
17269
18913
 
17270
- var _Panel = __webpack_require__(190);
18914
+ var _Panel = __webpack_require__(191);
17271
18915
 
17272
18916
  var _Panel2 = _interopRequireDefault(_Panel);
17273
18917
 
17274
- var _placements = __webpack_require__(194);
18918
+ var _placements = __webpack_require__(195);
17275
18919
 
17276
18920
  var _placements2 = _interopRequireDefault(_placements);
17277
18921
 
@@ -17553,7 +19197,7 @@ module.exports =
17553
19197
  module.exports = exports['default'];
17554
19198
 
17555
19199
  /***/ },
17556
- /* 193 */
19200
+ /* 194 */
17557
19201
  /***/ function(module, exports, __webpack_require__) {
17558
19202
 
17559
19203
  'use strict';
@@ -17562,7 +19206,7 @@ module.exports =
17562
19206
  value: true
17563
19207
  });
17564
19208
 
17565
- var _TimePicker = __webpack_require__(192);
19209
+ var _TimePicker = __webpack_require__(193);
17566
19210
 
17567
19211
  var _TimePicker2 = _interopRequireDefault(_TimePicker);
17568
19212
 
@@ -17572,7 +19216,7 @@ module.exports =
17572
19216
  module.exports = exports['default'];
17573
19217
 
17574
19218
  /***/ },
17575
- /* 194 */
19219
+ /* 195 */
17576
19220
  /***/ function(module, exports) {
17577
19221
 
17578
19222
  'use strict';
@@ -17618,7 +19262,7 @@ module.exports =
17618
19262
  module.exports = exports['default'];
17619
19263
 
17620
19264
  /***/ },
17621
- /* 195 */
19265
+ /* 196 */
17622
19266
  /***/ function(module, exports, __webpack_require__) {
17623
19267
 
17624
19268
  'use strict';
@@ -17639,15 +19283,15 @@ module.exports =
17639
19283
 
17640
19284
  var _reactDom2 = _interopRequireDefault(_reactDom);
17641
19285
 
17642
- var _rcAlign = __webpack_require__(182);
19286
+ var _rcAlign = __webpack_require__(183);
17643
19287
 
17644
19288
  var _rcAlign2 = _interopRequireDefault(_rcAlign);
17645
19289
 
17646
- var _rcAnimate = __webpack_require__(187);
19290
+ var _rcAnimate = __webpack_require__(188);
17647
19291
 
17648
19292
  var _rcAnimate2 = _interopRequireDefault(_rcAnimate);
17649
19293
 
17650
- var _PopupInner = __webpack_require__(196);
19294
+ var _PopupInner = __webpack_require__(197);
17651
19295
 
17652
19296
  var _PopupInner2 = _interopRequireDefault(_PopupInner);
17653
19297
 
@@ -17849,7 +19493,7 @@ module.exports =
17849
19493
  module.exports = exports['default'];
17850
19494
 
17851
19495
  /***/ },
17852
- /* 196 */
19496
+ /* 197 */
17853
19497
  /***/ function(module, exports, __webpack_require__) {
17854
19498
 
17855
19499
  'use strict';
@@ -17906,7 +19550,7 @@ module.exports =
17906
19550
  module.exports = exports['default'];
17907
19551
 
17908
19552
  /***/ },
17909
- /* 197 */
19553
+ /* 198 */
17910
19554
  /***/ function(module, exports, __webpack_require__) {
17911
19555
 
17912
19556
  'use strict';
@@ -17927,7 +19571,7 @@ module.exports =
17927
19571
 
17928
19572
  var _reactDom2 = _interopRequireDefault(_reactDom);
17929
19573
 
17930
- var _contains = __webpack_require__(200);
19574
+ var _contains = __webpack_require__(201);
17931
19575
 
17932
19576
  var _contains2 = _interopRequireDefault(_contains);
17933
19577
 
@@ -17935,13 +19579,13 @@ module.exports =
17935
19579
 
17936
19580
  var _addEventListener2 = _interopRequireDefault(_addEventListener);
17937
19581
 
17938
- var _Popup = __webpack_require__(195);
19582
+ var _Popup = __webpack_require__(196);
17939
19583
 
17940
19584
  var _Popup2 = _interopRequireDefault(_Popup);
17941
19585
 
17942
- var _utils = __webpack_require__(199);
19586
+ var _utils = __webpack_require__(200);
17943
19587
 
17944
- var _getContainerRenderMixin = __webpack_require__(201);
19588
+ var _getContainerRenderMixin = __webpack_require__(202);
17945
19589
 
17946
19590
  var _getContainerRenderMixin2 = _interopRequireDefault(_getContainerRenderMixin);
17947
19591
 
@@ -18405,15 +20049,15 @@ module.exports =
18405
20049
  module.exports = exports['default'];
18406
20050
 
18407
20051
  /***/ },
18408
- /* 198 */
20052
+ /* 199 */
18409
20053
  /***/ function(module, exports, __webpack_require__) {
18410
20054
 
18411
20055
  'use strict';
18412
20056
 
18413
- module.exports = __webpack_require__(197);
20057
+ module.exports = __webpack_require__(198);
18414
20058
 
18415
20059
  /***/ },
18416
- /* 199 */
20060
+ /* 200 */
18417
20061
  /***/ function(module, exports, __webpack_require__) {
18418
20062
 
18419
20063
  'use strict';
@@ -18453,7 +20097,7 @@ module.exports =
18453
20097
  }
18454
20098
 
18455
20099
  /***/ },
18456
- /* 200 */
20100
+ /* 201 */
18457
20101
  /***/ function(module, exports) {
18458
20102
 
18459
20103
  "use strict";
@@ -18476,7 +20120,7 @@ module.exports =
18476
20120
  module.exports = exports['default'];
18477
20121
 
18478
20122
  /***/ },
18479
- /* 201 */
20123
+ /* 202 */
18480
20124
  /***/ function(module, exports, __webpack_require__) {
18481
20125
 
18482
20126
  'use strict';
@@ -18581,7 +20225,7 @@ module.exports =
18581
20225
  module.exports = exports['default'];
18582
20226
 
18583
20227
  /***/ },
18584
- /* 202 */
20228
+ /* 203 */
18585
20229
  /***/ function(module, exports, __webpack_require__) {
18586
20230
 
18587
20231
  (function webpackUniversalModuleDefinition(root, factory) {
@@ -19602,8 +21246,8 @@ module.exports =
19602
21246
  //# sourceMappingURL=index.js.map
19603
21247
 
19604
21248
  /***/ },
19605
- /* 203 */,
19606
- /* 204 */
21249
+ /* 204 */,
21250
+ /* 205 */
19607
21251
  /***/ function(module, exports, __webpack_require__) {
19608
21252
 
19609
21253
  'use strict';
@@ -19612,19 +21256,19 @@ module.exports =
19612
21256
 
19613
21257
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
19614
21258
 
19615
- var _addClass = __webpack_require__(206);
21259
+ var _addClass = __webpack_require__(207);
19616
21260
 
19617
21261
  var _addClass2 = _interopRequireDefault(_addClass);
19618
21262
 
19619
- var _removeClass = __webpack_require__(208);
21263
+ var _removeClass = __webpack_require__(209);
19620
21264
 
19621
21265
  var _removeClass2 = _interopRequireDefault(_removeClass);
19622
21266
 
19623
- var _requestAnimationFrame = __webpack_require__(210);
21267
+ var _requestAnimationFrame = __webpack_require__(211);
19624
21268
 
19625
21269
  var _requestAnimationFrame2 = _interopRequireDefault(_requestAnimationFrame);
19626
21270
 
19627
- var _properties = __webpack_require__(209);
21271
+ var _properties = __webpack_require__(210);
19628
21272
 
19629
21273
  var _react = __webpack_require__(1);
19630
21274
 
@@ -19837,7 +21481,7 @@ module.exports =
19837
21481
  module.exports = exports['default'];
19838
21482
 
19839
21483
  /***/ },
19840
- /* 205 */
21484
+ /* 206 */
19841
21485
  /***/ function(module, exports, __webpack_require__) {
19842
21486
 
19843
21487
  'use strict';
@@ -19858,11 +21502,11 @@ module.exports =
19858
21502
 
19859
21503
  var _propTypes2 = _interopRequireDefault(_propTypes);
19860
21504
 
19861
- var _warning = __webpack_require__(212);
21505
+ var _warning = __webpack_require__(213);
19862
21506
 
19863
21507
  var _warning2 = _interopRequireDefault(_warning);
19864
21508
 
19865
- var _ChildMapping = __webpack_require__(211);
21509
+ var _ChildMapping = __webpack_require__(212);
19866
21510
 
19867
21511
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19868
21512
 
@@ -20114,7 +21758,7 @@ module.exports =
20114
21758
  module.exports = exports['default'];
20115
21759
 
20116
21760
  /***/ },
20117
- /* 206 */
21761
+ /* 207 */
20118
21762
  /***/ function(module, exports, __webpack_require__) {
20119
21763
 
20120
21764
  'use strict';
@@ -20124,7 +21768,7 @@ module.exports =
20124
21768
  });
20125
21769
  exports.default = addClass;
20126
21770
 
20127
- var _hasClass = __webpack_require__(207);
21771
+ var _hasClass = __webpack_require__(208);
20128
21772
 
20129
21773
  var _hasClass2 = _interopRequireDefault(_hasClass);
20130
21774
 
@@ -20136,7 +21780,7 @@ module.exports =
20136
21780
  module.exports = exports['default'];
20137
21781
 
20138
21782
  /***/ },
20139
- /* 207 */
21783
+ /* 208 */
20140
21784
  /***/ function(module, exports) {
20141
21785
 
20142
21786
  "use strict";
@@ -20151,7 +21795,7 @@ module.exports =
20151
21795
  module.exports = exports["default"];
20152
21796
 
20153
21797
  /***/ },
20154
- /* 208 */
21798
+ /* 209 */
20155
21799
  /***/ function(module, exports) {
20156
21800
 
20157
21801
  'use strict';
@@ -20161,7 +21805,7 @@ module.exports =
20161
21805
  };
20162
21806
 
20163
21807
  /***/ },
20164
- /* 209 */
21808
+ /* 210 */
20165
21809
  /***/ function(module, exports, __webpack_require__) {
20166
21810
 
20167
21811
  'use strict';
@@ -20276,7 +21920,7 @@ module.exports =
20276
21920
  }
20277
21921
 
20278
21922
  /***/ },
20279
- /* 210 */
21923
+ /* 211 */
20280
21924
  /***/ function(module, exports, __webpack_require__) {
20281
21925
 
20282
21926
  'use strict';
@@ -20334,7 +21978,7 @@ module.exports =
20334
21978
  module.exports = exports['default'];
20335
21979
 
20336
21980
  /***/ },
20337
- /* 211 */
21981
+ /* 212 */
20338
21982
  /***/ function(module, exports, __webpack_require__) {
20339
21983
 
20340
21984
  'use strict';
@@ -20430,7 +22074,7 @@ module.exports =
20430
22074
  }
20431
22075
 
20432
22076
  /***/ },
20433
- /* 212 */
22077
+ /* 213 */
20434
22078
  /***/ function(module, exports, __webpack_require__) {
20435
22079
 
20436
22080
  /**
@@ -20496,13 +22140,13 @@ module.exports =
20496
22140
 
20497
22141
 
20498
22142
  /***/ },
20499
- /* 213 */
22143
+ /* 214 */
20500
22144
  /***/ function(module, exports) {
20501
22145
 
20502
22146
  module.exports = require("moment-timezone");
20503
22147
 
20504
22148
  /***/ },
20505
- /* 214 */
22149
+ /* 215 */
20506
22150
  /***/ function(module, exports) {
20507
22151
 
20508
22152
  module.exports = require("redux");