updeep-remeda/dist/updateIn.js
2023-01-03 13:51:35 -05:00

21 lines
756 B
JavaScript

import update from "./update.js";
import splitPath from "./util/splitPath.js";
import wrap from "./wrap.js";
import map from "./map.js";
const wildcard = "*";
function reducePath(acc, key) {
if (key === wildcard) {
return (value) => Object.prototype.hasOwnProperty.call(value, wildcard)
? // If we actually have wildcard as a property, update that
update(value, { [wildcard]: acc })
: // Otherwise map over all properties
map(value, acc);
}
return { [key]: acc };
}
function updateIn(object, path, value) {
const updates = splitPath(path).reduceRight(reducePath, value);
return update(object, updates);
}
export default wrap(updateIn);
//# sourceMappingURL=updateIn.js.map