fs-resolver
v1.0.0
Published
Resolve and load files and directories from multiple filesystem search paths
Downloads
7
Maintainers
Readme
fs-resolver
Resolve and load files and directories from multiple filesystem search paths.
Initially developed to resolve Swig template files for AdminPlus Lite Bootstrap Theme.
Usage
Search paths
var Loader = require('fs-resolver');
var path = require('path');
var loader = new Loader([
process.cwd(),
path.join(process.cwd(), 'test')
]);
Resolve path to file
loader.resolve('assets/a.txt') // -> /full/path/to/test/assets/a.txt
loader.resolve('test/assets/a.txt') // -> /full/path/to/test/assets/a.txt
Resolve path to directory
loader.resolve('assets', undefined, dir = true) // -> /full/path/to/test/assets/
loader.resolve('test/assets', undefined, dir = true) // -> /full/path/to/test/assets/
Load file sync
loader.load('assets/a.txt') -> // contents of /full/path/to/test/assets/a.txt
Load file async
new Promise(function(resolve, reject) {
loader.load( 'assets/a.txt', function(err, data) {
if (err) return reject(err);
resolve(data);
});
})
.then(function(data) {
// data = contents of /full/path/to/test/assets/a.txt
});