UNPKG

@skhemata/skhemata-form

Version:

Skhemata Form Web Component. This web component can be used as base web component when working with forms and inputs.

22 lines (18 loc) 538 B
import assertString from './util/assertString'; import merge from './util/merge'; const default_json_options = { allow_primitives: false, }; export default function isJSON(str, options) { assertString(str); try { options = merge(options, default_json_options); let primitives = []; if (options.allow_primitives) { primitives = [null, false, true]; } const obj = JSON.parse(str); return primitives.includes(obj) || (!!obj && typeof obj === 'object'); } catch (e) { /* ignore */ } return false; }