forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignWith.js
35 lines (33 loc) · 1.17 KB
/
assignWith.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import copyObject from './.internal/copyObject.js'
import createAssigner from './.internal/createAssigner.js'
import keys from './keys.js'
/**
* This method is like `assign` except that it accepts `customizer`
* which is invoked to produce the assigned values. If `customizer` returns
* `undefined`, assignment is handled by the method instead. The `customizer`
* is invoked with five arguments: (objValue, srcValue, key, object, source).
*
* **Note:** This method mutates `object`.
*
* @since 4.0.0
* @category Object
* @param {Object} object The destination object.
* @param {...Object} sources The source objects.
* @param {Function} [customizer] The function to customize assigned values.
* @returns {Object} Returns `object`.
* @see assignInWith
* @example
*
* function customizer(objValue, srcValue) {
* return isUndefined(objValue) ? srcValue : objValue
* }
*
* const defaults = partialRight(assignWith, customizer)
*
* defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 })
* // => { 'a': 1, 'b': 2 }
*/
const assignWith = createAssigner((object, source, srcIndex, customizer) => {
copyObject(source, keys(source), object, customizer)
})
export default assignWith