@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.
26 lines • 688 B
JavaScript
;
/**
* 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
*/
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