Giter VIP home page Giter VIP logo

files-import's Introduction

Build Status Maintainability codecov GitHub issues GitHub

LICENSE

MIT

GOAL

Traverse all files in a folder

INSTALL

npm i files-import

HOW TO USE

#   Afolder
#     Afile
#     Bfile
#   Bfolder
#     Cfolder
#        Efile
#   Cfile
#   Dfile

const path = require('path');
const Factory = require('files-import');
const factory = new Factory('myFolder');
factory.map(file => {
    console.log(
        file.folders.join('/') + '|' + path.basename(file.path)
    )
});

# |Cfile
# |Dfile
# Afolder|Afile
# Afolder|Bfile
# Bfolder/Cfolder|Efile


factory
.exclude('Cfile')
.exclude('Dfile')
.include('A', Factory.PATH_TYPE.FOLDER)
.exclude('Afile', Factory.PATH_TYPE.FILE)
.map(file => {
    console.log( path.basename(file.path) );
});


# Bfile

INCLUDE

// fac.include = 'folder';
// fac.include = /folder/;
// fac.include('folder');
// fac.include(/folder/);
factory.include(function(f) {
    return f.path.indexOf('folder') !== -1;
}).map(file => {
    console.log(
        file.folders.join('/') + '|' + path.basename(file.path)
    )
});

# Afolder|Afile
# Afolder|Bfile
# Bfolder/Cfolder|Efile

EXCLUDE

// fac.exclude = 'folder';
// fac.exclude = /folder/;
// fac.exclude('folder');
// fac.exclude(/folder/);
factory.exclude(function(f) {
    return f.path.indexOf('folder') !== -1;
}).map(file => {
    console.log(
        file.folders.join('/') + '|' + path.basename(file.path)
    )
});

# |Cfile
# |Dfile

SUGGESTION

/** wrong */
factory.map(function() {
    if(file.folders[0] === 'test') return;
    // other code
});

/** ok */
factory.exclude(f => {
    return f.folders[0] === 'test';
}).map(function() {
    // other code
});

/** traverse files in folder exclude folder inside */
factory.exclude(f => {
    return f.folders[0];
}).map(function() {
    // other code
});

# |Cfile
# |Dfile

files-import's People

Contributors

uccu avatar

Watchers

James Cloos avatar  avatar  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.