UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

27 lines (22 loc) 455 B
/** * to json */ // eval hack var evil = fn => { // A variable points to Function, preventing reporting errors var Fn = Function; return new Fn('return ' + fn)(); }; // bbo.toJSON = bbo.tojson = bbo.toJson var toJson = res => { if (!res) return null; if (typeof res === 'string') { try { return JSON.parse(res); } catch (e) { return evil('(' + res + ')'); } } else { return res; } }; export default toJson;