How to use the papaparse.parse function in papaparse

To help you get started, we’ve selected a few papaparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nylas-mail-lives / nylas-mail / packages / client-app / internal_packages / composer-mail-merge / lib / mail-merge-utils.es6 View on Github external
return new Promise((resolve, reject) => {
    Papa.parse(file, {
      skipEmptyLines: true,
      complete: ({data}) => {
        if (data.length === 0) {
          NylasEnv.showErrorDialog(
            `The csv file you are trying to import contains no rows. Please select another file.`
          );
          resolve(null)
          return;
        }

        // If a cell in the first row contains a valid email address, assume that
        // the table has no headers. We need row[0] to be field names, so make some up!
        const emailRegexp = RegExpUtils.emailRegex();
        const emailInFirstRow = data[0].find((val) => emailRegexp.test(val));
        if (emailInFirstRow) {
          const headers = data[0].map((val, idx) => {
github grafana / grafana / packages / grafana-ui / src / utils / csv.ts View on Github external
readCSV(text: string): SeriesData[] {
    this.data = [this.series];

    const papacfg = {
      ...this.config,
      dynamicTyping: false,
      skipEmptyLines: true,
      comments: false, // Keep comment lines
      step: this.step,
    } as ParseConfig;

    Papa.parse(text, papacfg);
    return this.data;
  }
}
github uber / manifold / modules / mlvis-common / src / utils / io.js View on Github external
export const loadCsvFileWithoutWorker = (path, onComplete) => {
  const batchId = Date.now();
  // https://www.papaparse.com/docs#config
  parse(path, {
    delimiter: ',',
    download: true,
    dynamicTyping: true,
    // TODO: header: true lead to large memory consumption
    header: true,
    newline: '',
    quotes: false,
    quoteChar: '"',
    skipEmptyLines: true,
    complete: results => {
      const {
        data,
        meta: {fields},
      } = results;
      onComplete({data, fields, batchId});
    },
github ProtonMail / proton-contacts / src / app / helpers / csv.js View on Github external
const { headers, contacts, errors } = await new Promise((resolve, reject) => {
        const onComplete = ({ data = [], errors = [] } = {}) =>
            resolve({ headers: data[0], contacts: data.slice(1), errors });
        Papa.parse(file, {
            header: false,
            /*
                If true, the first row of parsed data will be interpreted as field names. An array of field names will be returned in meta,
                and each row of data will be an object of values keyed by field name instead of a simple array.
                Rows with a different number of fields from the header row will produce an error.
            */
            dynamicTyping: false, // If true, numeric and Boolean data will be converted to their type instead of remaining strings.
            complete: onComplete,
            error: reject,
            skipEmptyLines: true // If true, lines that are completely empty will be skipped. An empty line is defined to be one which evaluates to empty string.
        });
    });
github publiclab / simple-data-grapher / dist / transpiled_code / CsvParser.js View on Github external
value: function parse() {
      var _this = this;

      var csvMatrixLocal = [];
      var count = 0;
      var f = this.parseReturn;
      Papa.parse(this.csvFile, {
        download: true,
        dynamicTyping: true,
        comments: true,
        step: function step(row) {
          csvMatrixLocal[count] = row.data[0];
          count += 1;
        },
        complete: function complete() {
          _this.callbackForLocalFile(csvMatrixLocal);
        }
      });
    } // parsing string: for remote and csvString import options. Dat is parsed line by line but NOT asynchronously.
github alephdata / aleph / ui / src / components / EntityImport / EntityImport.jsx View on Github external
fetchCsvRows() {
    const { entity } = this.props;
    const url = entity.links.csv;
    // set chunk size to 100 KB
    Papa.RemoteChunkSize = 1024 * 100;
    Papa.parse(url, {
      download: true,
      delimiter: ',',
      newline: '\n',
      encoding: 'utf-8',
      chunk: (results, parser) => {
        this.setState({
          csvRows: results.data.slice(0, 10),
        });
        parser.abort();
      },
    });
  }
github elastic / kibana / x-pack / plugins / canvas / canvas_plugin_src / functions / common / csv.ts View on Github external
transform: (val: string) => {
          if (val.indexOf('"') >= 0) {
            return val.trim().replace(/(^\"|\"$)/g, '');
          }
          return val;
        },
      };

      if (delimiter != null) {
        config.delimiter = delimiter;
      }
      if (newline != null) {
        config.newline = newline;
      }

      const output = Papa.parse(csvString, config);
      const { data, errors } = output;

      if (errors.length > 0) {
        throw errorMessages.invalidInputCSV();
      }

      // output.data is an array of arrays, rows and values in each row
      return data.reduce(
        (acc, row, i) => {
          if (i === 0) {
            // first row, assume header values
            row.forEach((colName: string) =>
              acc.columns.push({ name: colName.trim(), type: 'string' })
            );
          } else {
            // any other row is a data row
github makebrainwaves / BrainWaves / app / utils / filesystem / storage.js View on Github external
const convertCSVToObject = csv => {
  const data = Papa.parse(csv, {
    header: true
  });
  return data;
};
github beaucronin / embedding / src / dataset.js View on Github external
static createFromCSV(url, callback) {
		Papa.parse(url, {
			download: true,
			header: true,
			dynamicTyping: true,
			complete: function(results) {
				var ds = new Dataset();
				for (let i in results.data) {
					let dp = results.data[i];
					dp._id = i;
					ds.add(dp);
				}
				callback(ds);
			}
		});
	}

papaparse

Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.

MIT
Latest version published 1 year ago

Package Health Score

86 / 100
Full package analysis