Have ideas to improve npm?Join in the discussion! »

    files-import
    TypeScript icon, indicating that this package has built-in type declarations

    1.4.1 • Public • Published

    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

    Install

    npm i files-import

    DownloadsWeekly Downloads

    1

    Version

    1.4.1

    License

    MIT

    Unpacked Size

    21.8 kB

    Total Files

    12

    Last publish

    Collaborators

    • avatar