Merge pull request #24064 from ibezkrovnyi/pify

[pify] include and exclude options should allow multiple entries (for TypeScript 2.7+)
This commit is contained in:
Armando Aguirre
2018-03-06 12:27:08 -08:00
committed by GitHub
2 changed files with 19 additions and 2 deletions

View File

@@ -9,8 +9,8 @@ interface PromiseModule {
interface PifyOptions {
multiArgs?: boolean,
include?: [string | RegExp],
exclude?: [string | RegExp],
include?: Array<string | RegExp>,
exclude?: Array<string | RegExp>,
excludeMain?: boolean,
errorFirst?: boolean,
promiseModule?: PromiseModule

View File

@@ -31,3 +31,20 @@ pify(fs.readFile, { promiseModule: Promise})('bar.txt').then((result: string) =>
pify(fs.exists, { errorFirst: false })('foo.txt').then((result: boolean) => assert(result.toString(), true.toString()));
// include/exclude with multiple entries
const module = {
f1: (callback: Function) => callback(),
f2: (callback: Function) => callback(),
f3: (callback: Function) => callback(),
};
const include = pify(module, { include: ['f1', 'f2'] });
if (include.f1 === module.f1) throw new Error();
if (include.f2 === module.f2) throw new Error();
if (include.f3 !== module.f3) throw new Error();
const exclude = pify(module, { exclude: ['f1', 'f2'] });
if (include.f1 !== module.f1) throw new Error();
if (include.f2 !== module.f2) throw new Error();
if (include.f3 === module.f3) throw new Error();