This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af82534
commit 16768eb
Showing
5 changed files
with
25 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Mutates an object at the path with the value. If the path | ||
* does not exist, it is created by nesting objects along the | ||
* path segments. | ||
* | ||
* From https://stackoverflow.com/a/20240290 | ||
* | ||
* @param {any} obj - The object to mutate. | ||
* @param {string} path - The dot delimited path on the object to mutate. | ||
* @param {unknown} value - The value to set at the path. | ||
*/ | ||
exports.setToValue = function setValue(obj, path, value) { | ||
var a = path.split('.') | ||
var o = obj | ||
while (a.length - 1) { | ||
var n = a.shift() | ||
if (!(n in o)) o[n] = {} | ||
o = o[n] | ||
} | ||
o[a[0]] = value | ||
} |