kindly
v1.0.0
Published
A thin wrapper for fs to group files by type
Downloads
210
Readme
Kindly
Purpose
Kindly is a thin wrapper around fs.readdir that groups files by type.
Installation
npm install kindly --save
var kindly = require('kindly');
API
.get(directory[, options, callback])
Get files in a directory asynchronously. This function returns a promise but also accepts a callback if you prefer a more traditional style of async.
Promise-based:
kindly.get('dir').then(results => {
}, err => {
});
Callback-based:
kindly.get('dir', (err, results) => {
});
.getSync(directory[, options])
Get files in a directory synchronously.
let results = kindly.getSync('dir');
Results
In all cases described above, results will be an object in this form:
{
files: [],
directories: [],
symlinks: [],
other: []
}
All file and directory names are prefaced with the path you pass to kindly. Thus, if you use something like
var kindly = require('kindly');
var path = require('path');
kindly.get(path.resolve('lib')).then((results) => {
});
all of results will be fully qualified paths.
Options
noFollow
By default, kindly
uses fs.stat
and fs.statSync
which, in the case of symlinks, give the filetype of the real file to which the symlink points (i.e. by default, you will never get symlinks back in your results). If you would prefer to get symlinks back as symlinks instead of files, you can pass { noFollow: true }
as the second argument, which will force this library to use fs.lstat
and fs.lstatSync
instead.
kindly.get('dir', { noFollow: true }).then(results => {
});
kindly.get('dir', { noFollow: true }, results => {
});
let results = kindly.get('dir', { noFollow: true });
Contributing
Please see the contribution guidelines.