Adds safeParseJSON.ts file

This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2022-10-07 12:43:47 +05:30
1 parent da88beb1f5
commit 12f54773f9
1 file changed
+8
+8
View File
@@ -0,0 +1,8 @@
export default function parseJSONSafely(str: string) {
try {
return JSON.parse(str);
} catch (e) {
console.error((e as Error).message);
return {};
}
}