JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 412
  • Score
    100M100P100Q86574F
  • License MIT

Export CSV files from javascript objects in the browser

Package Exports

  • csvexport

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (csvexport) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

CsvExport

Export CSV files from javascript objects in the browser

Usage

let exporter = Export.create();

let people = [
  {name: "Alice", age: 20},
  {name: "Bob", age: 19},
  {name: "Charlie", age: 30}
];

exporter.downloadCsv(people);

Demo

A live demo is available at https://edamtoft.github.io/CsvExport/

Install

Configuration

Export.create takes an options object which supports the following:

  • delimiter: specify a custom delimeter (string; optional; default = ",")
  • contentType: specity a custom contentType (string; optional; default = "text/csv")
  • filename: a name for the file to download (string; options; default = "export.csv")
  • includeHeaders: choose to include or exclude the headers as the first row (boolean; optional; default = true)
  • columns: choose which columns to include. If not specified, will use the properties of the first data item (array; optional)
  • headers: object which maps property names to headers (object; optional)
  • formatters: object which maps property names to a function which will return the formatted value (object; optional)
  • byteOrderMark: A unicode character to be placed at the beginning of the file to help open utf-8 csv in excel (string; optional)

Examples

let exporter = Export.create({
  delimiter: "\t",
  contentType: "text/tab-separated-values",
  filename: "some-filename.tsv",
  includeHeaders: "false",
  columns: ["name","age"],
  headers: {
    name: "Person's Name",
    age: "Person's Age"
  },
  formatters: {
    age: age => age + " years old"
  },
  byteOrderMark: '\uFEFF'
});

exporter.downloadCsv(people);