formats.exposed/public/common/maybeJsonParse.js

15 lines
246 B
JavaScript
Raw Normal View History

2023-08-01 14:20:57 +00:00
// @ts-check
/**
* Like `JSON.parse`, but returns `null` instead of throwing an error.
* @param {string} text
* @returns {unknown}
*/
export default (text) => {
try {
return JSON.parse(text);
} catch (_err) {
return null;
}
};