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

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.3 KB
RevLine 
[a762898]1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const identity = require('../../function/identity.js');
6const isFunction = require('../../predicate/isFunction.js');
7const forEach = require('../array/forEach.js');
8const isBuffer = require('../predicate/isBuffer.js');
9const isObject = require('../predicate/isObject.js');
10const isTypedArray = require('../predicate/isTypedArray.js');
11const iteratee = require('../util/iteratee.js');
12
13function transform(object, iteratee$1 = identity.identity, accumulator) {
14 const isArrayOrBufferOrTypedArray = Array.isArray(object) || isBuffer.isBuffer(object) || isTypedArray.isTypedArray(object);
15 iteratee$1 = iteratee.iteratee(iteratee$1);
16 if (accumulator == null) {
17 if (isArrayOrBufferOrTypedArray) {
18 accumulator = [];
19 }
20 else if (isObject.isObject(object) && isFunction.isFunction(object.constructor)) {
21 accumulator = Object.create(Object.getPrototypeOf(object));
22 }
23 else {
24 accumulator = {};
25 }
26 }
27 if (object == null) {
28 return accumulator;
29 }
30 forEach.forEach(object, (value, key, object) => iteratee$1(accumulator, value, key, object));
31 return accumulator;
32}
33
34exports.transform = transform;
Note: See TracBrowser for help on using the repository browser.