1.4.1 • Published 4 years ago

files-import v1.4.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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
1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago