mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-24 06:03:07 +02:00
c2370a1be6
* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
23 lines
633 B
TypeScript
23 lines
633 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
// structredCloneが遅いため
|
|
// SEE: http://var.blog.jp/archives/86038606.html
|
|
|
|
type Cloneable = string | number | boolean | null | { [key: string]: Cloneable } | Cloneable[];
|
|
|
|
export function deepClone<T extends Cloneable>(x: T): T {
|
|
if (typeof x === 'object') {
|
|
if (x === null) return x;
|
|
if (Array.isArray(x)) return x.map(deepClone) as T;
|
|
const obj = {} as Record<string, Cloneable>;
|
|
for (const [k, v] of Object.entries(x)) {
|
|
obj[k] = deepClone(v);
|
|
}
|
|
return obj as T;
|
|
} else {
|
|
return x;
|
|
}
|
|
}
|