Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (obj: any, path: Path, value?: any): any => {
let ast = null
if (!cache.get(path)) {
ast = parseDesturctPath(path)
cache.set(path, ast)
} else {
ast = cache.get(path)
}
if (!isArr(ast.destruct) && !isPlainObj(ast.destruct)) {
return get(obj, path, value)
}
return mapReduce(ast.destruct, (mapPath, key) => {
return get(obj, ast.startPath.concat(key[key.length - 1]))
})
}
}
destructKey(key, readyReplace) {
if (!key) {
return
}
token = key
if (readyReplace) {
realKey = key
lastDestruct = destruct
return
}
if (isArr(destruct)) {
;(destruct as string[]).push(key)
} else if (isPlainObj(destruct)) {
destruct[realKey && lastDestruct === destruct ? realKey : key] = key
}
realKey = ''
lastDestruct = destruct
},
destructArrayStart() {
return map(internalObj, (item: any, key: string) => {
const newPath = path.concat(key)
if (isArr(item) || isPlainObj(item)) {
return internalTraverse(item, newPath)
} else {
return callback(
newPath,
newPath.slice(0, newPath.length - 1).concat(item)
)
}
})
}
each(internalObj, (item: any, key: string) => {
const newPath = path.concat(key)
if (isArr(item) || isPlainObj(item)) {
internalTraverse(item, newPath)
} else {
callback(newPath, item)
}
})
}
destructArrayStart() {
if (!destruct) {
root = []
destruct = root
} else {
destruct = []
}
const tail = stack[stack.length - 1]
if (isPlainObj(tail)) {
tail[token] = destruct
} else if (isArr(tail)) {
tail.push(destruct)
}
stack.push(destruct)
},
destructObjectStart() {