[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 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.deepCopy = exports.mapObject = void 0;
|
---|
| 11 | /** @deprecated Since v12.0, unused by the Angular tooling */
|
---|
| 12 | function mapObject(obj, mapper) {
|
---|
| 13 | return Object.keys(obj).reduce((acc, k) => {
|
---|
| 14 | acc[k] = mapper(k, obj[k]);
|
---|
| 15 | return acc;
|
---|
| 16 | }, {});
|
---|
| 17 | }
|
---|
| 18 | exports.mapObject = mapObject;
|
---|
| 19 | const copySymbol = Symbol();
|
---|
| 20 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
---|
| 21 | function 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 | }
|
---|
| 47 | exports.deepCopy = deepCopy;
|
---|