UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

14 lines (10 loc) 287 B
export const parseJsonSafely = (str : string, parseWith? : (str : string) => object) : object | undefined => { if (!parseWith) parseWith = JSON.parse let result try { result = parseWith(str) } catch (e) { result = undefined } return result }