Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 20, 2019
1 parent a43ceb0 commit fe8ce39
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ language: node_js
node_js:
- '10'
- '8'
- '6'
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const toReadableStream = require('to-readable-stream');
const csvParser = require('csv-parser');
const getStream = require('get-stream');

module.exports = (input, options) => {
if (typeof input === 'string' || Buffer.isBuffer(input)) {
input = toReadableStream(input);
module.exports = async (data, options) => {
if (typeof data === 'string' || Buffer.isBuffer(data)) {
data = toReadableStream(data);
}

return getStream.array(input.pipe(csvParser(options)));
// TODO: Use `stream.pipeline` here when targeting Node.js 10
return getStream.array(data.pipe(csvParser(options)));
};
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -29,7 +29,6 @@
"separator",
"text",
"string",
"str",
"buffer",
"stream",
"parser"
Expand All @@ -40,7 +39,7 @@
"to-readable-stream": "^1.0.0"
},
"devDependencies": {
"ava": "^0.25.0",
"xo": "^0.23.0"
"ava": "^1.4.1",
"xo": "^0.24.0"
}
}
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $ npm install neat-csv

```js
const neatCsv = require('neat-csv');

const csv = 'type,part\nunicorn,horn\nrainbow,pink';

(async () => {
Expand All @@ -29,17 +30,17 @@ const csv = 'type,part\nunicorn,horn\nrainbow,pink';

### neatCsv(data, [options])

Returns a `Promise<Object[]>` with the parsed CSV.
Returns a `Promise<object[]>` with the parsed CSV.

#### data

Type: `string` `Buffer` `Stream`
Type: `string | Buffer | stream.Readable`

CSV data to parse.

#### options

Type: `Object`
Type: `object`

See the `csv-parser` [options](https://github.com/mafintosh/csv-parser#options).

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ test('stream', async t => {
});

test('error', async t => {
await t.throws(neatCsv('name,val\nfoo,1,3\nbar,2', {strict: true}), /Row length does not match headers/);
await t.throwsAsync(neatCsv('name,val\nfoo,1,3\nbar,2', {strict: true}), /Row length does not match headers/);
});

0 comments on commit fe8ce39

Please sign in to comment.