diff --git a/types/neat-csv/index.d.ts b/types/neat-csv/index.d.ts new file mode 100644 index 0000000000..7fadcc316a --- /dev/null +++ b/types/neat-csv/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for neat-csv 4.0 +// Project: https://github.com/sindresorhus/neat-csv +// Definitions by: Alex Ruble +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +import { Readable } from 'stream'; + +declare function neatCsv(input: neatCsv.Input, options?: neatCsv.Options): Promise; + +declare namespace neatCsv { + /** The CSV data to parse. */ + type Input = string | Buffer | Readable; + + /** A configuration object to be passed to csv-parser. */ + interface Options { + escape?: string; + headers?: ReadonlyArray | boolean; + mapHeaders?: (args: { header: string; index: number }) => string | null; + mapValues?: (args: { header: string; index: number; value: any }) => any; + newline?: string; + quote?: string; + raw?: boolean; + separator?: string; + skipLines?: number; + maxRowBytes?: number; + strict?: boolean; + } + + /** A representation of one row of the input CSV. */ + interface Row { + [header: string]: string; + } +} + +export = neatCsv; diff --git a/types/neat-csv/neat-csv-tests.ts b/types/neat-csv/neat-csv-tests.ts new file mode 100644 index 0000000000..18bd94632a --- /dev/null +++ b/types/neat-csv/neat-csv-tests.ts @@ -0,0 +1,10 @@ +import * as neatCsv from 'neat-csv'; + +const data: neatCsv.Input = 'type,part\nunicorn,horn\nrainbow,pink'; +const options: neatCsv.Options = { separator: ',' }; + +neatCsv(data); // $ExpectType Promise +const rowsPromise = neatCsv(data, options); // $ExpectType Promise + +rowsPromise.then(rows => + rows.map(({ type, part }: neatCsv.Row) => `type: ${type}, part: ${part}`)); diff --git a/types/neat-csv/tsconfig.json b/types/neat-csv/tsconfig.json new file mode 100644 index 0000000000..ea4ccaf99e --- /dev/null +++ b/types/neat-csv/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "neat-csv-tests.ts" + ] +} diff --git a/types/neat-csv/tslint.json b/types/neat-csv/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/neat-csv/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }