Add promiseFiles and the sync version of files (#35237)

This commit is contained in:
jlismore 2019-05-13 22:19:59 +00:00 committed by Nathan Shively-Sanders
parent fcd45613c0
commit 32b5bf0bb7
2 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
// Type definitions for node-dir
// Project: https://github.com/fshost/node-dir
// Definitions by: Panu Horsmalahti <https://github.com/panuhorsmalahti>
// James Lismore <https://github.com/jlismore>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference types="node"/>
@ -66,6 +67,8 @@ export function readFiles(dir: string, options: Options, fileCallback: FileNamed
export function readFilesStream(dir: string, streamCallback: StreamCallback, finishedCallback?: FinishedCallback): void;
export function readFilesStream(dir: string, options: Options, streamCallback: StreamCallback, finishedCallback?: FinishedCallback): void;
export function files(dir: string, callback: (error: any, files: string[]) => void): void;
export function files(dir: string, syncOption: { sync: true }): string[];
export function promiseFiles(dir: string): Promise<string[]>;
export function subdirs(dir: string, callback: (error: any, subdirs: string[]) => void): void;
export function paths(dir: string, callback: (error: any, paths: PathsResult) => void): void;
export function paths(dir: string, combine: boolean, callback: (error: any, paths: string[] | PathsResult) => void): void;

View File

@ -74,6 +74,14 @@ dir.files("./", function(err, files) {
});
});
dir.files("./", { sync: true }).map(file => console.log(file.toLowerCase()));
dir.promiseFiles("./")
.then(files => {
console.log(files);
})
.catch(e => console.error(e));
dir.subdirs("./", function(err, subdirs) {
console.log(subdirs);
});