PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.9.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.9.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Admin / package / parse-json.js

parse-json.js in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.9.0, at src/Performance/Admin/package/parse-json.js

21 lines 588 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 export default ( jsonString, forceJson = true ) => {
2 try {
3 var o = JSON.parse( jsonString );
4
5 // Handle non-exception-throwing cases:
6 // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,
7 // but... JSON.parse(null) returns null, and typeof null === "object",
8 // so we must check for that, too. Thankfully, null is falsey, so this suffices:
9 if (o && typeof o === "object") {
10 return o;
11 }
12 }
13 catch (e) { }
14 if ( jsonString && typeof jsonString === "object" ) {
15 return jsonString;
16 }
17 if ( forceJson ) {
18 return {};
19 }
20 return false;
21 };