diff --git a/types/parse-columns/index.d.ts b/types/parse-columns/index.d.ts new file mode 100644 index 0000000000..cbe7c9d8c7 --- /dev/null +++ b/types/parse-columns/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for parse-columns 1.3 +// Project: https://github.com/sindresorhus/parse-columns +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = parseColumns; + +declare function parseColumns( + input: string, + options?: parseColumns.BaseOptions +): Array<{ [key: string]: string }>; +declare function parseColumns( + input: string, + options: parseColumns.Options +): Array<{ [key: string]: T }>; + +declare namespace parseColumns { + interface BaseOptions { + separator?: string; + headers?: ReadonlyArray; + } + + interface Options extends BaseOptions { + transform: (element: string, header: string, columnIndex: number, rowIndex: number) => T; + } +} diff --git a/types/parse-columns/parse-columns-tests.ts b/types/parse-columns/parse-columns-tests.ts new file mode 100644 index 0000000000..51f7ff7661 --- /dev/null +++ b/types/parse-columns/parse-columns-tests.ts @@ -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; + }, +}); diff --git a/types/parse-columns/tsconfig.json b/types/parse-columns/tsconfig.json new file mode 100644 index 0000000000..aceda8a52a --- /dev/null +++ b/types/parse-columns/tsconfig.json @@ -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" + ] +} diff --git a/types/parse-columns/tslint.json b/types/parse-columns/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/parse-columns/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }