3.0.3 • Published 7 years ago

get-csv v3.0.3

Weekly downloads
204
License
ISC
Repository
github
Last release
7 years ago

A super-simple package that fetches a CSV file and parses its data into an object in one function.

Example

data.csv:

foo,bar
one,two

compile.js:

const getCSV = require('get-csv');
getCSV('data.csv')
  .then(rows => console.log(rows));

data will log as [{foo: "one", bar: "two"}].

You can pass a URL instead of a file path:

getCSV('http://www.path.to.my.doc.csv')
  .then(rows => /* some JS */);

You can also pass a stream:

getCSV(fs.createReadStream('data.csv'))
  .then(rows => /* some JS */);

Options

You can pass fast-csv parsing options as the second argument.

The headers option defaults to true when using getCSV, but you can override this by explicitly setting it false in the options argument. Like so:

getCSV('data.csv', {headers: false})
  .then(rows => console.log(rows));

Here, rows will log as [['foo','bar'],['one','two']].

Callbacks

getCSV also supports old-fashioned callbacks. Example:

getCSV('test.csv', function(err, data){
  /* some JS */
});
3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.3

8 years ago

2.1.2

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.6

9 years ago

2.0.5

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago