@web3r/flowerkit
Version:
Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).
15 lines (14 loc) • 604 B
JavaScript
Object.defineProperty(exports,"__esModule",{value:true});
/**
* Checks if a string is a valid JSON string
* @param {string} str source String
* @returns {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"&&json!==null;
// eslint-disable-next-line no-unused-vars
}catch(_err){return false}return false};exports.isJSON=isJSON;
//# sourceMappingURL=index.cjs.map