mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #31461 from BendingBender/parse-columns
[parse-columns] Add types
This commit is contained in:
Vendored
+26
@@ -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;
|
||||
},
|
||||
});
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user