export type Parser = typeof import("./../parser"); export type BootstrapCallbackContext = { util: Util; defer: typeof deferConfig; raw: typeof RawConfig.raw; }; /** * A function for deferred configuration * * Executable config files can now be initialized by a callback which receives useful * context in order to avoid the need for require() or import() calls to config while * it is still initializing. */ export type bootstrapCallback = (context: BootstrapCallbackContext) => any; /** * A source in the configSources list */ export type ConfigSource = { name: string; /** * - parsed representation */ parsed: any; /** * - unparsed representation of the data */ original?: string | undefined; }; /** * The data used for a Load operation, mostly derived from environment variables */ export type LoadOptions = { /** * - config directory location, absolute or relative to cwd() */ configDir?: string | undefined; /** * - NODE_ENV value or commo-separated list */ nodeEnv?: string[] | undefined; /** * - hostName for host-specific loads */ hostName?: string | undefined; /** * - per-process config ID */ appInstance?: string | undefined; /** * - don't track sources */ skipConfigSources?: boolean | undefined; /** * - allow gitcrypt files */ gitCrypt?: boolean | undefined; /** * - alternative parser implementation */ parser?: Parser | undefined; }; /** * Callback for converting loaded data. */ export type DataConvert = (input: any) => any; /** * Util functions that do not require the singleton in order to run. */ export class Util { /** *
Make a configuration property hidden so it doesn't appear when enumerating * elements of the object.
* ** The property still exists and can be read from and written to, but it won't * show up in for ... in loops, Object.keys(), or JSON.stringify() type methods. *
* ** If the property already exists, it will be made hidden. Otherwise it will * be created as a hidden property with the specified value. *
* ** This method was built for hiding configuration values, but it can be applied * to any javascript object. *
* *Example:
*
* const Util = require('config/lib/util.js');
* ...
*
* // Hide the Amazon S3 credentials
* Util.makeHidden(CONFIG.amazonS3, 'access_id');
* Util.makeHidden(CONFIG.amazonS3, 'secret_key');
*
*
* @method makeHidden
* @param {object} object - The object to make a hidden property into.
* @param {string} property - The name of the property to make hidden.
* @param {*=} value - (optional) Set the property value to this (otherwise leave alone)
* @return {object} - The original object is returned - for chaining.
*/
static makeHidden(object: object, property: string, value?: any | undefined): object;
/**
* Make a javascript object immutable (assuring it cannot be changed from the current value)
*
* All attributes of that object are made immutable, including properties of contained
* objects, recursively.
*
* This operation cannot be undone.
*
* Example:
*
* const config = require('config');
* const myObject = {hello:'world'};
* Util.makeImmutable(myObject);
*
*
* @method makeImmutable
* @param object {Object} - The object to freeze
* @return object {Object} - The original object is returned - for chaining.
*/
static makeImmutable(object: any): any;
/**
* Looks into an options object for a specific attribute
*
* * This method looks into the options object, and if an attribute is defined, returns it, * and if not, returns the default value *
* * @template T * @method getOption * @param {Object | undefined} options the options object * @param {string} optionName the attribute name to look for * @param {T} defaultValue the default in case the options object is empty, or the attribute does not exist. * @return {T} options[optionName] if defined, defaultValue if not. */ static getOption* This method builds a map of filename to the configuration object defined * by the file. The search order is: *
* *
* default.EXT
* (deployment).EXT
* (hostname).EXT
* (hostname)-(deployment).EXT
* local.EXT
* local-(deployment).EXT
*
*
* * EXT can be yml, yaml, coffee, iced, json, jsonc, cson or js signifying the file type. * yaml (and yml) is in YAML format, coffee is a coffee-script, iced is iced-coffee-script, * json is in JSON format, jsonc is in JSONC format, cson is in CSON format, properties is * in .properties format (http://en.wikipedia.org/wiki/.properties), and js is a javascript * executable file that is require()'d with module.exports being the config object. *
* ** hostname is the $HOST environment variable (or --HOST command line parameter) * if set, otherwise the $HOSTNAME environment variable (or --HOSTNAME command * line parameter) if set, otherwise the hostname found from * require('os').hostname(). *
* ** Once a hostname is found, everything from the first period ('.') onwards * is removed. For example, abc.example.com becomes abc *
* ** (deployment) is the deployment type, found in the $NODE_ENV environment * variable (which can be overridden by using $NODE_CONFIG_ENV * environment variable). Defaults to 'development'. *
* ** If the $NODE_APP_INSTANCE environment variable (or --NODE_APP_INSTANCE * command line parameter) is set, then files with this appendage will be loaded. * See the Multiple Application Instances section of the main documentation page * for more information. *
* * @method loadFileConfigs * @param {LoadOptions | Load} opts parsing options or Load to update * @return {Load} loadConfig */ static loadFileConfigs(opts: LoadOptions | Load): Load; /** * Return a list of fullFilenames who exists in allowedFiles * Ordered according to allowedFiles argument specifications * * @method locateMatchingFiles * @param {string} configDirs the config dir, or multiple dirs separated by a column (:) * @param {Object} allowedFiles an object. keys and supported filenames * and values are the position in the resolution order * @returns {string[]} fullFilenames - path + filename */ static locateMatchingFiles(configDirs: string, allowedFiles: any): string[]; /** * * @param {object} config */ static resolveDeferredConfigs(config: object): void; /** * Used to resolve configs that have async functions. * * NOTE: Do not use `config.get` before executing this method, it will freeze the config object * * This replaces ./async.js, which is deprecated. * * @param config * @returns {PromiseInitialize a parameter from the command line or process environment
* ** This method looks for the parameter from the command line in the format * --PARAMETER=VALUE, then from the process environment, then from the * default specified as an argument. *
* * @template T * @method initParam * @param {string} paramName Name of the parameter * @param {T} [defaultValue] Default value of the parameter * @return {T} The found value, or default value */ initParamGet Command Line Arguments
* ** This method allows you to retrieve the value of the specified command line argument. *
* ** The argument is case sensitive, and must be of the form '--ARG_NAME=value' *
* * @method getCmdLineArg * @param {string} searchFor The argument name to search for * @return {false|string} false if the argument was not found, the argument value if found */ getCmdLineArg(searchFor: string): false | string; /** *Get a Config Environment Variable Value
* ** This method returns the value of the specified config environment variable, * including any defaults or overrides. *
* * @method getEnv * @param {string} varName The environment variable name * @return {string} The value of the environment variable */ getEnv(varName: string): string; /** * Set a tracing variable of what was accessed from process.env * * @see fromEnvironment * @param {string} key * @param {*} value */ setEnv(key: string, value: any): void; /** * Add a set of configurations and record the source * * @param {string=} name an entry will be added to sources under this name (if given) * @param {object=} values values to merge in * @param {string=} original Optional unparsed version of the data * @return {Load} this */ addConfig(name?: string | undefined, values?: object | undefined, original?: string | undefined): Load; /** * scan and load config files in the same manner that config.js does * * @param {{name: string, config: any}[]=} additional additional values to populate (usually from NODE_CONFIG) */ scan(additional?: { name: string; config: any; }[] | undefined): void; /** * Load a file and add it to the configuration * * @param {string} fullFilename an absolute file path * @param {DataConvert=} convert * @returns {null} */ loadFile(fullFilename: string, convert?: DataConvert | undefined): null; /** * load custom-environment-variables * * @param extNames {string[]=} extensions * @returns {{}} */ loadCustomEnvVars(extNames?: string[] | undefined): {}; /** * Return the report of where the sources for this load operation came from * @returns {ConfigSource[]} */ getSources(): ConfigSource[]; /** ** Set default configurations for a node.js module. *
* ** This allows module developers to attach their configurations onto the * default configuration object so they can be configured by the consumers * of the module. *
* *Using the function within your module:
*
* load.setModuleDefaults("MyModule", {
* templateName: "t-50",
* colorScheme: "green"
* });
*
* // Template name may be overridden by application config files
* console.log("Template: " + CONFIG.MyModule.templateName);
*
*
* * The above example results in a "MyModule" element of the configuration * object, containing an object with the specified default values. *
* * @method setModuleDefaults * @param moduleName {string} - Name of your module. * @param defaultProperties {Object} - The default module configuration. * @return {Object} - The module level configuration object. */ setModuleDefaults(moduleName: string, defaultProperties: any): any; /** * Parse and return the specified string with the specified format. * * The format determines the parser to use. * * json = File is parsed using JSON.parse() * yaml (or yml) = Parsed with a YAML parser * toml = Parsed with a TOML parser * cson = Parsed with a CSON parser * hjson = Parsed with a HJSON parser * json5 = Parsed with a JSON5 parser * properties = Parsed with the 'properties' node package * xml = Parsed with a XML parser * * If the file doesn't exist, a null will be returned. If the file can't be * parsed, an exception will be thrown. * * This method performs synchronous file operations, and should not be called * after synchronous module loading. * * @protected * @method parseString * @param {string} content The full content * @param {string} format The format to be parsed * @return {object} configObject The configuration object parsed from the string */ protected parseString(content: string, format: string): object; /** * Create a new object patterned after substitutionMap, where: * 1. Terminal string values in substitutionMap are used as keys * 2. To look up values in a key-value store, variables * 3. And parent keys are created as necessary to retain the structure of substitutionMap. * * @protected * @method substituteDeep * @param {object} substitutionMap {Object} - an object whose terminal (non-subobject) values are strings * @param {RecordInitialize a parameter from the command line or process environment
* ** This method looks for the parameter from the command line in the format * --PARAMETER=VALUE, then from the process environment, then from the * default specified as an argument. *
* * @template T * @method initParam * @param {string} paramName Name of the parameter * @param {T} [defaultValue] Default value of the parameter * @return {T} The found value, or default value */ initParamGet Command Line Arguments
* ** This method allows you to retrieve the value of the specified command line argument. *
* ** The argument is case sensitive, and must be of the form '--ARG_NAME=value' *
* * @method getCmdLineArg * @param {string} searchFor The argument name to search for * @return {false|string} false if the argument was not found, the argument value if found */ getCmdLineArg(searchFor: string): false | string; /** *Get a Config Environment Variable Value
* ** This method returns the value of the specified config environment variable, * including any defaults or overrides. *
* * @method getEnv * @param {string} varName The environment variable name * @return {string} The value of the environment variable */ getEnv(varName: string): string; /** * Set a tracing variable of what was accessed from process.env * * @see fromEnvironment * @param {string} key * @param {*} value */ setEnv(key: string, value: any): void; } export {};