Skip to content

Commit

Permalink
refactor to have a consistent function signature internally
Browse files Browse the repository at this point in the history
  • Loading branch information
manidlou committed Dec 3, 2017
1 parent a196859 commit f340803
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions klaw-sync.js
Expand Up @@ -3,28 +3,29 @@
const fs = require('graceful-fs')
const path = require('path')

function klawSync (dir, opts, ls) {
if (!ls) {
opts = opts || {}
ls = []
dir = path.resolve(dir)
}
function klawSync (dir, opts) {
dir = path.resolve(dir)
opts = opts || {}
return _klawSync(dir, opts, [])
}

function _klawSync (dir, opts, ls) {
const paths = fs.readdirSync(dir).map(p => dir + path.sep + p)
for (var i = 0; i < paths.length; i += 1) {
const pi = paths[i]
const st = fs.lstatSync(pi)
const st = fs.statSync(pi)
const item = {path: pi, stats: st}
if (st.isDirectory()) {
if (opts.filter) {
if (opts.filter(item) && !opts.nodir) {
ls.push(item)
ls = klawSync(pi, opts, ls)
ls = _klawSync(pi, opts, ls)
} else {
if (!opts.noRecurseOnFailedFilter) ls = klawSync(pi, opts, ls)
if (!opts.noRecurseOnFailedFilter) ls = _klawSync(pi, opts, ls)
}
} else {
if (!opts.nodir) ls.push(item)
ls = klawSync(pi, opts, ls)
ls = _klawSync(pi, opts, ls)
}
} else {
if (opts.filter) {
Expand Down

0 comments on commit f340803

Please sign in to comment.