@redocly/theme
Version:
Shared UI components lib
36 lines • 973 B
JavaScript
;
/**
* RegExps.
* A URL must match #1 and then at least one of #2/#3.
* Use two levels of REs to avoid REDOS.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isUrl = isUrl;
const protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
const localhostDomainRE = /^localhost[:?\d]*(?:[^:?\d]\S*)?$/;
const nonLocalhostDomainRE = /^[^\s.]+\.\S{2,}$/;
/**
* Loosely validate a URL `string`.
*
* @param {String} input
* @return {Boolean}
*/
function isUrl(input) {
if (typeof input !== 'string') {
return false;
}
const match = input.match(protocolAndDomainRE);
if (!match) {
return false;
}
const everythingAfterProtocol = match[1];
if (!everythingAfterProtocol) {
return false;
}
if (localhostDomainRE.test(everythingAfterProtocol) ||
nonLocalhostDomainRE.test(everythingAfterProtocol)) {
return true;
}
return false;
}
//# sourceMappingURL=is-url.js.map