This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

confenv

0.1.5 • Public • Published

confenv

Build Status npm npm

Installation

$ npm i [-g] [--save] confenv[@tag]

Before you can start

const confenv = require('confenv');

The confenv module itself already returns a ready to use instance of the ConfEnv constructor so it's not necessary to create a new one. If you want to create a new instance anyway just go ahead and use the confenv.$new() function like below:

const confenv = require('confenv').$new([options]);

Options

There are several ways to define you own (runtime) options for the confenv module. If no custom options are defined the module will always fallback to the default values defined by confenv.DEFAULT_RC. Otherwise it will try to parse an existing root configuration file named .confrc that will override the default values. At least the options passed in to the constructor will be used to again override the used values.

DEFAULT_RC
{
  "variable": "NODE_ENV",
  "directory": "config/",
  "tokens": {
    "default": "*.conf.{js,json}"
  }
}

Runtime

confenv internally generates reasonable reusable values along a configuration that's returned by the confenv.get() function. Those values are prefixed with a $ sign and can be directly accessed via the returned object. Let's say we got an existing configuration object instance named config so the following fields would be accessible:

/**
@returns {string} The path value for the used configuration file in the current environment
*/
config.$path;
 
/**
@returns {string|RegExp} The term value used to receive the desired configuration file 
*/
config.$term;
Note

These fields are not going to be displayed by a JSON.stringify() call since they're create by the Object.defineProperty() function using the default descriptor values apart from writable that's set to true.

For more information please have a look at the developer API.

API

Static functions
/**
 * Reads and parses a potentially existing configuration file for the {ConfEnv} module. If nothing is defined
 * the function will return the default RC options defined by {ConfEnv.DEFAULT_RC} 
 * @returns The configuration JSON data as object instance
 */
confenv.$rc();
Prototype functions
/**
 * Exposes all configuration files the {glob} defined for a given token can find. If no token is defined the function
 * will fallback to the pattern defined for the default token
 * @param {string} [token] - The token holding the {glob} pattern to use
 * @returns {array} An array or object of the found entries matching the characteristic
 */
confenv.expose([token]);
 
/**
 * Returns the env value for the defined environment variable key
 * @param {string} [variable] - The environment variable key to use
 * @returns {string} The value for the given key
 */
confenv.env([variable]);
 
/**
 * Receives a configuration {object} holding the desired properties by its name. This function is using a simple regular
 * match expression to search for the desired file
 * @param {string|RegExp} term - The term to receive the configuration files for
 * @returns {object} The desired configuration as object instance
 */
confenv.get(term);

Readme

Keywords

Package Sidebar

Install

npm i confenv

Weekly Downloads

6

Version

0.1.5

License

MIT

Last publish

Collaborators

  • janunld