From e128fc0753d17241c49aa6569293900a2f5af05c Mon Sep 17 00:00:00 2001 From: Andrey Lalev Date: Sat, 11 Nov 2017 08:12:01 +0200 Subject: [PATCH] Create definitions for find@0.2 --- types/find/find-tests.ts | 32 +++++++++++ types/find/index.d.ts | 116 +++++++++++++++++++++++++++++++++++++++ types/find/tsconfig.json | 23 ++++++++ types/find/tslint.json | 1 + 4 files changed, 172 insertions(+) create mode 100644 types/find/find-tests.ts create mode 100644 types/find/index.d.ts create mode 100644 types/find/tsconfig.json create mode 100644 types/find/tslint.json diff --git a/types/find/find-tests.ts b/types/find/find-tests.ts new file mode 100644 index 0000000000..c6c1cd04f5 --- /dev/null +++ b/types/find/find-tests.ts @@ -0,0 +1,32 @@ +import * as find from "find"; + +const stringPattern = ".d.ts"; +const regexPattern = /ts(config|lint)\.json/; +const rootDir = "."; + +const emptyCb = (): void => { }; +const errorCb = (err: Error): void => { }; +const stringArrayCallback = (paths: string[]): void => { }; +const singleStringCb = (paths: string): void => { }; + +find.file(rootDir, (dirs: string[]): void => { }).error(emptyCb); // $ExpectType void +find.file(rootDir, (dirs: string[]): void => { }).error(errorCb); // $ExpectType void +find.file(stringPattern, rootDir, (dirs: string[]): void => { }).error(errorCb); // $ExpectType void +find.file(regexPattern, rootDir, (dirs: string[]): void => { }).error(errorCb); // $ExpectType void +find.fileSync(rootDir); // $ExpectType string[] +find.fileSync(stringPattern, rootDir); // $ExpectType string[] +find.fileSync(regexPattern, rootDir); // $ExpectType string[] +find.eachFile(rootDir, singleStringCb).end(emptyCb).error(errorCb).end(emptyCb); // $ExpectType FindEachStream +find.eachFile(stringPattern, rootDir, singleStringCb).end(emptyCb).error(errorCb).end(emptyCb); // $ExpectType FindEachStream +find.eachFile(regexPattern, rootDir, singleStringCb).end(emptyCb).error(errorCb).end(emptyCb); // $ExpectType FindEachStream + +find.dir(stringPattern, rootDir, (dirs: string[]): void => { }).error(emptyCb); // $ExpectType void +find.dir(stringPattern, rootDir, (dirs: string[]): void => { }).error(errorCb); // $ExpectType void +find.dir(regexPattern, rootDir, (dirs: string[]): void => { }).error(errorCb); // $ExpectType void +find.dir(rootDir, (dirs: string[]): void => { }).error(errorCb); // $ExpectType void +find.dirSync(rootDir); // $ExpectType string[] +find.dirSync(stringPattern, rootDir); // $ExpectType string[] +find.dirSync(regexPattern, rootDir); // $ExpectType string[] +find.eachDir(rootDir, singleStringCb).end(emptyCb).error(errorCb).end(emptyCb); // $ExpectType FindEachStream +find.eachDir(stringPattern, rootDir, singleStringCb).end(emptyCb).error(errorCb).end(emptyCb); // $ExpectType FindEachStream +find.eachDir(regexPattern, rootDir, singleStringCb).end(emptyCb).error(errorCb).end(emptyCb); // $ExpectType FindEachStream diff --git a/types/find/index.d.ts b/types/find/index.d.ts new file mode 100644 index 0000000000..61166669db --- /dev/null +++ b/types/find/index.d.ts @@ -0,0 +1,116 @@ +// Type definitions for find 0.2 +// Project: https://github.com/yuanchuan/find#readme +// Definitions by: Andrey Lalev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface AsyncFindStream { + /** + * Handling errors in asynchronous interfaces. + * @param callback The callback that is called upon an error + */ + error(callback: (() => void) | ((err: Error) => void)): void; +} + +export interface FindEachStream { + /** + * Handling errors in asynchronous interfaces. + * @param callback The callback that is called upon an error + */ + error(callback: (() => void) | ((err: Error) => void)): FindEachStream; + + /** + * Detect end in find.eachfile and find.eachdir. + * @param callback The callback called at the end of find.eachfile and find.eachdir + */ + end(callback: () => void): FindEachStream; +} + +/** + * Find all files in a given directory asynchronously. + * @param root The root directory + * @param callback A callback that accepts an array of the found files + */ +export function file(root: string, callback: (files: string[]) => void): AsyncFindStream; + +/** + * Find all files that match a glob pattern in a given directory asynchronously. + * @param pattern The pattern to filter the files with + * @param root The root directory + * @param callback A callback that accepts an array of the found files + */ +export function file(pattern: string | RegExp, root: string, callback: (files: string[]) => void): AsyncFindStream; + +/** + * Find all files in a given directory asynchronously. + * @param root The root directory + * @param callback A callback that accepts each file separately + */ +export function eachFile(root: string, callback: (file: string) => void): FindEachStream; + +/** + * Find all files that match a glob pattern in a given directory asynchronously. + * @param pattern The pattern to filter the files with + * @param root The root directory + * @param callback A callback that accepts an array of the found files + */ +export function eachFile(pattern: string | RegExp, root: string, callback: (file: string) => void): FindEachStream; + +/** + * Find all files in a given directory synchronously. + * @param root The root directory + * @returns The files that have been found + */ +export function fileSync(root: string): string[]; + +/** + * Find all files that match a glob pattern in a given directory synchronously. + * @param pattern The pattern to filter the files with + * @param root The root directory + * @returns The files that have been found + */ +export function fileSync(pattern: string | RegExp, root: string): string[]; + +/** + * Find all directories in a given directory asynchronously. + * @param root The root directory + * @param callback A callback that accepts an array of the found directories + */ +export function dir(root: string, callback: (directories: string[]) => void): AsyncFindStream; + +/** + * Find all directories that match a glob pattern in a given directory asynchronously. + * @param pattern The pattern to filter the directories with + * @param root The root directory + * @param callback A callback that accepts an array of the found directories + */ +export function dir(pattern: RegExp | string, root: string, callback: (directories: string[]) => void): AsyncFindStream; + +/** + * Find all directories in a given directory synchronously. + * @param root The root directory + * @returns The directories that have been found + */ +export function dirSync(root: string): string[]; + +/** + * Find all directories that match a glob pattern in a given directory synchronously. + * @param pattern The pattern to filter the directories with + * @param root The root directory + * @returns The directories that have been found + */ +export function dirSync(pattern: string | RegExp, root: string): string[]; + +/** + * Find all directories in a given directory asynchronously. + * @param root The root directory + * @param callback A callback that accepts each of the found directories separately + */ +export function eachDir(root: string, callback: (directory: string) => void): FindEachStream; + +/** + * Find all directories that match a glob pattern in a given directory asynchronously. + * @param pattern The pattern to filter the directories with + * @param root The root directory + * @param callback A callback that accepts each of the found directories separately + */ +export function eachDir(pattern: string | RegExp, root: string, callback: (directory: string) => void): FindEachStream; diff --git a/types/find/tsconfig.json b/types/find/tsconfig.json new file mode 100644 index 0000000000..e231e78ff5 --- /dev/null +++ b/types/find/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", + "find-tests.ts" + ] +} diff --git a/types/find/tslint.json b/types/find/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/find/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }