Updated to be more efficient

This commit is contained in:
2020-12-24 07:19:09 +11:00
parent 0a007862e7
commit 992e025e6b
2 changed files with 40 additions and 29 deletions

View File

@@ -6,8 +6,9 @@ efficient and no dependencies.
Only one method is provided;
```js
const csv = 'Name,Age,Location\nDom,26,Sydney\nSteve,30,New York';
parseCSV(csv, function(line) {
console.log(line.name);//Dom then Steve
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.