Comparing version 3.0.1 to 3.0.2
55
index.js
@@ -25,9 +25,18 @@ "use strict"; | ||
const rrdir = module.exports = async (dir, opts) => { | ||
opts = Object.assign({}, defaults, opts); | ||
function isExcluded(dir, opts) { | ||
if (!dir || !opts || !opts.exclude || !opts.exclude.length) return false; | ||
return opts.exclude.length && !!multimatch(dir, opts.exclude, opts.minimatch).length; | ||
} | ||
function handleOpts(dir, opts) { | ||
if (!dir || !typeof dir === "string") { | ||
throw new Error(`Expected a string, got '${dir}'`); | ||
} | ||
return Object.assign({}, defaults, opts); | ||
} | ||
const rrdir = module.exports = async (dir, opts) => { | ||
if (isExcluded(dir, opts)) return []; | ||
opts = handleOpts(dir, opts); | ||
let results = []; | ||
@@ -37,6 +46,3 @@ let entries = []; | ||
try { | ||
const exclude = (opts.exclude.length) && !!(multimatch(dir, opts.exclude, opts.minimatch).length); | ||
if (!exclude) { | ||
entries = await readdir(dir, {encoding: opts.encoding, withFileTypes: true}); | ||
} | ||
entries = await readdir(dir, {encoding: opts.encoding, withFileTypes: true}); | ||
} catch (err) { | ||
@@ -56,7 +62,4 @@ if (opts.strict) { | ||
const path = join(dir, entry.name); | ||
if (isExcluded(path, opts)) continue; | ||
if (opts.exclude.length && !!(multimatch(path, opts.exclude, opts.minimatch).length)) { | ||
continue; | ||
} | ||
let stats; | ||
@@ -94,3 +97,4 @@ if (!opts.stats) { | ||
module.exports.sync = (dir, opts) => { | ||
opts = Object.assign({}, defaults, opts); | ||
if (isExcluded(dir, opts)) return []; | ||
opts = handleOpts(dir, opts); | ||
@@ -101,6 +105,3 @@ let results = []; | ||
try { | ||
const exclude = (opts.exclude.length) && !!(multimatch(dir, opts.exclude, opts.minimatch).length); | ||
if (!exclude) { | ||
entries = fs.readdirSync(dir, {encoding: opts.encoding, withFileTypes: true}); | ||
} | ||
entries = fs.readdirSync(dir, {encoding: opts.encoding, withFileTypes: true}); | ||
} catch (err) { | ||
@@ -120,7 +121,4 @@ if (opts.strict) { | ||
const path = join(dir, entry.name); | ||
if (isExcluded(path, opts)) continue; | ||
if (opts.exclude.length && !!(multimatch(path, opts.exclude, opts.minimatch).length)) { | ||
continue; | ||
} | ||
let stats; | ||
@@ -158,15 +156,9 @@ if (!opts.stats) { | ||
module.exports.stream = async function* (dir, opts) { | ||
opts = Object.assign({}, defaults, opts); | ||
if (isExcluded(dir, opts)) return; | ||
opts = handleOpts(dir, opts); | ||
if (!dir || !typeof dir === "string") { | ||
throw new Error(`Expected a string, got '${dir}'`); | ||
} | ||
let entries = []; | ||
try { | ||
const exclude = (opts.exclude.length) && !!(multimatch(dir, opts.exclude, opts.minimatch).length); | ||
if (!exclude) { | ||
entries = await readdir(dir, {encoding: opts.encoding, withFileTypes: true}); | ||
} | ||
entries = await readdir(dir, {encoding: opts.encoding, withFileTypes: true}); | ||
} catch (err) { | ||
@@ -186,7 +178,4 @@ if (opts.strict) { | ||
const path = join(dir, entry.name); | ||
if (isExcluded(path, opts)) continue; | ||
if (opts.exclude.length && !!(multimatch(path, opts.exclude, opts.minimatch).length)) { | ||
continue; | ||
} | ||
let stats; | ||
@@ -215,3 +204,3 @@ if (!opts.stats) { | ||
if (directory) { | ||
yield * await rrdir(path, opts); | ||
yield * await rrdir.stream(path, opts); | ||
} | ||
@@ -218,0 +207,0 @@ } |
{ | ||
"name": "rrdir", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Recursive directory crawler with a delightful API", | ||
@@ -5,0 +5,0 @@ "author": "silverwind <me@silverwind.io>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8781
169