Skip to content

Commit

Permalink
Add emptyDir method to general helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
saiat3 committed Aug 15, 2019
1 parent f4be8c6 commit b189caa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/helpers/general-helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fs = require('fs');
const path = require('path');

module.exports = {
capitalize: (s) => {
if (typeof s !== 'string') {
Expand All @@ -13,4 +16,15 @@ module.exports = {
return s.charAt(0).toLowerCase() + s.slice(1);
}
},
emptyDir: (dir) => {
fs.readdir(dir, (err, files) => {
if (err) throw err;

for (const file of files) {
fs.unlink(path.join(dir, file), err => {
if (err) throw err;
});
}
});
}
};

0 comments on commit b189caa

Please sign in to comment.