* 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)
| 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. |
no outgoing calls
no test coverage detected