|
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 | |
|---|
| 1 | import { identity } from '../../function/identity.mjs';
|
|---|
| 2 | import { isFunction } from '../../predicate/isFunction.mjs';
|
|---|
| 3 | import { forEach } from '../array/forEach.mjs';
|
|---|
| 4 | import { isBuffer } from '../predicate/isBuffer.mjs';
|
|---|
| 5 | import { isObject } from '../predicate/isObject.mjs';
|
|---|
| 6 | import { isTypedArray } from '../predicate/isTypedArray.mjs';
|
|---|
| 7 | import { iteratee } from '../util/iteratee.mjs';
|
|---|
| 8 |
|
|---|
| 9 | function 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 |
|
|---|
| 30 | export { transform };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.