Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

csv-es

1.4.6 • Public • Published

CSV-ES

CSV-ES is a universal JavaScript CSV parser designed specifically to be simple, fast, and spec compliant.

GitHub Releases NPM Release Bundlephobia MIT License Latest Status Release Status

⚠️ Notice: EcmaScript Module Support in Node is Experimental ⚠️

Features

  • RFC Compliant
  • ECMAScript Module
  • CommonJS Bundle Included
  • Typescript Compatible

Installation

npm install csv-es
import CSV from 'csv-es';

CSV.parse()

Takes a string of CSV data and converts it to a 2 dimensional array of [entries][values]

Arguments

CSV.parse(csv, {options}, reviver(value, col, row)) : [entries][values]

  • csv - the CSV string to parse
  • options
    • typed - infer types (default false)
  • reviver - a custom function to modify the output (default (value) => value)

Example

import CSV from '/path/to/csv/index.js';
const csv = `
"header1,header2,header3"
"aaa,bbb,ccc"
"zzz,yyy,xxx"
`;
const parsed = CSV.parse(csv)
console.log(parsed);
> [
>   [ "header1", "header2", "header3" ],
>   [ "aaa", "bbb", "ccc" ],
>   [ "zzz", "yyy", "xxx" ]
> ]

CSV.stringify()

Takes a 2 dimensional array of [entries][values] and converts them to CSV

Arguments

CSV.stringify(array, {options}, replacer(value, col, row)) : string

  • array - the input array to stringify
  • options
    • eof - add a trailing newline at the end of file (default true)
  • replacer - a custom function to modify the values (default (value) => value)

Example

import CSV from '/path/to/csv/index.js';
const data = [
  [ "header1", "header2", "header3" ],
  [ "aaa", "bbb", "ccc" ],
  [ "zzz", "yyy", "xxx" ]
];
const stringified = CSV.stringify(data)
console.log(stringified);
> "header1,header2,header3"
> "aaa,bbb,ccc"
> "zzz,yyy,xxx"

CommonJS

A .cjs bundle is included for CommonJS compatibility

CSV.parse()

const CSV = require('csv-es');
const csv = // the csv string
const data = CSV.parse(csv);

CSV.stringify()

const CSV = require('csv-es');
const data = // the a 2-dimensional array
const csv = CSV.stringify(data);

Typings

Typings are generated from JSDoc using Typescript. They are 100% compatible with VSCode Intellisense and will work seamlessly with Typescript.

Install

npm i csv-es

DownloadsWeekly Downloads

196

Version

1.4.6

License

MIT

Unpacked Size

24.6 kB

Total Files

28

Last publish

Collaborators

  • avatar