1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import arrayEach from './_arrayEach.js';
- import baseCreate from './_baseCreate.js';
- import baseForOwn from './_baseForOwn.js';
- import baseIteratee from './_baseIteratee.js';
- import getPrototype from './_getPrototype.js';
- import isArray from './isArray.js';
- import isBuffer from './isBuffer.js';
- import isFunction from './isFunction.js';
- import isObject from './isObject.js';
- import isTypedArray from './isTypedArray.js';
- function transform(object, iteratee, accumulator) {
- var isArr = isArray(object),
- isArrLike = isArr || isBuffer(object) || isTypedArray(object);
- iteratee = baseIteratee(iteratee, 4);
- if (accumulator == null) {
- var Ctor = object && object.constructor;
- if (isArrLike) {
- accumulator = isArr ? new Ctor : [];
- }
- else if (isObject(object)) {
- accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
- }
- else {
- accumulator = {};
- }
- }
- (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
- return iteratee(accumulator, value, index, object);
- });
- return accumulator;
- }
- export default transform;
|