You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
472 B
TypeScript
22 lines
472 B
TypeScript
// Copyright (C) 2021 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
function deepCopy<T>(obj: T): T {
|
|
if (typeof obj !== 'object') {
|
|
return obj;
|
|
}
|
|
if (!obj) {
|
|
return obj;
|
|
}
|
|
const container: any = (obj instanceof Array) ? [] : {};
|
|
for (const i in obj) {
|
|
if (Object.prototype.hasOwnProperty.call(obj, i)) {
|
|
container[i] = deepCopy(obj[i]);
|
|
}
|
|
}
|
|
return container;
|
|
}
|
|
|
|
export default deepCopy;
|