updeep-remeda/lib/in.js

16 lines
397 B
JavaScript
Raw Normal View History

2015-08-05 05:28:31 +00:00
import curry from 'lodash/function/curry';
import reject from 'lodash/collection/reject';
2015-08-05 05:28:31 +00:00
import update from './update';
2015-08-05 07:27:56 +00:00
function updateIn(path, value, object) {
const parts = Array.isArray(path) ?
path :
reject(path.split('.'), x => !x);
2015-08-05 05:28:31 +00:00
const updates = parts.reduceRight((acc, key) => ({ [key]: acc }), value);
2015-08-05 07:27:56 +00:00
return update(updates, object);
2015-08-05 05:28:31 +00:00
}
export default curry(updateIn);