Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eldoy/conficurse
Recursively converts YAML, JSON and JS config files into Javascript objects
https://github.com/eldoy/conficurse
Last synced: 6 days ago
JSON representation
Recursively converts YAML, JSON and JS config files into Javascript objects
- Host: GitHub
- URL: https://github.com/eldoy/conficurse
- Owner: eldoy
- License: mit
- Created: 2018-08-21T02:58:09.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-22T11:47:16.000Z (about 2 months ago)
- Last Synced: 2024-10-13T14:15:33.517Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 468 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Conficurse Config Loader
The conficurse library will load your config YAML, JSON and JS files as a Javascript object. This is great for huge configuration file hierarchies or applications with deep structures.
Awesome features:
- Env support, merges files automatically based on your current environment
- Supports callback functions for modifying file content before and after load
- Can lazy load modules using Javascript proxy objects
- You can load your files async in parallel using promises### Install
```npm i conficurse```### Usage
See the ```test/config``` directory for an example directory structure.
```js
var loader = require('conficurse')// Path is the directory relative to where you run the command
var config = loader.load('config')// Lazy load, functions won't be required until you use them
var pages = loader.load('app/pages', { lazy: true })// Load files async using promises, can be used with Promise.all
var pages = await loader.load('app/pages', { async: true })// We also have this convenience function
var pages = await loader.loadAsync('app/pages')// Change content on load
var config = loader.load('config', {
onload: function({
mode,
dir,
file,
base,
ext,
trail,
content
}) {
if (ext == 'yml') {
return YAML.load(content)
}
return content
}
})// Change content before require
var app = loader.load('app', {
onrequire: function({
mode,
dir,
file,
base,
ext,
trail,
content
}) {
return content.replace('@', process.cwd())
}
})
```### Caveats
These are some things to be aware of:
- You cannot use env with `.js` files
- Only `.js` files can be lazy loaded
- Only `.js` files supports `onrequire` callbacksMIT licensed. Enjoy!