Merge pull request #31461 from BendingBender/parse-columns

[parse-columns] Add types
This commit is contained in:
Nathan Shively-Sanders
2018-12-17 09:02:27 -08:00
committed by GitHub
4 changed files with 77 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for parse-columns 1.3
// Project: https://github.com/sindresorhus/parse-columns
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = parseColumns;
declare function parseColumns(
input: string,
options?: parseColumns.BaseOptions
): Array<{ [key: string]: string }>;
declare function parseColumns<T>(
input: string,
options: parseColumns.Options<T>
): Array<{ [key: string]: T }>;
declare namespace parseColumns {
interface BaseOptions {
separator?: string;
headers?: ReadonlyArray<string>;
}
interface Options<T> extends BaseOptions {
transform: (element: string, header: string, columnIndex: number, rowIndex: number) => T;
}
}
@@ -0,0 +1,27 @@
import parseColumns = require('parse-columns');
// $ExpectType { [key: string]: string; }[]
parseColumns('foo');
// $ExpectType { [key: string]: string; }[]
parseColumns('foo', { separator: ' ' });
// $ExpectType { [key: string]: string; }[]
parseColumns('foo', { headers: ['foo', 'bar'] });
// $ExpectType { [key: string]: string | number; }[]
parseColumns('foo', {
transform(el, header, columnIndex, rowIndex) {
// $ExpectType string
el;
// $ExpectType string
header;
// $ExpectType number
columnIndex;
// $ExpectType number
rowIndex;
if (columnIndex >= 1 && columnIndex <= 3) {
return Number(el);
}
return el;
},
});
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"parse-columns-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }