add folder lists array and make them filterable through regex

This commit is contained in:
Philipp Kunz 2016-06-28 08:40:22 +02:00
parent 2fc132ab20
commit 8205da5284
4 changed files with 188 additions and 10 deletions

View File

@ -80,9 +80,29 @@ export declare let requireReload: (path: string) => any;
* lists Folders in a directory on local disk
* @returns Promise
*/
export declare let listFolders: (pathArg: string) => any;
export declare let listFolders: (pathArg: string, regexFilter?: RegExp) => any;
/**
* lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export declare let listFoldersSync: (pathArg: any) => string[];
export declare let listFoldersSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists Files in a directory on local disk
* @returns Promise
*/
export declare let listFiles: (pathArg: string, regexFilter?: RegExp) => any;
/**
* lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export declare let listFilesSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise
*/
export declare let listAllItems: (pathArg: string, regexFilter?: RegExp) => any;
/**
* lists all items (folders AND files) SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export declare let listAllItemsSync: (pathArg: string, regexFilter?: RegExp) => string[];

86
dist/smartfile.fs.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
{
"mode":"default",
"codecov":true,
"coverageTreshold":80
"coverageTreshold":70
}

View File

@ -175,11 +175,16 @@ export let requireReload = function(path:string){
* lists Folders in a directory on local disk
* @returns Promise
*/
export let listFolders = function(pathArg:string){
export let listFolders = function(pathArg:string,regexFilter?:RegExp){
let done = plugins.q.defer();
let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
if(regexFilter){
folderArray = folderArray.filter((fileItem) => {
regexFilter.test(fileItem);
});
}
done.resolve(folderArray);
return done.promise;
};
@ -188,8 +193,83 @@ export let listFolders = function(pathArg:string){
* lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listFoldersSync = function(pathArg):string[]{
return plugins.fs.readdirSync(pathArg).filter(function(file) {
export let listFoldersSync = function(pathArg:string,regexFilter?:RegExp):string[]{
let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
if(regexFilter){
folderArray = folderArray.filter((fileItem) => {
regexFilter.test(fileItem);
});
};
return folderArray;
};
/**
* lists Files in a directory on local disk
* @returns Promise
*/
export let listFiles = function(pathArg:string, regexFilter?:RegExp){
let done = plugins.q.defer();
let fileArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
});
if(regexFilter){
fileArray = fileArray.filter((fileItem) => {
regexFilter.test(fileItem);
});
};
done.resolve(fileArray);
return done.promise();
};
/**
* lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listFilesSync = function(pathArg:string, regexFilter?:RegExp):string[]{
let fileArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
});
if(regexFilter){
fileArray = fileArray.filter((fileItem) => {
regexFilter.test(fileItem);
});
};
return fileArray;
};
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise
*/
export let listAllItems = function(pathArg:string, regexFilter?:RegExp){
let done = plugins.q.defer();
let allItmesArray = plugins.fs.readdirSync(pathArg);
if(regexFilter){
allItmesArray = allItmesArray.filter((fileItem) => {
regexFilter.test(fileItem);
});
};
done.resolve(allItmesArray);
return done.promise();
};
/**
* lists all items (folders AND files) SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listAllItemsSync = function(pathArg:string, regexFilter?:RegExp):string[]{
let allItmesArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
});
if(regexFilter){
allItmesArray = allItmesArray.filter((fileItem) => {
regexFilter.test(fileItem);
});
};
return allItmesArray;
};