1.1.0 • Published 7 years ago

vi-directory-loader v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

vi-directory-loader

NPM version build status Test coverage

A tool to find all files under a certain directory. The scan result files are organized in a tree just as they are in file system.

usage

const load = require('vi-directory-loader');

const directory = load('./foo');

/*
directory => {
    'name': 'foo',
    'type': 'DIRECTORY',
    'files': Map{
        'a': { 'name': 'a', ...},
        'b': { 'name': 'b', ...},
        ...
    }
}
*/

.filter() and .each()

Apply handler for every file and directory in the target.

const dectory1 = directory.filter(file => file.type !== file.File.TYPE_DIRECTORY && file.name != ''a');
directory.each(file => console.log(file.name));

.toTree()

Map all files into a tree, file name as the key and path (by default) as the value

const tree = directory.toTree();

/*
directory => {
    'a': 'xxx',
    'b': 'xxx',
    'c': Map{
        'd': 'xxx',
        'e': 'xxx',
        ...
    }
}
*/