config 4.4.0 → 5.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,368 +1,6 @@
1
1
  declare namespace _exports {
2
- export { Util, Load, LoadOptions, Parser, Config };
2
+ export { Config };
3
3
  }
4
4
  declare const _exports: Config;
5
5
  export = _exports;
6
- type Util = import("./util").Util;
7
- type Load = import("./util").Load;
8
- type LoadOptions = import("./util").LoadOptions;
9
- type Parser = typeof import("./../parser");
10
- /**
11
- * The exported configuration instance type.
12
- * This is here because the Config class is not a named export and this is how we get
13
- * the exported configuration instance type.
14
- */
15
- type Config = ConfigClass;
16
- /**
17
- * <p>Application Configurations</p>
18
- * @class
19
- */
20
- declare class ConfigClass {
21
- /**
22
- * <p>Get the configuration object.</p>
23
- *
24
- * <p>
25
- * The configuration object is a shared singleton object within the application,
26
- * attained by calling require('config').
27
- * </p>
28
- *
29
- * <p>
30
- * Usually you'll specify a CONFIG variable at the top of your .js file
31
- * for file/module scope. If you want the root of the object, you can do this:
32
- * </p>
33
- * <pre>
34
- * const CONFIG = require('config');
35
- * </pre>
36
- *
37
- * <p>
38
- * Sometimes you only care about a specific sub-object within the CONFIG
39
- * object. In that case you could do this at the top of your file:
40
- * </p>
41
- * <pre>
42
- * const CONFIG = require('config').customer;
43
- * or
44
- * const CUSTOMER_CONFIG = require('config').customer;
45
- * </pre>
46
- *
47
- * <script type="text/javascript">
48
- * document.getElementById("showProtected").style.display = "block";
49
- * </script>
50
- *
51
- * @method constructor
52
- */
53
- constructor(load: any);
54
- /**
55
- * Non-enumerable field for util functions
56
- *
57
- * @type {ConfigUtils}
58
- */
59
- util: ConfigUtils;
60
- /**
61
- * <p>Get a configuration value</p>
62
- *
63
- * <p>
64
- * This will return the specified property value, throwing an exception if the
65
- * configuration isn't defined. It is used to assure configurations are defined
66
- * before being used, and to prevent typos.
67
- * </p>
68
- *
69
- * @template T
70
- * @param {string} property - The configuration property to get. Can include '.' sub-properties.
71
- * @returns {T} The property value
72
- */
73
- get<T>(property: string): T;
74
- /**
75
- * Test that a configuration parameter exists
76
- *
77
- * <pre>
78
- * const config = require('config');
79
- * if (config.has('customer.dbName')) {
80
- * console.log('Customer database name: ' + config.customer.dbName);
81
- * }
82
- * </pre>
83
- *
84
- * @method has
85
- * @param {string} property - The configuration property to test. Can include '.' sub-properties.
86
- * @return {boolean} - True if the property is defined, false if not defined.
87
- */
88
- has(property: string): boolean;
89
- [LOAD_SYMBOL]: any;
90
- }
91
- /**
92
- * The exported configuration instance type.
93
- * This is here because the Config class is not a named export and this is how we get
94
- * the exported configuration instance type.
95
- * @typedef {ConfigClass} Config
96
- */
97
- /**
98
- * Source of config.util utility functions.
99
- *
100
- * In general, lib/util.js is what you are looking for.
101
- *
102
- * @class ConfigUtils
103
- */
104
- declare class ConfigUtils {
105
- /**
106
- * @param {Config} config
107
- */
108
- constructor(config: Config);
109
- /**
110
- * <p>
111
- * Set default configurations for a node.js module.
112
- * </p>
113
- *
114
- * <p>
115
- * This allows module developers to attach their configurations onto the
116
- * default configuration object so they can be configured by the consumers
117
- * of the module.
118
- * </p>
119
- *
120
- * <p>Using the function within your module:</p>
121
- * <pre>
122
- * const CONFIG = require("config");
123
- * CONFIG.util.setModuleDefaults("MyModule", {
124
- * &nbsp;&nbsp;templateName: "t-50",
125
- * &nbsp;&nbsp;colorScheme: "green"
126
- * });
127
- * <br>
128
- * // Template name may be overridden by application config files
129
- * console.log("Template: " + CONFIG.MyModule.templateName);
130
- * </pre>
131
- *
132
- * <p>
133
- * The above example results in a "MyModule" element of the configuration
134
- * object, containing an object with the specified default values.
135
- * </p>
136
- *
137
- * @method setModuleDefaults
138
- * @param {string} moduleName - Name of your module.
139
- * @param {any} defaultProperties - The default module configuration.
140
- * @return {any} moduleConfig - The module level configuration object.
141
- * @see Load.scan() for loading more robust defaults
142
- */
143
- setModuleDefaults(moduleName: string, defaultProperties: any): any;
144
- /**
145
- * Set default configurations for a node.js module.
146
- *
147
- * This variant is provided to support handling loading of multiple versions
148
- * of a library. This is meant for module developers to create a config snapshot
149
- * for an old version of the code, particularly during a staged upgrade.
150
- * Instead of adding the values to the configuration, it creates a new Config
151
- * instance that contains the provided defaults.
152
- *
153
- * Note: This feature is primarily useful for adding, removing, or renaming
154
- * properties. It will struggle to deal with changing the semantics of
155
- * existing fields if you need to override those fields in your top level
156
- * config/ directory. It is always best when versioning an API to change the
157
- * names of fields when you change the meaning of the field.
158
- *
159
- * <p>Using the function within your module:</p>
160
- * <pre>
161
- * const configModule = require("config");
162
- * const config = configModule.withModuleDefaults("MyModule", {
163
- * &nbsp;&nbsp;templateName: "t-50",
164
- * &nbsp;&nbsp;colorScheme: "green"
165
- * });
166
- * <br>
167
- * // Template name may be overridden by application config files
168
- * console.log("Template: " + config.MyModule.templateName);
169
- * </pre>
170
- *
171
- * <p>
172
- * The above example results in a "MyModule" element of the configuration
173
- * object, containing an object with the specified default values.
174
- * </p>
175
- *
176
- * @method withModuleDefaults
177
- * @param moduleName {string} - Name of your module.
178
- * @param defaultProperties {Object} - The default module configuration.
179
- * @returns {Config}
180
- * @see Load.scan() for loading more robust defaults
181
- */
182
- withModuleDefaults(moduleName: string, defaultProperties: any): Config;
183
- /**
184
- * <p>Make a javascript object property immutable (assuring it cannot be changed
185
- * from the current value).</p>
186
- * <p>
187
- * If the specified property is an object, all attributes of that object are
188
- * made immutable, including properties of contained objects, recursively.
189
- * If a property name isn't supplied, the object and all of its properties
190
- * are made immutable.
191
- * </p>
192
- * <p>
193
- * This operation cannot be undone.
194
- * </p>
195
- *
196
- * <p>Example:</p>
197
- * <pre>
198
- * const config = require('config');
199
- * const myObject = {hello:'world'};
200
- * config.util.makeImmutable(myObject);
201
- * </pre>
202
- *
203
- * @method makeImmutable
204
- * @deprecated see Util.makeImmutable()
205
- * @param {any} object - The object to specify immutable properties for
206
- * @param {string | string[]=} property - The name of the property (or array of names) to make immutable.
207
- * If not provided, the entire object is marked immutable.
208
- * @param {any=} value - Property value (or array of values) to set
209
- * the property to before making immutable. Only used when setting a single
210
- * property. Retained for backward compatibility.
211
- * @return {any} - The original object is returned - for chaining.
212
- */
213
- makeImmutable(object: any, property?: (string | string[]) | undefined, value?: any | undefined): any;
214
- /**
215
- * <p>Make a javascript object property immutable (assuring it cannot be changed
216
- * from the current value).</p>
217
- * <p>
218
- * If the specified property is an object, all attributes of that object are
219
- * made immutable, including properties of contained objects, recursively.
220
- * If a property name isn't supplied, the object and all of its properties
221
- * are made immutable.
222
- * </p>
223
- * <p>
224
- * This operation cannot be undone.
225
- * </p>
226
- *
227
- * <p>Example:</p>
228
- * <pre>
229
- * const config = require('config');
230
- * const myObject = {hello:'world'};
231
- * config.util.makeImmutable(myObject);
232
- * </pre>
233
- *
234
- * @method makeImmutable
235
- * @protected
236
- * @deprecated - partial immutability will no longer be supported by this project
237
- * @param object {Object} - The object to specify immutable properties for
238
- * @param property {string | [string]} - The name of the property (or array of names) to make immutable.
239
- * If not provided, the entire object is marked immutable.
240
- * @param [value] {* | [*]} - Property value (or array of values) to set
241
- * the property to before making immutable. Only used when setting a single
242
- * property. Retained for backward compatibility.
243
- * @return object {Object} - The original object is returned - for chaining.
244
- */
245
- protected makeImmutablePartial(object: any, property: string | [string], value?: any | [any]): any;
246
- /**
247
- * Return the sources for the configurations
248
- *
249
- * <p>
250
- * All sources for configurations are stored in an array of objects containing
251
- * the source name (usually the filename), the original source (as a string),
252
- * and the parsed source as an object.
253
- * </p>
254
- *
255
- * @method getConfigSources
256
- * @return {import('./util').ConfigSource[]} configSources - An array of objects containing
257
- * name, original, and parsed elements
258
- */
259
- getConfigSources(): import("./util").ConfigSource[];
260
- /**
261
- * Load the individual file configurations.
262
- *
263
- * <p>
264
- * This method builds a map of filename to the configuration object defined
265
- * by the file. The search order is:
266
- * </p>
267
- *
268
- * <pre>
269
- * default.EXT
270
- * (deployment).EXT
271
- * (hostname).EXT
272
- * (hostname)-(deployment).EXT
273
- * local.EXT
274
- * local-(deployment).EXT
275
- * </pre>
276
- *
277
- * <p>
278
- * EXT can be yml, yaml, coffee, iced, json, jsonc, cson or js signifying the file type.
279
- * yaml (and yml) is in YAML format, coffee is a coffee-script, iced is iced-coffee-script,
280
- * json is in JSON format, jsonc is in JSONC format, cson is in CSON format, properties is
281
- * in .properties format (http://en.wikipedia.org/wiki/.properties), and js is a javascript
282
- * executable file that is require()'d with module.exports being the config object.
283
- * </p>
284
- *
285
- * <p>
286
- * hostname is the $HOST environment variable (or --HOST command line parameter)
287
- * if set, otherwise the $HOSTNAME environment variable (or --HOSTNAME command
288
- * line parameter) if set, otherwise the hostname found from
289
- * require('os').hostname().
290
- * </p>
291
- *
292
- * <p>
293
- * Once a hostname is found, everything from the first period ('.') onwards
294
- * is removed. For example, abc.example.com becomes abc
295
- * </p>
296
- *
297
- * <p>
298
- * (deployment) is the deployment type, found in the $NODE_ENV environment
299
- * variable (which can be overridden by using $NODE_CONFIG_ENV
300
- * environment variable). Defaults to 'development'.
301
- * </p>
302
- *
303
- * <p>
304
- * If the $NODE_APP_INSTANCE environment variable (or --NODE_APP_INSTANCE
305
- * command line parameter) is set, then files with this appendage will be loaded.
306
- * See the Multiple Application Instances section of the main documentation page
307
- * for more information.
308
- * </p>
309
- *
310
- * @see Util.loadFileConfigs for discrete execution of most of this functionality
311
- * @method loadFileConfigs
312
- * @param {string=} configDir the path to the directory containing the configurations to load
313
- * @param {LoadOptions=} options parsing options
314
- * @return {Record<string, any>} The configuration object
315
- */
316
- loadFileConfigs(configDir?: string | undefined, options?: LoadOptions | undefined): Record<string, any>;
317
- /**
318
- * Attach the Config class prototype to all config objects recursively.
319
- *
320
- * <p>
321
- * This allows you to do anything with CONFIG sub-objects as you can do with
322
- * the top-level CONFIG object. It's so you can do this:
323
- * </p>
324
- *
325
- * <pre>
326
- * const CUST_CONFIG = require('config').Customer;
327
- * CUST_CONFIG.get(...)
328
- * </pre>
329
- *
330
- * @method attachProtoDeep
331
- * @param {object} toObject
332
- * @param {number=20} depth
333
- * @return {object}
334
- */
335
- attachProtoDeep(toObject: object, depth?: number): object;
336
- /**
337
- * <p>Get a Config Environment Variable Value</p>
338
- *
339
- * <p>
340
- * This method returns the value of the specified config environment variable,
341
- * including any defaults or overrides.
342
- * </p>
343
- *
344
- * @method getEnv
345
- * @param varName {String} The environment variable name
346
- * @return {String} The value of the environment variable
347
- */
348
- getEnv(varName: string): string;
349
- /**
350
- * Returns a new deep copy of the current config object, or any part of the config if provided.
351
- *
352
- * @param {Config} config The part of the config to copy and serialize. Omit this argument to return the entire config.
353
- * @returns {object} The cloned config or part of the config
354
- */
355
- toObject(config: Config): object;
356
- /**
357
- * Run strictness checks on NODE_ENV and NODE_APP_INSTANCE and throw an error if there's a problem.
358
- * @param {Config} config
359
- */
360
- runStrictnessChecks(config?: Config): void;
361
- /**
362
- * @deprecated please use Parser.stripYamlComments
363
- * @param {string} fileStr The string to strip comments from
364
- */
365
- stripYamlComments(fileStr: string): any;
366
- #private;
367
- }
368
- declare const LOAD_SYMBOL: unique symbol;
6
+ type Config = import("./config.mjs").Config;
@@ -285,7 +285,7 @@ export class Util {
285
285
  * @method extendDeep
286
286
  * @param mergeInto {Object} The object to merge into
287
287
  * @param mergeFrom... {Object} - Any number of objects to merge from
288
- * @param [depth] {number} An optional depth to prevent recursion. Default: 20.
288
+ * @param {number} [depth=20] - An optional depth to prevent recursion. Default: 20.
289
289
  * @return {Object} The altered mergeInto object is returned
290
290
  */
291
291
  static extendDeep(mergeInto: any, ...vargs: any[]): any;
@@ -368,10 +368,9 @@ export class Load {
368
368
  * This function exists in part to reduce the circular dependency of variable initializations
369
369
  * in the config.js file
370
370
  * @param {string} environments the NODE_CONFIG_ENVs you want to load
371
- * @private
372
371
  * @returns {Load}
373
372
  */
374
- private static fromEnvironment;
373
+ static fromEnvironment(environments: string): Load;
375
374
  /**
376
375
  * @constructor
377
376
  * @param {LoadOptions=} options - defaults to reading from environment variables
@@ -581,7 +580,7 @@ export class RawConfig {
581
580
  resolve(): any;
582
581
  #private;
583
582
  }
584
- import { deferConfig } from "./defer.js";
583
+ import { deferConfig } from './defer.js';
585
584
  /**
586
585
  * Record a set of lookups
587
586
  */
package/types/parser.d.ts CHANGED
@@ -1,132 +1,135 @@
1
- /**
2
- * @param {string} filename
3
- * @param {string} content
4
- * @returns {object | undefined}
5
- */
6
- export function parse(filename: string, content: string): object | undefined;
7
- /**
8
- * @param {string} filename
9
- * @param {string} content
10
- * @returns {object}
11
- */
12
- export function xmlParser(filename: string, content: string): object;
13
- /**
14
- * @param {string} filename
15
- * @param {string} content
16
- * @returns {object}
17
- */
18
- export function jsParser(filename: string, content: string): object;
19
- /**
20
- * @param {string} filename
21
- * @param {string} content
22
- * @returns {object}
23
- */
24
- export function tsParser(filename: string, content: string): object;
25
- /**
26
- * @param {string} filename
27
- * @param {string} content
28
- * @returns {object}
29
- */
30
- export function coffeeParser(filename: string, content: string): object;
31
- /**
32
- * @param {string} filename
33
- * @param {string} content
34
- * @returns {object | undefined}
35
- */
36
- export function icedParser(filename: string, content: string): object | undefined;
37
- /**
38
- * @param {string} filename
39
- * @param {string} content
40
- * @returns {object | undefined}
41
- */
42
- export function yamlParser(filename: string, content: string): object | undefined;
43
- /**
44
- * @param {string} filename
45
- * @param {string} content
46
- * @returns {object}
47
- */
48
- export function jsonParser(filename: string, content: string): object;
49
- /**
50
- * @param {string} filename
51
- * @param {string} content
52
- * @returns {object}
53
- */
54
- export function json5Parser(filename: string, content: string): object;
55
- /**
56
- * @param {string} filename
57
- * @param {string} content
58
- * @returns {object}
59
- */
60
- export function hjsonParser(filename: string, content: string): object;
61
- /**
62
- * @param {string} filename
63
- * @param {string} content
64
- * @returns {object}
65
- */
66
- export function tomlParser(filename: string, content: string): object;
67
- /**
68
- * @param {string} filename
69
- * @param {string} content
70
- * @returns {object}
71
- */
72
- export function csonParser(filename: string, content: string): object;
73
- /**
74
- * @param {string} filename
75
- * @param {string} content
76
- * @returns {object}
77
- */
78
- export function propertiesParser(filename: string, content: string): object;
79
- /**
80
- * Strip YAML comments from the string
81
- *
82
- * The 2.0 yaml parser doesn't allow comment-only or blank lines. Strip them.
83
- *
84
- * @protected
85
- * @method stripYamlComments
86
- * @param {string} fileStr The string to strip comments from
87
- * @return {string} The string with comments stripped.
88
- */
89
- export function stripYamlComments(fileStr: string): string;
90
- /**
91
- * Parses the environment variable to the boolean equivalent.
92
- * Defaults to false
93
- *
94
- * @param {string} filename - Filename of the env variable (not used)
95
- * @param {string} content - Environment variable value
96
- * @return {boolean} - Boolean value fo the passed variable value
97
- */
98
- export function booleanParser(filename: string, content: string): boolean;
99
- /**
100
- * Parses the environment variable to the number equivalent.
101
- * Defaults to undefined
102
- *
103
- * @param {string} filename - Filename of the env variable (not used)
104
- * @param {string} content - Environment variable value
105
- * @return {number} - Number value fo the passed variable value
106
- */
107
- export function numberParser(filename: string, content: string): number;
108
- /**
109
- * @param {string} name
110
- * @returns {ParserFn | undefined}
111
- */
112
- export function getParser(name: string): ParserFn | undefined;
113
- /**
114
- * @param {string} name
115
- * @param {ParserFn} parser
116
- */
117
- export function setParser(name: string, parser: ParserFn): void;
118
- /**
119
- * @param {string=} name
120
- * @returns {string[] | number}
121
- */
122
- export function getFilesOrder(name?: string | undefined): string[] | number;
123
- /**
124
- * @param {string|string[]} name
125
- * @param {number=} newIndex
126
- * @returns {string[]}
127
- */
128
- export function setFilesOrder(name: string | string[], newIndex?: number | undefined): string[];
1
+ export default Parser;
129
2
  /**
130
3
  * <T>
131
4
  */
132
5
  export type ParserFn<T = any> = (filename: string, content: string) => T | undefined;
6
+ declare namespace Parser {
7
+ /**
8
+ * @param {string} filename
9
+ * @param {string} content
10
+ * @returns {object | undefined}
11
+ */
12
+ function parse(filename: string, content: string): object | undefined;
13
+ /**
14
+ * @param {string} filename
15
+ * @param {string} content
16
+ * @returns {object}
17
+ */
18
+ function xmlParser(filename: string, content: string): object;
19
+ /**
20
+ * @param {string} filename
21
+ * @param {string} content
22
+ * @returns {object}
23
+ */
24
+ function jsParser(filename: string, content: string): object;
25
+ /**
26
+ * @param {string} filename
27
+ * @param {string} content
28
+ * @returns {object}
29
+ */
30
+ function tsParser(filename: string, content: string): object;
31
+ /**
32
+ * @param {string} filename
33
+ * @param {string} content
34
+ * @returns {object}
35
+ */
36
+ function coffeeParser(filename: string, content: string): object;
37
+ /**
38
+ * @param {string} filename
39
+ * @param {string} content
40
+ * @returns {object | undefined}
41
+ */
42
+ function icedParser(filename: string, content: string): object | undefined;
43
+ /**
44
+ * @param {string} filename
45
+ * @param {string} content
46
+ * @returns {object | undefined}
47
+ */
48
+ function yamlParser(filename: string, content: string): object | undefined;
49
+ /**
50
+ * @param {string} filename
51
+ * @param {string} content
52
+ * @returns {object}
53
+ */
54
+ function jsonParser(filename: string, content: string): object;
55
+ /**
56
+ * @param {string} filename
57
+ * @param {string} content
58
+ * @returns {object}
59
+ */
60
+ function json5Parser(filename: string, content: string): object;
61
+ /**
62
+ * @param {string} filename
63
+ * @param {string} content
64
+ * @returns {object}
65
+ */
66
+ function hjsonParser(filename: string, content: string): object;
67
+ /**
68
+ * @param {string} filename
69
+ * @param {string} content
70
+ * @returns {object}
71
+ */
72
+ function tomlParser(filename: string, content: string): object;
73
+ /**
74
+ * @param {string} filename
75
+ * @param {string} content
76
+ * @returns {object}
77
+ */
78
+ function csonParser(filename: string, content: string): object;
79
+ /**
80
+ * @param {string} filename
81
+ * @param {string} content
82
+ * @returns {object}
83
+ */
84
+ function propertiesParser(filename: string, content: string): object;
85
+ /**
86
+ * Strip YAML comments from the string
87
+ *
88
+ * The 2.0 yaml parser doesn't allow comment-only or blank lines. Strip them.
89
+ *
90
+ * @protected
91
+ * @method stripYamlComments
92
+ * @param {string} fileStr The string to strip comments from
93
+ * @return {string} The string with comments stripped.
94
+ */
95
+ function stripYamlComments(fileStr: string): string;
96
+ /**
97
+ * Parses the environment variable to the boolean equivalent.
98
+ * Defaults to false
99
+ *
100
+ * @param {string} filename - Filename of the env variable (not used)
101
+ * @param {string} content - Environment variable value
102
+ * @return {boolean} - Boolean value fo the passed variable value
103
+ */
104
+ function booleanParser(filename: string, content: string): boolean;
105
+ /**
106
+ * Parses the environment variable to the number equivalent.
107
+ * Defaults to undefined
108
+ *
109
+ * @param {string} filename - Filename of the env variable (not used)
110
+ * @param {string} content - Environment variable value
111
+ * @return {number} - Number value fo the passed variable value
112
+ */
113
+ function numberParser(filename: string, content: string): number;
114
+ /**
115
+ * @param {string} name
116
+ * @returns {ParserFn | undefined}
117
+ */
118
+ function getParser(name: string): ParserFn | undefined;
119
+ /**
120
+ * @param {string} name
121
+ * @param {ParserFn} parser
122
+ */
123
+ function setParser(name: string, parser: ParserFn): void;
124
+ /**
125
+ * @param {string=} name
126
+ * @returns {string[] | number}
127
+ */
128
+ function getFilesOrder(name?: string | undefined): string[] | number;
129
+ /**
130
+ * @param {string|string[]} name
131
+ * @param {number=} newIndex
132
+ * @returns {string[]}
133
+ */
134
+ function setFilesOrder(name: string | string[], newIndex?: number | undefined): string[];
135
+ }