Created
April 12, 2021 18:46
-
-
Save gaurangrshah/2f51b9ff670e6898adec2781642c44b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export function isValidJson(string) { | |
/** | |
* @SCOPE: uses json.parse to validate a string as json | |
* used by: | |
* - show-json | |
* | |
*/ | |
if (typeof string !== "string") return false; | |
try { | |
JSON.parse(string); | |
return true; | |
} catch (error) { | |
return false; | |
} | |
} |
This file contains hidden or 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
export function jsonCompare(val1, val2) { | |
// unused | |
let compare1, compare2; | |
const values = [val1, val2]; | |
const comparators = values.map((val) => | |
isValidJson(val) ? val : JSON.stringify(val) | |
); | |
return comparators[0] === comparators[1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment