fs-iterators
v1.0.0
Published
Iterating over file paths in a given set of directories, lambda filters
Downloads
4
Readme
fs-iterators
is a zero dependency node.js library implementing file system iterators over given sets or root paths with functions as filtering conditions.
It features two classes:
Installation
npm install fs-iterators
Usage
const {DirList} = require ('fs-iterators')
const myDir = new DirList ({
root: ['/opt/myProject'],
filter: (str, arr) =>
/src/.test (str) // contains 'src'
&& arr.at (-2) === 'Model', // **/Model/*
// live: true, // avoid caching, scan every time
})
for (const dir of myDir.paths) console.log ({dir})
for (const file of myDir.files ()) console.log ({file})
for (const file of myDir.files ('index.js')) console.log ({file})
for (const file of myDir.files (_ => /js$/.test (_))) console.log ({file})
See also
- fs-iterator seems to solve a pretty similar problem, with some restrictions (e. g. a single root path instead of multiple ones);
- filelist is a much more popular solution, but it implements the complete Array interface instead of only Iterator and uses masks (globs) instead of functional filters.