Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vanillaes/csv
A modern, fast, RFC 4180 compliant parser for JS
https://github.com/vanillaes/csv
csv csv-parser esm esmodule rfc4180
Last synced: about 1 month ago
JSON representation
A modern, fast, RFC 4180 compliant parser for JS
- Host: GitHub
- URL: https://github.com/vanillaes/csv
- Owner: vanillaes
- License: mit
- Created: 2019-05-07T08:25:14.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-08-22T19:34:05.000Z (4 months ago)
- Last Synced: 2024-11-07T07:38:58.379Z (about 2 months ago)
- Topics: csv, csv-parser, esm, esmodule, rfc4180
- Language: JavaScript
- Homepage:
- Size: 302 KB
- Stars: 98
- Watchers: 3
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - vanillaes/csv - A modern, fast, RFC 4180 compliant parser for JS (JavaScript)
README
CSV
CSV is a universal JavaScript CSV parser designed specifically to be simple, fast, and spec compliant.
## Features
- RFC Compliant
- ECMAScript Module
- Typescript Compatible## Imports
This package works isomorphically in browser and server-side JavaScript
### Browser
Import directly from the local path or a CDN
```html
import { parse } from 'path/to/csv/index.js'
```
The minified version can be imported from
```html
import { parse } from 'path/to/csv/index.min.js'
```
### Node
Install the package
```sh
npm install @vanillaes/csv
```Import using the module path
```javascript
import { parse } from '@vanillaes/csv'
```
## Usage### 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
```javascript
const csv = `
header1,header2,header3
aaa,bbb,ccc
zzz,yyy,xxx
`;
const parsed = 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
```javascript
const data = [
[ "header1", "header2", "header3" ],
[ "aaa", "bbb", "ccc" ],
[ "zzz", "yyy", "xxx" ]
];
const stringified = stringify(data)
console.log(stringified);
> "header1,header2,header3"
> "aaa,bbb,ccc"
> "zzz,yyy,xxx"
```## Typescript
Typings are generated from JSDoc using Typescript. They are 100% compatible with VSCode Intellisense and will work seamlessly with Typescript.