Added Types and Unit tests

This commit is contained in:
2020-12-24 07:44:13 +11:00
parent 992e025e6b
commit d13c712be8
7 changed files with 3784 additions and 6 deletions

View File

@@ -5,10 +5,26 @@ efficient and no dependencies.
## Usage
Only one method is provided;
```js
const csv = 'Name,Age,Location\nDom,26,Sydney\nSteve,30,New York';
const csv = 'Name,Age,Location\nDom,26,"Sydney, Australia"\nSteve,30,"New York, USA"';
parseCSV(csv, function(headers, line, index) {
console.log(index, '-', line[headers.indexOf('Name')]);//1 - Dom
return true;//Return false to break loop
})
```
To stay efficient we ask for a callback that is fired for every line parsed.
To stay efficient we ask for a callback that is fired for every line parsed.
## Options
Options can be provided if necessary;
```js
parseCSV(csv, (headers,line,index) => true, {
skipBlanks: false
});
```
Current Options;
```
skipBlanks - True or False, whether or not to skip blank lines
```
## Testing
Tests are written in jest. Run `yarn test`