fix regex filter

This commit is contained in:
Philipp Kunz 2016-06-28 09:59:59 +02:00
parent 8c386ee91c
commit 2e2b8351f8
4 changed files with 54 additions and 18 deletions

18
dist/smartfile.fs.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,24 @@ describe("smartfile".yellow,function(){
}); });
}); });
}); });
describe(".listFilesSync()",function(){
it("should get the file type from a string",function(){
smartfile.fs.listFilesSync("./test/").should.containDeep([ "mytest.json"]);
smartfile.fs.listFilesSync("./test/").should.not.containDeep([ "notExistentFile"]);
smartfile.fs.listFilesSync("./test/",/mytest\.json/).should.containDeep([ "mytest.json"]);
smartfile.fs.listFilesSync("./test/",/mytests.json/).should.not.containDeep([ "mytest.json"]);
});
});
describe(".listFiles()",function(){
it("should get the file type from a string",function(done){
smartfile.fs.listFiles("./test/")
.then(function(folderArrayArg){
folderArrayArg.should.containDeep([ "mytest.json"]);
folderArrayArg.should.not.containDeep([ "notExistentFile"]);
done();
});
});
});
describe(".copy()".yellow,function(){ describe(".copy()".yellow,function(){
it("should copy a directory",function(){ it("should copy a directory",function(){
smartfile.fs.copy("./test/testfolder/","./test/temp/") smartfile.fs.copy("./test/testfolder/","./test/temp/")

View File

@ -182,7 +182,7 @@ export let listFolders = function(pathArg:string,regexFilter?:RegExp){
}); });
if(regexFilter){ if(regexFilter){
folderArray = folderArray.filter((fileItem) => { folderArray = folderArray.filter((fileItem) => {
regexFilter.test(fileItem); return regexFilter.test(fileItem);
}); });
} }
done.resolve(folderArray); done.resolve(folderArray);
@ -199,7 +199,7 @@ export let listFoldersSync = function(pathArg:string,regexFilter?:RegExp):string
}); });
if(regexFilter){ if(regexFilter){
folderArray = folderArray.filter((fileItem) => { folderArray = folderArray.filter((fileItem) => {
regexFilter.test(fileItem); return regexFilter.test(fileItem);
}); });
}; };
return folderArray; return folderArray;
@ -217,11 +217,11 @@ export let listFiles = function(pathArg:string, regexFilter?:RegExp){
}); });
if(regexFilter){ if(regexFilter){
fileArray = fileArray.filter((fileItem) => { fileArray = fileArray.filter((fileItem) => {
regexFilter.test(fileItem); return regexFilter.test(fileItem);
}); });
}; };
done.resolve(fileArray); done.resolve(fileArray);
return done.promise(); return done.promise;
}; };
/** /**
@ -234,7 +234,7 @@ export let listFilesSync = function(pathArg:string, regexFilter?:RegExp):string[
}); });
if(regexFilter){ if(regexFilter){
fileArray = fileArray.filter((fileItem) => { fileArray = fileArray.filter((fileItem) => {
regexFilter.test(fileItem); return regexFilter.test(fileItem);
}); });
}; };
return fileArray; return fileArray;
@ -249,11 +249,11 @@ export let listAllItems = function(pathArg:string, regexFilter?:RegExp){
let allItmesArray = plugins.fs.readdirSync(pathArg); let allItmesArray = plugins.fs.readdirSync(pathArg);
if(regexFilter){ if(regexFilter){
allItmesArray = allItmesArray.filter((fileItem) => { allItmesArray = allItmesArray.filter((fileItem) => {
regexFilter.test(fileItem); return regexFilter.test(fileItem);
}); });
}; };
done.resolve(allItmesArray); done.resolve(allItmesArray);
return done.promise(); return done.promise;
}; };
/** /**
@ -266,7 +266,7 @@ export let listAllItemsSync = function(pathArg:string, regexFilter?:RegExp):stri
}); });
if(regexFilter){ if(regexFilter){
allItmesArray = allItmesArray.filter((fileItem) => { allItmesArray = allItmesArray.filter((fileItem) => {
regexFilter.test(fileItem); return regexFilter.test(fileItem);
}); });
}; };
return allItmesArray; return allItmesArray;