UNPKG

@azizbecha/strkit

Version:

strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.

34 lines 1.04 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isJSON; /** * Checks if a string is a valid JSON format. * * @param str - The string to check. * @returns A boolean indicating whether the string is valid JSON. * * @example * isJSON('{"name": "John", "age": 30}'); // Output: true * isJSON('{name: John, age: 30}'); // Output: false * isJSON('random string'); // Output: false */ function isJSON(str) { try { JSON.parse(str); return true; } catch (_a) { return false; } } }); //# sourceMappingURL=isJSON.js.map