Socket
Socket
Sign inDemoInstall

csv-es

Package Overview
Dependencies
0
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    csv-es

A modern, fast, RFC 4180 compliant parser for JS


Version published
Weekly downloads
55
increased by323.08%
Maintainers
1
Install size
23.9 kB
Created
Weekly downloads
 

Readme

Source

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

Features

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

Installation

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

or

import { parse, stringify } 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, row, col)) : [entries][values]

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

1 Values for row and col are 1-based.

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, row, col)) : string

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

1 Values for row and col are 1-based.

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);

Typescript

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

Keywords

FAQs

Last updated on 23 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc