| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | var baseRest = require('./_baseRest'), |
| 2 | isIterateeCall = require('./_isIterateeCall'); |
| 3 | |
| 4 | /** |
| 5 | * Creates a function like `_.assign`. |
| 6 | * |
| 7 | * @private |
| 8 | * @param {Function} assigner The function to assign values. |
| 9 | * @returns {Function} Returns the new assigner function. |
| 10 | */ |
| 11 | function createAssigner(assigner) { |
| 12 | return baseRest(function(object, sources) { |
| 13 | var index = -1, |
| 14 | length = sources.length, |
| 15 | customizer = length > 1 ? sources[length - 1] : undefined, |
| 16 | guard = length > 2 ? sources[2] : undefined; |
| 17 | |
| 18 | customizer = (assigner.length > 3 && typeof customizer == 'function') |
| 19 | ? (length--, customizer) |
| 20 | : undefined; |
| 21 | |
| 22 | if (guard && isIterateeCall(sources[0], sources[1], guard)) { |
| 23 | customizer = length < 3 ? undefined : customizer; |
| 24 | length = 1; |
| 25 | } |
| 26 | object = Object(object); |
| 27 | while (++index < length) { |
| 28 | var source = sources[index]; |
| 29 | if (source) { |
| 30 | assigner(object, source, index, customizer); |
| 31 | } |
| 32 | } |
| 33 | return object; |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | module.exports = createAssigner; |