Last active
April 26, 2024 04:43
-
-
Save trapcodeio/927cf3f382e5ec38518c435817f3ad58 to your computer and use it in GitHub Desktop.
Compare Javascript obj using json
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
/** | |
* Compare two objects. | |
* @param source | |
* @param compare | |
*/ | |
export function isSameObjectByJson(source: Record<any, any>, compare: Record<any, any>) { | |
let s: string, c: string; | |
try { | |
s = JSON.stringify(source, null, 0); | |
} catch (e) { | |
throw new Error(`isSameObjectByJson cannot convert "source" object to JSON`); | |
} | |
try { | |
c = JSON.stringify(compare, null, 0); | |
} catch (e) { | |
throw new Error(`isSameObjectByJson cannot convert "compare" object to JSON`); | |
} | |
return s === c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment