add folder lists array and make them filterable through regex
This commit is contained in:
parent
2fc132ab20
commit
8205da5284
24
dist/smartfile.fs.d.ts
vendored
24
dist/smartfile.fs.d.ts
vendored
@ -80,9 +80,29 @@ export declare let requireReload: (path: string) => any;
|
|||||||
* lists Folders in a directory on local disk
|
* lists Folders in a directory on local disk
|
||||||
* @returns Promise
|
* @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
|
* lists Folders SYNCHRONOUSLY in a directory on local disk
|
||||||
* @returns an array with the folder names as strings
|
* @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
86
dist/smartfile.fs.js
vendored
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mode":"default",
|
"mode":"default",
|
||||||
"codecov":true,
|
"codecov":true,
|
||||||
"coverageTreshold":80
|
"coverageTreshold":70
|
||||||
}
|
}
|
@ -175,11 +175,16 @@ export let requireReload = function(path:string){
|
|||||||
* lists Folders in a directory on local disk
|
* lists Folders in a directory on local disk
|
||||||
* @returns Promise
|
* @returns Promise
|
||||||
*/
|
*/
|
||||||
export let listFolders = function(pathArg:string){
|
export let listFolders = function(pathArg:string,regexFilter?:RegExp){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
|
let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
|
||||||
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
||||||
});
|
});
|
||||||
|
if(regexFilter){
|
||||||
|
folderArray = folderArray.filter((fileItem) => {
|
||||||
|
regexFilter.test(fileItem);
|
||||||
|
});
|
||||||
|
}
|
||||||
done.resolve(folderArray);
|
done.resolve(folderArray);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
@ -188,8 +193,83 @@ export let listFolders = function(pathArg:string){
|
|||||||
* lists Folders SYNCHRONOUSLY in a directory on local disk
|
* lists Folders SYNCHRONOUSLY in a directory on local disk
|
||||||
* @returns an array with the folder names as strings
|
* @returns an array with the folder names as strings
|
||||||
*/
|
*/
|
||||||
export let listFoldersSync = function(pathArg):string[]{
|
export let listFoldersSync = function(pathArg:string,regexFilter?:RegExp):string[]{
|
||||||
return plugins.fs.readdirSync(pathArg).filter(function(file) {
|
let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
|
||||||
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user