source: trip-planner-front/node_modules/@angular-devkit/core/src/utils/object.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[6a3a178]1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.deepCopy = exports.mapObject = void 0;
11/** @deprecated Since v12.0, unused by the Angular tooling */
12function mapObject(obj, mapper) {
13 return Object.keys(obj).reduce((acc, k) => {
14 acc[k] = mapper(k, obj[k]);
15 return acc;
16 }, {});
17}
18exports.mapObject = mapObject;
19const copySymbol = Symbol();
20// eslint-disable-next-line @typescript-eslint/no-explicit-any
21function deepCopy(value) {
22 if (Array.isArray(value)) {
23 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24 return value.map((o) => deepCopy(o));
25 }
26 else if (value && typeof value === 'object') {
27 const valueCasted = value;
28 if (valueCasted[copySymbol]) {
29 // This is a circular dependency. Just return the cloned value.
30 return valueCasted[copySymbol];
31 }
32 if (valueCasted['toJSON']) {
33 return JSON.parse(valueCasted['toJSON']());
34 }
35 const copy = Object.create(Object.getPrototypeOf(valueCasted));
36 valueCasted[copySymbol] = copy;
37 for (const key of Object.getOwnPropertyNames(valueCasted)) {
38 copy[key] = deepCopy(valueCasted[key]);
39 }
40 valueCasted[copySymbol] = undefined;
41 return copy;
42 }
43 else {
44 return value;
45 }
46}
47exports.deepCopy = deepCopy;
Note: See TracBrowser for help on using the repository browser.