hmpo-config
v4.0.2
Published
Config loader
Readme
hmpo-config
Configuration loading and caching for an application.
In-depth API Documentation can be found in API_DOCS.md
You can re-generate the documentation after making changes by running:
npm run documentationFeatures and benefits of hmpo-config
- Provides config loading from a range of common file formats:
.json.json5.yaml.yml
- Provides config loading from a standard JavaScript object.
- Provides safe modification of an application config using a deep-merging strategy to nest, preserve, or override values safely.
- Enables easy access to the application's
package.jsonand default config values. - Allows dynamic configuration by running a JavaScript config script in a sandboxed context.
[!CAUTION] Use caution when passing untrusted strings to
addScript(), as executing arbitrary code can be a security risk.
Installation
Add hmpo-config to your project via npm or yarn
npm install hmpo-configyarn add hmpo-configUsage
You can add hmpo-config anywhere you see fit, using:
const myConfig = require('hmpo-config');See some examples in:
- hmpo-form-wizard
- A simple example app using
hmpo-config.
- A simple example app using
- hmpo-app
- A more complex implementation, showing a custom config built around
hmpo-config.
- A more complex implementation, showing a custom config built around
API Documentation
Full documentation for hmpo-config can be found at API Docs
A few examples as follows:
// Add hmpo-config to your project, such as in your app.js or index.js
const config = require('hmpo-config');
// Load config from JSON into the app's config object.
config.addFile('filename.json');
// Load config from JSON5 into the app's config object.
config.addFile('filename.json5');
// Load config from YAML into the app's config object.
config.addFile('filename.yaml');
// Add a config string to the app's config object.
config.addString('{ config: "value" }');
// Add a JavaScript object to the app's config object.
config.addConfig({ config: 'value' });
// Run a JavaScript config script in a sandboxed context.
config.addScript('config = "value";');
// Read the current state of the app's config.
let result = config.toJSON();