Skip to content

Commit

Permalink
Merge pull request #215 from qgustavor/include-dir-filter
Browse files Browse the repository at this point in the history
Include directories in .find and .filter methods
  • Loading branch information
qgustavor authored Sep 10, 2024
2 parents 069aeaa + 489df51 commit ab149d1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,11 @@ class File extends EventEmitter {

return this.children.reduce((result, entry) => {
if (result) return result
if (entry.children) {
return deep ? entry.find(query, deep) : null
if (query(entry)) return entry
if (entry.children && deep) {
return entry.find(query, deep)
}
return query(entry) ? entry : null
return null
}, null)
}

Expand All @@ -462,11 +463,11 @@ class File extends EventEmitter {
}

return this.children.reduce((results, entry) => {
if (entry.children) {
if (deep) return results.concat(entry.filter(query, deep))
return results
if (query(entry)) results.push(entry)
if (entry.children && deep) {
return results.concat(entry.filter(query, deep))
}
return query(entry) ? results.concat(entry) : results
return results
}, [])
}

Expand Down

0 comments on commit ab149d1

Please sign in to comment.