-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a079ca
commit ea80e37
Showing
3 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/// <reference types="node"/> | ||
import {Readable as ReadableStream} from 'stream'; | ||
import {Options as CsvParserOptions} from 'csv-parser'; | ||
|
||
declare namespace neatCsv { | ||
type Options = CsvParserOptions; | ||
|
||
interface Row { | ||
[header: string]: string; | ||
} | ||
} | ||
|
||
/** | ||
Fast CSV parser. | ||
Convenience wrapper around the super-fast streaming [`csv-parser`](https://github.com/mafintosh/csv-parser) module. Use that one if you want streamed parsing. | ||
@param data - CSV data to parse. | ||
@param options - See the `csv-parser` [options](https://github.com/mafintosh/csv-parser#options). | ||
@example | ||
``` | ||
import neatCsv = require('neat-csv'); | ||
const csv = 'type,part\nunicorn,horn\nrainbow,pink'; | ||
(async () => { | ||
console.log(await neatCsv(csv)); | ||
//=> [{type: 'unicorn', part: 'horn'}, {type: 'rainbow', part: 'pink'}] | ||
})(); | ||
``` | ||
*/ | ||
declare function neatCsv( | ||
data: string | Buffer | ReadableStream, | ||
options?: neatCsv.Options | ||
): Promise<neatCsv.Row[]>; | ||
|
||
export = neatCsv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {expectType} from 'tsd'; | ||
import * as fs from 'fs'; | ||
import toReadableStream = require('to-readable-stream'); | ||
import neatCsv = require('.'); | ||
|
||
const options: neatCsv.Options = {}; | ||
const csvText = 'type,part\nunicorn,horn\nrainbow,pink'; | ||
|
||
expectType<Promise<neatCsv.Row[]>>(neatCsv(csvText)); | ||
expectType<Promise<neatCsv.Row[]>>(neatCsv(Buffer.from(csvText))); | ||
expectType<Promise<neatCsv.Row[]>>(neatCsv(toReadableStream(csvText))); | ||
expectType<Promise<neatCsv.Row[]>>(neatCsv(fs.createReadStream('test.csv'))); | ||
expectType<Promise<neatCsv.Row[]>>(neatCsv(csvText, {separator: ','})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters