mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #31222 from Calamitizer/neat-csv
Add type definitions for neat-csv
This commit is contained in:
Vendored
+36
@@ -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;
|
||||
@@ -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}`));
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user