How to use papaparse - 10 common examples

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 flow-typed / flow-typed / definitions / npm / papaparse_v4.x.x / test_papaparse_v4.x.x.js View on Github external
a.meta.fields;
    b.name;
  }
}): PapaParse$ParseResult);

var flat: Array = [{a: 1, b: 1, c: 1}];
(Papa.unparse(flat): string);

var nested: Array> = [[1, 2, 3], [4, 5, 6]];
(Papa.unparse(nested): string);

var explicit: PapaParse$UnparseObject = {
  fields: ['One', 'Two'],
  data: '1,2',
};
(Papa.unparse(explicit): string);

var explicitAnyData: PapaParse$UnparseObject = {
  fields: ['One', 'Two'],
  data: [1, 2]
};
(Papa.unparse(explicitAnyData): string);

// $ExpectError
var explicitInvalidData: PapaParse$UnparseObject = {
  fields: ['One', 'Two'],
  data: 1
};
(Papa.unparse(explicitInvalidData): string);

// $ExpectError
var explicitInvalidFields: PapaParse$UnparseObject = {
github flow-typed / flow-typed / definitions / npm / papaparse_v4.x.x / test_papaparse_v4.x.x.js View on Github external
};
(Papa.unparse(explicitAnyData): string);

// $ExpectError
var explicitInvalidData: PapaParse$UnparseObject = {
  fields: ['One', 'Two'],
  data: 1
};
(Papa.unparse(explicitInvalidData): string);

// $ExpectError
var explicitInvalidFields: PapaParse$UnparseObject = {
  fields: 'One,Two',
  data: '1,2'
};
(Papa.unparse(explicitInvalidFields): string);

Papa.unparse({
  fields: ["3"],
  data: ["3"]
});

Papa.unparse({
  fields: ["3"],
  data: ["3"]
}, {
  quotes: true
});

Papa.SCRIPT_PATH;
Papa.LocalChunkSize;
github flow-typed / flow-typed / definitions / npm / papaparse_v4.x.x / test_papaparse_v4.x.x.js View on Github external
data: '1,2',
};
(Papa.unparse(explicit): string);

var explicitAnyData: PapaParse$UnparseObject = {
  fields: ['One', 'Two'],
  data: [1, 2]
};
(Papa.unparse(explicitAnyData): string);

// $ExpectError
var explicitInvalidData: PapaParse$UnparseObject = {
  fields: ['One', 'Two'],
  data: 1
};
(Papa.unparse(explicitInvalidData): string);

// $ExpectError
var explicitInvalidFields: PapaParse$UnparseObject = {
  fields: 'One,Two',
  data: '1,2'
};
(Papa.unparse(explicitInvalidFields): string);

Papa.unparse({
  fields: ["3"],
  data: ["3"]
});

Papa.unparse({
  fields: ["3"],
  data: ["3"]
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 CodeForAfrica / africanCOMMONS / bin / commons.js View on Github external
// Move file because of UTF8 issues with Jekyll
  var fileToMove = './dist/_data/users.json'
  var filePath = './dist/js/data/users.json'
  if (fs.existsSync(fileToMove)) {
    fs.removeSync(filePath)
    fs.moveSync(fileToMove, filePath)
  }

  var users = fs.readJsonSync(filePath)

  // Shuffle the users
  users = utils.shuffleArray(users)

  // Save to CSV
  fs.outputFileSync('./dist/_data/users.csv', Papa.unparse(users))

  console.log('Finished processing ' + users.length + ' users.')
}
github rexrainbow / phaser3-rex-notes / examples / papaparser / parse-csv.js View on Github external
create() {
        var csvString = `,2,3
4,5,6
7,8,9`;
        var data = Papa.parse(csvString, {
            dynamicTyping: true
        });
        console.log(data);  // a 3x3 array

        csvString = `name,hp,mp
4,5,6
7,8,9`;
        data = Papa.parse(csvString, {
            dynamicTyping: true,
            header: true
        });
        console.log(data);  // an object array with 2 rows
    }
github rexrainbow / phaser3-rex-notes / examples / papaparser / parse-csv.js View on Github external
create() {
        var csvString = `,2,3
4,5,6
7,8,9`;
        var data = Papa.parse(csvString, {
            dynamicTyping: true
        });
        console.log(data);  // a 3x3 array

        csvString = `name,hp,mp
4,5,6
7,8,9`;
        data = Papa.parse(csvString, {
            dynamicTyping: true,
            header: true
        });
        console.log(data);  // an object array with 2 rows
    }
github rexrainbow / phaser3-rex-notes / examples / lokijs / load-csv-table.js View on Github external
create() {
        var csvString = `name,hp,mp
Rex,100,20
Alice,300,40`;

        var csvTable = Papa.parse(csvString, {
            dynamicTyping: true,
            header: true
        }).data;

        // Create the database
        var db = new loki();

        // Create a collection
        var children = db.addCollection('children');

        // insert csv-table
        children.insert(csvTable);

        var result = children.chain().data();
        console.log(result);
    }
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});
    },

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 11 months ago

Package Health Score

83 / 100
Full package analysis