@web3r/flowerkit
Version:
A collection of more than 60 often used utility JS functions that simplify frontend development.
15 lines (14 loc) • 528 B
JavaScript
/**
* Checks if string is a valid JSON string
* @param str{String} - source String
* @return {Boolean}
* @example
* // How to check if string is a JSON?
* const str = '{ "hello": "world" }';
* const isStrJSON = isJSON(str);
* console.log(isStrJSON); // => true
*/
const isJSON=str=>{if(typeof str==="string"&&str.length)try{const json=JSON.parse(str);return typeof json==="object";
// eslint-disable-next-line no-unused-vars
}catch(err){return false}else return false};export{isJSON};
//# sourceMappingURL=index.js.map