Skip to content

Commit 16ff06f

Browse files
committed
Add special case for Dates in clone
Fixes #78
1 parent 47e718d commit 16ff06f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

util.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function isNonPrimitive(value: any): value is object {
2222
/**
2323
Recursively copy a value.
2424
25-
@param source - should be a JavaScript primitive, Array, or (plain old) Object.
25+
@param source - should be a JavaScript primitive, Array, Date, or (plain old) Object.
2626
@returns copy of source where every Array and Object have been recursively
2727
reconstructed from their constituent elements
2828
*/
@@ -42,6 +42,11 @@ export function clone<T extends any>(source: T): T {
4242
}
4343
return arrayTarget
4444
}
45+
// Date
46+
if (source.constructor == Date) {
47+
const dateTarget: any = new Date(+source)
48+
return dateTarget
49+
}
4550
// Object
4651
const objectTarget: any = {}
4752
// declaring the variable (with const) inside the loop is faster

0 commit comments

Comments
 (0)