GithubHelp home page GithubHelp logo

isabella232 / fs-readdir-rec-gen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from orange-opensource/fs-readdir-rec-gen

0.0 0.0 0.0 12 KB

Get an ES6 generator for files in a directory and subdirectories

License: MIT License

JavaScript 100.00%

fs-readdir-rec-gen's Introduction

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.

fs-readdir-rec-gen's People

Contributors

nicolas-moteau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.