15 lines
246 B
JavaScript
15 lines
246 B
JavaScript
|
// @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;
|
||
|
}
|
||
|
};
|