From b189caab9143c043cff77f56cea5bc4ed6586112 Mon Sep 17 00:00:00 2001 From: Saiat Kalbiev Date: Thu, 15 Aug 2019 14:46:48 +0400 Subject: [PATCH] Add emptyDir method to general helper class --- src/helpers/general-helper.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/helpers/general-helper.js b/src/helpers/general-helper.js index fa3cabf..39d8831 100644 --- a/src/helpers/general-helper.js +++ b/src/helpers/general-helper.js @@ -1,3 +1,6 @@ +const fs = require('fs'); +const path = require('path'); + module.exports = { capitalize: (s) => { if (typeof s !== 'string') { @@ -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; + }); + } + }); + } };