Create definitions for find@0.2

This commit is contained in:
Andrey Lalev 2017-11-11 08:12:01 +02:00
parent 8aac41c1e2
commit e128fc0753
4 changed files with 172 additions and 0 deletions

32
types/find/find-tests.ts Normal file
View File

@ -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

116
types/find/index.d.ts vendored Normal file
View File

@ -0,0 +1,116 @@
// Type definitions for find 0.2
// Project: https://github.com/yuanchuan/find#readme
// Definitions by: Andrey Lalev <https://github.com/andypyrope>
// 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;

23
types/find/tsconfig.json Normal file
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",
"find-tests.ts"
]
}

1
types/find/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }