source: node_modules/es-toolkit/dist/compat/object/transform.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import { identity } from '../../function/identity.mjs';
2import { isFunction } from '../../predicate/isFunction.mjs';
3import { forEach } from '../array/forEach.mjs';
4import { isBuffer } from '../predicate/isBuffer.mjs';
5import { isObject } from '../predicate/isObject.mjs';
6import { isTypedArray } from '../predicate/isTypedArray.mjs';
7import { iteratee } from '../util/iteratee.mjs';
8
9function transform(object, iteratee$1 = identity, accumulator) {
10 const isArrayOrBufferOrTypedArray = Array.isArray(object) || isBuffer(object) || isTypedArray(object);
11 iteratee$1 = iteratee(iteratee$1);
12 if (accumulator == null) {
13 if (isArrayOrBufferOrTypedArray) {
14 accumulator = [];
15 }
16 else if (isObject(object) && isFunction(object.constructor)) {
17 accumulator = Object.create(Object.getPrototypeOf(object));
18 }
19 else {
20 accumulator = {};
21 }
22 }
23 if (object == null) {
24 return accumulator;
25 }
26 forEach(object, (value, key, object) => iteratee$1(accumulator, value, key, object));
27 return accumulator;
28}
29
30export { transform };
Note: See TracBrowser for help on using the repository browser.