MCPcopy Create free account
hub / github.com/node-config/node-config / setModuleDefaults

Method setModuleDefaults

lib/config.mjs:195–210  ·  view source on GitHub ↗

* * 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 wi

(moduleName, defaultProperties)

Source from the content-addressed store, hash-verified

193 * @see Load.scan() for loading more robust defaults
194 */
195 setModuleDefaults(moduleName, defaultProperties) {
196 // Copy the properties into a new object
197 const path = moduleName.split('.');
198 const load = this.#config[LOAD_SYMBOL];
199 const moduleConfig = load.setModuleDefaults(moduleName, defaultProperties);
200 let existing = Util.getPath(this.#config, path);
201
202 if (existing === undefined) {
203 Util.setPath(this.#config, path, Util.cloneDeep(moduleConfig));
204 } else {
205 Util.extendDeep(existing, moduleConfig);
206 }
207
208 // Attach handlers & watchers onto the module config object
209 return this.attachProtoDeep(Util.getPath(this.#config, path));
210 }
211
212 /**
213 * Set default configurations for a node.js module.

Callers 1

withModuleDefaultsMethod · 0.45

Calls 5

attachProtoDeepMethod · 0.95
getPathMethod · 0.80
setPathMethod · 0.80
cloneDeepMethod · 0.80
extendDeepMethod · 0.80

Tested by

no test coverage detected