From f3d08afcdd4bbb66acf68af9f2633b206c0942bb Mon Sep 17 00:00:00 2001 From: ecwu Date: Sat, 4 Jan 2025 23:53:28 +0800 Subject: [PATCH] feat: add isVailedJSON utility function for JSON validation --- src/utils/isVailedJSON.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/utils/isVailedJSON.ts diff --git a/src/utils/isVailedJSON.ts b/src/utils/isVailedJSON.ts new file mode 100644 index 0000000..b35a8a3 --- /dev/null +++ b/src/utils/isVailedJSON.ts @@ -0,0 +1,8 @@ +export const isVailedJSON = (str: string): boolean => { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; +};