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.

36 lines 1.08 kB
/** * Validates whether a given string is a valid URL. * * This function attempts to create a new `URL` object from the input string. * If the input is not a valid URL, it throws an error and returns `false`. * * @param url - The string to validate as a URL. * @returns `true` if the string is a valid URL, otherwise `false`. * * @example * isURL('https://example.com'); // true * isURL('not-a-url'); // false */ (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 = isURL; function isURL(url) { try { new URL(url); return true; } catch (_a) { return false; } } }); //# sourceMappingURL=isURL.js.map