(str, options)
| 8 | }; |
| 9 | |
| 10 | export default function isJSON(str, options) { |
| 11 | assertString(str); |
| 12 | try { |
| 13 | options = merge(options, default_json_options); |
| 14 | const obj = JSON.parse(str); |
| 15 | |
| 16 | // When allow_any_value is true, accept anything that JSON.parse successfully parses |
| 17 | if (options.allow_any_value) { |
| 18 | return true; |
| 19 | } |
| 20 | |
| 21 | let primitives = []; |
| 22 | if (options.allow_primitives) { |
| 23 | primitives = [null, false, true]; |
| 24 | } |
| 25 | |
| 26 | return includes(primitives, obj) || (!!obj && typeof obj === 'object'); |
| 27 | } catch (e) { /* ignore */ } |
| 28 | return false; |
| 29 | } |
nothing calls this directly
no test coverage detected