roles-bot/packages/bot/isJson.ts

11 lines
274 B
TypeScript
Raw Normal View History

2021-12-21 12:55:10 +01:00
export const isJSON = (data: any): boolean => {
2022-01-02 18:54:19 +01:00
if (typeof data !== 'string') return false;
try {
const result = JSON.parse(data);
const type = result.toString();
2021-12-21 12:55:10 +01:00
2022-01-02 18:54:19 +01:00
return type === '[object Object]' || type === '[object Array]';
} catch (err) {
return false;
}
};