diff --git a/types/fs-readfile-promise/fs-readfile-promise-tests.ts b/types/fs-readfile-promise/fs-readfile-promise-tests.ts new file mode 100644 index 0000000000..9bd1ac070c --- /dev/null +++ b/types/fs-readfile-promise/fs-readfile-promise-tests.ts @@ -0,0 +1,32 @@ +import * as readFile from "fs-readfile-promise"; + +declare const path: string; +declare const encoding: string; +declare const nullable: null; +declare const options: { encoding: string, flag: string }; + +async function testPathOnly() { + return readFile(path); +} +async function testPathEncoding() { + return readFile(path, encoding); +} +async function testPathNull() { + return readFile(path, nullable); +} +async function testPathOption() { + return readFile(path, options); +} + +testPathOnly() + .then(console.log) + .catch(console.log); +testPathEncoding() + .then(console.log) + .catch(console.log); +testPathNull() + .then(console.log) + .catch(console.log); +testPathOption() + .then(console.log) + .catch(console.log); diff --git a/types/fs-readfile-promise/index.d.ts b/types/fs-readfile-promise/index.d.ts new file mode 100644 index 0000000000..b2d6aeab61 --- /dev/null +++ b/types/fs-readfile-promise/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for fs-readfile-promise 3.0 +// Project: https://github.com/shinnn/fs-readfile-promise +// Definitions by: Motosugi Murata +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +import { PathLike } from "fs"; +type PathType = PathLike | number; +type OptionsType = { encoding: string; flag?: string; } | string; + +export = fsReadFilePromise; + +/** + * Asynchronously reads the entire contents of a file. + * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. + * If a file descriptor is provided, the underlying file will _not_ be closed automatically. + * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag. + * If a flag is not provided, it defaults to `'r'`. + */ +declare function fsReadFilePromise(path: PathType, options: OptionsType): Promise; + +/** + * Asynchronously reads the entire contents of a file. + * @param path A path to a file. If a URL is provided, it must use the `file:` protocol. + * If a file descriptor is provided, the underlying file will _not_ be closed automatically. + */ +declare function fsReadFilePromise(path: PathType, options?: null): Promise; + +declare namespace fsReadFilePromise { } diff --git a/types/fs-readfile-promise/tsconfig.json b/types/fs-readfile-promise/tsconfig.json new file mode 100644 index 0000000000..3496c329e5 --- /dev/null +++ b/types/fs-readfile-promise/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fs-readfile-promise-tests.ts" + ] +} \ No newline at end of file diff --git a/types/fs-readfile-promise/tslint.json b/types/fs-readfile-promise/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fs-readfile-promise/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }