Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabiospampinato/csv-simple-parser
A simple, fast and configurable CSV parser.
https://github.com/fabiospampinato/csv-simple-parser
csv fast parser
Last synced: about 2 months ago
JSON representation
A simple, fast and configurable CSV parser.
- Host: GitHub
- URL: https://github.com/fabiospampinato/csv-simple-parser
- Owner: fabiospampinato
- License: mit
- Created: 2023-08-15T12:41:33.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-05T00:06:58.000Z (10 months ago)
- Last Synced: 2024-08-08T19:17:09.971Z (6 months ago)
- Topics: csv, fast, parser
- Language: TypeScript
- Homepage:
- Size: 1.21 MB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# CSV Simple Parser
A simple, fast and configurable CSV parser.
## Install
```sh
npm install --save csv-simple-parser
```## Usage
```ts
import parse from 'csv-simple-parser';{ // Parse a CSV string, as an array of arrays of strings
const csv = 'Name,Surname\n"John",Doe\nJane,"Doe"';
const result = parse ( csv ); // => [['Name', 'Surname'], ['John', 'Doe'], ['Jane', 'Doe']]
}{ // Parse a CSV string, as an array of objects, considering the first row the headers row
const csv = 'Name,Surname\n"John",Doe\nJane,"Doe"';
const options = { header: true };
const result = parse ( csv, options ); // => [{ Name: 'John', Surname: 'Doe' }, { Name: 'Jane', Surname: 'Doe' }]
}{ // Parse a CSV string, inferring number types and null types automatically, and boolean types with a custom transform function
const csv = 'Name,Surname,Age,Pirate,Parent\n"John",Doe,50,1,null\nJane,"Doe",50,0,NULL';
const transform = ( value, x, y, quoted ) => quoted ? value : value === '0' ? false : value === '1' ? true : value;
const options = { header: true, infer: true, transform };
const result = parse ( csv, options ); // => [{ Name: 'John', Surname: 'Doe', Age: 50, Pirate: true, Parent: null }, { Name: 'Jane', Surname: 'Doe', Age: 50, Pirate: false, Parent: null }]
}{ // Parse a CSV-like string, with custom delimiters and quotes
const csv = "Name|Surname\n'John'|Doe\nJane|'Doe'";
const options = { header: true, delimiter: '|', quote: "'" };
const result = parse ( csv, options ); // => [{ Name: 'John', Surname: 'Doe' }, { Name: 'Jane', Surname: 'Doe' }]
}{ // Parse a potentially malformed CSV-like string, which could have inconsistent newlines
const csv = 'Name,Surname\r\n"John",Doe\nJane,"Doe"';
const options = { optimistic: false };
const result = parse ( csv ); // => [['Name', 'Surname'], ['John', 'Doe'], ['Jane', 'Doe']]
}
```## License
MIT © Fabio Spampinato