@simongrasinovski/str-utils
Version:
A lightweight utility library for effortless string manipulation. Simplify common tasks like case validation, conversion and formatting with easy-to-use functions that enhance your JavaScript applications
26 lines (24 loc) • 580 B
JavaScript
;
var _require = require('./utils'),
ensureString = _require.ensureString;
/**
* Checks if a string is a URL.
*
* @function
* @param {string} input - The string to valiate.
* @returns {boolean} true if valid, false otherwise.
*
* @throws {TypeError} Throws an error if the input is not a string.
*
* @example
* const result = isValidURL('https://www.example.com');
* console.log(result); // true
*/
module.exports = ensureString(function (input) {
try {
new URL(input);
return true;
} catch (_unused) {
return false;
}
});