Skip to content

Commit

Permalink
refactor: es6 syntax (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Mar 4, 2020
1 parent 336747f commit a71202e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/fs.js
Expand Up @@ -139,21 +139,21 @@ function trueFn() {
function ignoreHiddenFiles(ignore) {
if (!ignore) return trueFn;

return item => item.name[0] !== '.';
return ({ name }) => !name.startsWith('.');
}

function ignoreFilesRegex(regex) {
if (!regex) return trueFn;

return item => !regex.test(item.name);
return ({ name }) => !regex.test(name);
}

function ignoreExcludeFiles(arr, parent) {
if (!arr || !arr.length) return trueFn;

const set = new Set(arr);

return item => !set.has(join(parent, item.name));
return ({ name }) => !set.has(join(parent, name));
}

function reduceFiles(result, item) {
Expand All @@ -167,14 +167,14 @@ function reduceFiles(result, item) {

async function _readAndFilterDir(path, options) {
const { ignoreHidden = true, ignorePattern } = options;
return (await fsPromises.readdir(path, Object.assign(options, { withFileTypes: true })))
return (await fsPromises.readdir(path, { ...options, withFileTypes: true }))
.filter(ignoreHiddenFiles(ignoreHidden))
.filter(ignoreFilesRegex(ignorePattern));
}

function _readAndFilterDirSync(path, options) {
const { ignoreHidden = true, ignorePattern } = options;
return fs.readdirSync(path, Object.assign(options, { withFileTypes: true }))
return fs.readdirSync(path, { ...options, withFileTypes: true })
.filter(ignoreHiddenFiles(ignoreHidden))
.filter(ignoreFilesRegex(ignorePattern));
}
Expand Down

0 comments on commit a71202e

Please sign in to comment.