MCPcopy Create free account
hub / github.com/ClydeTime/Surge / lodash_set

Method lodash_set

Script/Env.js:79–91  ·  view source on GitHub ↗
(object = {}, path = "", value)

Source from the content-addressed store, hash-verified

77 }
78
79 lodash_set(object = {}, path = "", value) {
80 if (!Array.isArray(path)) path = this.toPath(path)
81 path
82 .slice(0, -1)
83 .reduce(
84 (previousValue, currentValue, currentIndex) =>
85 (Object(previousValue[currentValue]) === previousValue[currentValue])
86 ? previousValue[currentValue]
87 : previousValue[currentValue] = (/^\d+$/.test(path[currentIndex + 1]) ? [] : {}),
88 object
89 )[path[path.length - 1]] = value
90 return object
91 }
92
93 toPath(value) {
94 return value.replace(/\[(\d+)\]/g, '.$1').split('.').filter(Boolean)

Callers 3

setItemMethod · 0.45
fetchMethod · 0.45
doneMethod · 0.45

Calls 1

toPathMethod · 0.45

Tested by

no test coverage detected