MCPcopy Index your code
hub / github.com/node-config/node-config / setModuleDefaults

Method setModuleDefaults

lib/util.js:1243–1269  ·  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

1241 * @return {Object} - The module level configuration object.
1242 */
1243 setModuleDefaults(moduleName, defaultProperties) {
1244 this.updated = true;
1245
1246 if (this.defaults === undefined) {
1247 this.defaults = {};
1248 this.unmerged = {};
1249
1250 if (this.sources) {
1251 this.sources.splice(0, 0, { name: 'Module Defaults', parsed: this.defaults });
1252 }
1253 }
1254
1255 const path = moduleName.split('.');
1256 const defaults = Util.setPath(this.defaults, path, Util.getPath(this.defaults, path) ?? {});
1257
1258 Util.extendDeep(defaults, defaultProperties);
1259
1260 const original =
1261 Util.getPath(this.unmerged, path) ??
1262 Util.setPath(this.unmerged, path, Util.getPath(this.config, path) ?? {});
1263
1264 const moduleConfig = Util.extendDeep({}, defaults, original);
1265 Util.setPath(this.config, path, moduleConfig);
1266 Util.resolveDeferredConfigs(this.config);
1267
1268 return moduleConfig;
1269 }
1270
1271 /**
1272 * Parse and return the specified string with the specified format.

Callers 3

2-config-test.jsFile · 0.45
0-util.jsFile · 0.45
config.tsFile · 0.45

Calls 4

setPathMethod · 0.80
getPathMethod · 0.80
extendDeepMethod · 0.80

Tested by

no test coverage detected