now has get.folders() and get.foldersSync function

This commit is contained in:
Philipp Kunz 2016-04-14 20:33:58 +02:00
parent aed2c92b75
commit 4b1f3d234b
5 changed files with 79 additions and 3 deletions

15
dist/smartfile.get.js vendored
View File

@ -6,5 +6,18 @@ exports.filetype = function (pathArg) {
var fileType = extName.replace(/\.([a-z]*)/, "$1"); //remove . form fileType var fileType = extName.replace(/\.([a-z]*)/, "$1"); //remove . form fileType
return fileType; return fileType;
}; };
exports.foldersSync = function (pathArg) {
return plugins.fs.readdirSync(pathArg).filter(function (file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
};
exports.folders = function (pathArg) {
var done = plugins.q.defer();
var folderArray = plugins.fs.readdirSync(pathArg).filter(function (file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
done.resolve(folderArray);
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5nZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRXJDLGdCQUFRLEdBQUcsVUFBUyxPQUFjO0lBQ3pDLElBQUksT0FBTyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzVDLElBQUksUUFBUSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsWUFBWSxFQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsd0JBQXdCO0lBQzNFLE1BQU0sQ0FBQyxRQUFRLENBQUM7QUFDcEIsQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0ZmlsZS5nZXQuanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwiLi90eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgc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HlwZSA9IGV4dE5hbWUucmVwbGFjZSgvXFwuKFthLXpdKikvLFwiJDFcIik7IC8vcmVtb3ZlIC4gZm9ybSBmaWxlVHlwZVxuICAgIHJldHVybiBmaWxlVHlwZTtcbn07XG5cbmV4cG9ydCBsZXQgZm9sZGVyc1N5bmMgPSBmdW5jdGlvbihwYXRoQXJnKXtcbiAgICByZXR1cm4gcGx1Z2lucy5mcy5yZWFkZGlyU3luYyhwYXRoQXJnKS5maWx0ZXIoZnVuY3Rpb24oZmlsZSkge1xuICAgICAgICByZXR1cm4gcGx1Z2lucy5mcy5zdGF0U3luYyhwbHVnaW5zLnBhdGguam9pbihwYXRoQXJnLCBmaWxlKSkuaXNEaXJlY3RvcnkoKTtcbiAgICB9KTtcbn07XG5cbmV4cG9ydCBsZXQgZm9sZGVycyA9IGZ1bmN0aW9uKHBhdGhBcmc6c3RyaW5nKXtcbiAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xuICAgIGxldCBmb2xkZXJBcnJheSA9IHBsdWdpbnMuZnMucmVhZGRpclN5bmMocGF0aEFyZykuZmlsdGVyKGZ1bmN0aW9uKGZpbGUpIHtcbiAgICAgICAgcmV0dXJuIHBsdWdpbnMuZnMuc3RhdFN5bmMocGx1Z2lucy5wYXRoLmpvaW4ocGF0aEFyZywgZmlsZSkpLmlzRGlyZWN0b3J5KCk7XG4gICAgfSk7XG4gICAgZG9uZS5yZXNvbHZlKGZvbGRlckFycmF5KTtcbiAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xufTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -46,6 +46,30 @@ describe("smartfile".yellow,function(){
}); });
}); });
describe(".get",function(){
describe(".filetype()",function(){
it("should get the file type from a string",function(){
smartfile.get.filetype("./somefolder/data.json").should.equal("json");
});
});
describe(".foldersSync()",function(){
it("should get the file type from a string",function(){
smartfile.get.foldersSync("./test/").should.containDeep([ "testfolder"]);
smartfile.get.foldersSync("./test/").should.not.containDeep([ "notExistentFolder"]);
});
});
describe(".folders()",function(){
it("should get the file type from a string",function(done){
smartfile.get.folders("./test/")
.then(function(folderArrayArg){
folderArrayArg.should.containDeep([ "testfolder"]);
folderArrayArg.should.not.containDeep([ "notExistentFolder"]);
done();
});
});
});
});
describe(".local".yellow,function(){ describe(".local".yellow,function(){
describe("toGulpStreamSync() and toGulpDestSync",function(){ describe("toGulpStreamSync() and toGulpDestSync",function(){

View File

@ -6,3 +6,18 @@ export let filetype = function(pathArg:string):string {
let fileType = extName.replace(/\.([a-z]*)/,"$1"); //remove . form fileType let fileType = extName.replace(/\.([a-z]*)/,"$1"); //remove . form fileType
return fileType; return fileType;
}; };
export let foldersSync = function(pathArg){
return plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
};
export let folders = function(pathArg:string){
let done = plugins.q.defer();
let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
done.resolve(folderArray);
return done.promise;
};