Skip to content

Commit 2dff7d3

Browse files
committed
feat: use lodash to deep copy objects
1 parent 33c81f6 commit 2dff7d3

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

package-lock.json

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "",
55
"license": "MIT",
66
"author": "João Lenon",
@@ -24,6 +24,7 @@
2424
"@types/debug": "4.1.5",
2525
"@types/jest": "27.0.1",
2626
"@types/kind-of": "6.0.0",
27+
"@types/lodash": "4.14.178",
2728
"@types/mime-types": "2.1.1",
2829
"@types/ms": "0.7.31",
2930
"@types/node": "14.17.0",
@@ -168,6 +169,7 @@
168169
"change-case": "4.1.2",
169170
"http-status-codes": "2.2.0",
170171
"kind-of": "6.0.3",
172+
"lodash": "4.17.21",
171173
"mime-types": "2.1.34",
172174
"ms": "2.1.3",
173175
"pluralize": "8.0.0",

src/Classes/Json.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,17 @@
77
* file that was distributed with this source code.
88
*/
99

10+
import { cloneDeep } from 'lodash'
11+
1012
export class Json {
1113
/**
1214
* Deep copy any object properties without reference
1315
*
1416
* @param object The object to be copied
1517
* @return A copy from object without any reference
1618
*/
17-
static copy<T>(object: T): T {
18-
const copy: any = {}
19-
20-
for (const i in object) {
21-
const item = object[i]
22-
copy[i] =
23-
item != null && typeof item === 'object' ? this.copy(item) : item
24-
}
25-
26-
return copy
19+
static copy<T = any>(object: T): T {
20+
return cloneDeep(object)
2721
}
2822

2923
/**

0 commit comments

Comments
 (0)