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

Method setPath

lib/util.js:630–652  ·  view source on GitHub ↗

* Set objects given a path as a string list * * @method setPath * @param {object} object - Object to set the property on * @param {string|string[]} property - The property name to get (as an array or '.' delimited string) * @param {*} value - value to set, ignoring null * @return {

(object, property, value)

Source from the content-addressed store, hash-verified

628 * @return {*} - the given value
629 */
630 static setPath(object, property, value) {
631 const path = Array.isArray(property) ? property : property.split('.');
632
633 if (value === null || path.length === 0) {
634 return;
635 }
636
637 let next = object;
638
639 for (let i = 0; i < path.length; i++) {
640 let name = path[i];
641
642 if (i === path.length - 1) { // no more keys to make, so set the value
643 next[name] = value;
644 } else if (Object.hasOwnProperty.call(next, name)) {
645 next = next[name];
646 } else {
647 next = next[name] = {};
648 }
649 }
650
651 return value;
652 }
653
654 /**
655 * Return true if two objects have equal contents.

Callers 4

setModuleDefaultsMethod · 0.80
_substituteVarsMethod · 0.80
setModuleDefaultsMethod · 0.80
0-util.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected