-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassign.js
29 lines (27 loc) · 829 Bytes
/
assign.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
var curry2 = require('./internal/curry2')
var clone = require('./clone')
var keys = require('./keys')
/**
* Assign keys from left to right.
*
* @param {Object} fromCollection - Source collection
* @param {Object} toCollection - Target collection
* @returns {Object} Returns copy of `toCollection` overwritten by `fromCollection`.
*
* @example
* assign({ a: 1 }, { a: 4, b: 2 }) // => { a: 1, b: 2 }
*
* @since 0.2.0
*/
function assign (fromCollection, toCollection) {
var result = {}
if (typeof toCollection === 'object' && toCollection !== null) {
result = clone(toCollection)
}
var fromCollectionKeys = keys(fromCollection)
for (var index in fromCollectionKeys) {
result[fromCollectionKeys[index]] = fromCollection[fromCollectionKeys[index]]
}
return result
}
module.exports = curry2(assign)