updeep-remeda/lib/ifElse.js

13 lines
330 B
JavaScript
Raw Normal View History

2017-04-19 00:55:46 +00:00
import update from './update'
import wrap from './wrap'
2015-08-05 06:36:40 +00:00
2015-08-06 06:10:16 +00:00
function updateIfElse(predicate, trueUpdates, falseUpdates, object) {
2017-04-19 00:55:46 +00:00
const test = typeof predicate === 'function' ? predicate(object) : predicate
2015-08-05 06:36:40 +00:00
2017-04-19 00:55:46 +00:00
const updates = test ? trueUpdates : falseUpdates
2015-08-05 06:36:40 +00:00
2017-04-19 00:55:46 +00:00
return update(updates, object)
2015-08-05 06:36:40 +00:00
}
2017-04-19 00:55:46 +00:00
export default wrap(updateIfElse)