Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fs-readdir-rec-gen

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-readdir-rec-gen

Get an ES6 generator for files in a directory and subdirectories

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

A recursive read dir, generator based implementation

Build Status Coverage Status Installs! npm License

A NodeJS module to get a generator for files in a directory and subdirectories, with a file filter capability.

Install

npm install --save fs-readdir-rec-gen

API

fsReadDirRecGen(dir [, options] [, filter] [, recursive=true])
  • dir {String} - the directory where to look for files.
  • options {String|Object} - optional, options passed NodeJs File System API (see NodeJS' fs API).
  • filter {Function} - optional, a function to filter on file names. Defaults to no filter.
  • recursive {Boolean} - optional, whether to search in sub directories. Defaults to true.

If dir does not exists, an exception is immediately thrown by NodeJS' fs API.

Examples

With a simple .js file filter:

var fsReadDirRecGen = require('fs-readdir-rec-gen')

function dotJsFilesFilter(fileName) {
    return fileName.endsWith('.js');
};
for (let file of fsReadDirRecGen('./test/testData', dotJsFilesFilter)) {
    console.log('Relative path to file : ' + file);
}
Relative path to file : test/testData/aa/class3.js
Relative path to file : test/testData/abstractsuperclass.js
Relative path to file : test/testData/class.js
Relative path to file : test/testData/class2.js

With a RegExp file filter:

var fsReadDirRecGen = require('fs-readdir-rec-gen')

function classdotJsFileFilter() {
    var format = RegExp(/.*class.*\.js/i);
    return function (filename) {
        return format.test(filename);
    }
};
for (let file of fsReadDirRecGen('./test/testData', classdotJsFileFilter())){
    console.log('Relative path to file : ' + file);
}

Without file filter:

var fsReadDirRecGen = require('fs-readdir-rec-gen')

for (let file of fsReadDirRecGen('./test/testData')){
    console.log('Relative path to file : ' + file);
}

More examples in examples.js and test dir.

Keywords

FAQs

Package last updated on 06 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc