file-locator
v1.0.0
Published
Load data from files
Downloads
7
Maintainers
Readme
File-locator
- load file data
- load env file data
- import key to include files into main
- parse reference key using 'ref-parser' module
- add custom extension loader
- 2 defaults extension loaders: js, json
## Install
npm i --save file-locator
## Usage
const FileLocator = require('file-loader');
const fileLocator = FileLocator();
fileLocator.load(__dirname + '/config.json')
.then((data)=>{
})
.catch((err)=>{
});
Options
const FileLocator = require('file-loader');
// Default options
const fileLocator = FileLocator({
env: undefined,
data: {},
importsKey: 'imports',
refParserOptions: {}, // See ref-parser module documentation
});
// Override option for this load
fileLocator.load(__dirname + '/config.json', {
env: 'test',
data: {
env: process.env
}
})
.then((data)=>{
})
.catch((err)=>{
});
Add custom extension loader
const FileLocator = require('file-loader');
const fileLocator = FileLocator();
// Add extension loader
fileLocator.addExtensionLoader('yml', function(filepath, callback){
// ...
callback(null, data);
})
fileLocator.load(__dirname + '/config.yml')
.then((data)=>{
})
.catch((err)=>{
});
API
load(filepath: String, opts?: Object, noParsing?: Boolean): Promise<Object>
loadImports(data: Object, opts?:Object): Promise<Object>
addExtensionLoader(extension: ExtensionLoader|String, loaderCallback?: Function)
getExtensionLoader(extension: String): ExtensionLoader
Static
ExtensionLoader
const Loader = require('file-loader');
const loader = Loader();
const extLoader = new loader.ExtensionLoader('yml', function(filepath, callback){
});
loader.addExtensionLoader(extLoader);