mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 08:17:09 +00:00
Modify deepSet() to allow appending to arrays
This commit is contained in:
@@ -175,11 +175,19 @@ function deepEqual (a, b) {
|
||||
* If a non-leaf property does not exist, this function
|
||||
* creates it as an empty object ({}) and keeps traversing.
|
||||
*
|
||||
* The last member of `path` may be `null`, in which case,
|
||||
* if the object pointed to by the next to last member is
|
||||
* an array, an insert operation will take place.
|
||||
*
|
||||
*/
|
||||
function deepSet (obj, path, value) {
|
||||
const key = path.shift();
|
||||
if (!path.length) {
|
||||
obj[key] = value;
|
||||
if (key === null && Array.isArray(obj)) {
|
||||
obj.push(value);
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
} else {
|
||||
if (!Object.hasOwn(obj, key)) {
|
||||
obj[key] = {};
|
||||
|
||||
Reference in New Issue
Block a user