1.0.0 • Published 12 months ago

fs-iterators v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

workflow Jest coverage

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.
1.0.0

12 months ago