diff --git a/pify/pify-tests.ts b/pify/pify-tests.ts new file mode 100644 index 000000000..b80657df7 --- /dev/null +++ b/pify/pify-tests.ts @@ -0,0 +1,31 @@ +/// +/// + +import * as pify from 'pify'; +import * as Bluebird from 'bluebird'; + +function assert(actual: string, expected: string): void { + if (actual !== expected) { + throw new Error(`${JSON.stringify(actual)} !== ${JSON.stringify(expected)}`); + } +} + +const fs = { + readFile: (file: string, callback: Function) => { + let result: any = undefined; + + if (file === 'foo.txt') { + result = 'foo'; + } else if (file === 'bar.txt') { + result = 'bar'; + } + + callback(undefined, result); + } +}; + +const fsP = pify(fs); +fsP.readFile('foo.txt').then((result: string) => assert(result, 'foo')); + +pify(fs.readFile)('foo.txt').then((result: string) => assert(result, 'foo')); +pify(fs.readFile, Bluebird)('bar.txt').then((result: string) => assert(result, 'bar')); \ No newline at end of file diff --git a/pify/pify.d.ts b/pify/pify.d.ts new file mode 100644 index 000000000..41770873e --- /dev/null +++ b/pify/pify.d.ts @@ -0,0 +1,21 @@ +// Type definitions for pify +// Project: https://github.com/sindresorhus/pify +// Definitions by: Sam Verschueren +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "pify" { + interface PifyOptions { + multiArgs?: boolean, + include?: [string | RegExp], + exclude?: [string | RegExp], + excludeMain?: boolean + } + + function pify(input: Function, promiseModule?: Function, options?: PifyOptions): (...args:any[]) => Promise; + function pify(input: any, promiseModule?: Function, options?: PifyOptions): any; + function pify(input: Function, options?: PifyOptions): (...args:any[]) => Promise; + function pify(input: any, options?: PifyOptions): any; + + namespace pify {} + export = pify; +} \ No newline at end of file