-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anthony Fu <[email protected]>
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getTypeName } from './base' | ||
|
||
export function isDeepEqual(value1: any, value2: any): boolean { | ||
const type1 = getTypeName(value1) | ||
const type2 = getTypeName(value2) | ||
if (type1 !== type2) | ||
return false | ||
|
||
if (type1 === 'array') { | ||
if (value1.length !== value2.length) | ||
return false | ||
|
||
return value1.every((item: any, i: number) => { | ||
return isDeepEqual(item, value2[i]) | ||
}) | ||
} | ||
if (type1 === 'object') { | ||
const keyArr = Object.keys(value1) | ||
if (keyArr.length !== Object.keys(value2).length) | ||
return false | ||
|
||
return keyArr.every((key: string) => { | ||
return isDeepEqual(value1[key], value2[key]) | ||
}) | ||
} | ||
return value1 === value2 | ||
} |