Merge pull request #31222 from Calamitizer/neat-csv

Add type definitions for neat-csv
This commit is contained in:
Nathan Shively-Sanders
2018-12-17 15:13:53 -08:00
committed by GitHub
4 changed files with 70 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
// Type definitions for neat-csv 4.0
// Project: https://github.com/sindresorhus/neat-csv
// Definitions by: Alex Ruble <https://github.com/calamitizer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { Readable } from 'stream';
declare function neatCsv(input: neatCsv.Input, options?: neatCsv.Options): Promise<neatCsv.Row[]>;
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<string> | 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;
+10
View File
@@ -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<Row[]>
const rowsPromise = neatCsv(data, options); // $ExpectType Promise<Row[]>
rowsPromise.then(rows =>
rows.map(({ type, part }: neatCsv.Row) => `type: ${type}, part: ${part}`));
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }