-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafeCopy.ts
63 lines (55 loc) · 1.57 KB
/
safeCopy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2022 Michael Federczuk
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { deepCopy } from "./deepCopy";
import { deepFreeze } from "./deepFreeze";
/**
* Creates a deep copy of **arr** that is also deeply frozen.
*
* @param arr The 3-dimensional array to create a deeply frozen copy of.
*
* @returns A deeply frozen copy of **arr**.
*
* @see {@link deepCopy}
* @see {@link deepFreeze}
*/
function safeCopy<T>(arr: readonly (readonly (readonly T[])[])[]): readonly (readonly (readonly Readonly<T>[])[])[];
/**
* Creates a deep copy of **arr** that is also deeply frozen.
*
* @param arr The 2-dimensional array to create a deeply frozen copy of.
*
* @returns A deeply frozen copy of **arr**.
*
* @see {@link deepCopy}
* @see {@link deepFreeze}
*/
function safeCopy<T>(arr: readonly (readonly T[])[]): readonly (readonly Readonly<T>[])[];
/**
* Creates a deep copy of **arr** that is also deeply frozen.
*
* @param arr The 1-dimensional array to create a deeply frozen copy of.
*
* @returns A deeply frozen copy of **arr**.
*
* @see {@link deepCopy}
* @see {@link deepFreeze}
*/
function safeCopy<T>(arr: readonly T[]): readonly Readonly<T>[];
/**
* Creates a deep copy of **obj** that is also deeply frozen.
*
* @param obj The object to create a deeply frozen copy of.
*
* @returns A deeply frozen copy of **obj**.
*
* @see {@link deepCopy}
* @see {@link deepFreeze}
*/
function safeCopy<T>(obj: T): Readonly<T>;
function safeCopy<T>(obj: T): Readonly<T> {
return deepFreeze(deepCopy(obj));
}
deepFreeze(safeCopy);
export { safeCopy };