mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-10 21:01:41 +00:00
update
This commit is contained in:
47
node_modules/is-url/index.js
generated
vendored
Normal file
47
node_modules/is-url/index.js
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
/**
|
||||
* Expose `isUrl`.
|
||||
*/
|
||||
|
||||
module.exports = isUrl;
|
||||
|
||||
/**
|
||||
* RegExps.
|
||||
* A URL must match #1 and then at least one of #2/#3.
|
||||
* Use two levels of REs to avoid REDOS.
|
||||
*/
|
||||
|
||||
var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
|
||||
|
||||
var localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/
|
||||
var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
|
||||
|
||||
/**
|
||||
* Loosely validate a URL `string`.
|
||||
*
|
||||
* @param {String} string
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
function isUrl(string){
|
||||
if (typeof string !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var match = string.match(protocolAndDomainRE);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var everythingAfterProtocol = match[1];
|
||||
if (!everythingAfterProtocol) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (localhostDomainRE.test(everythingAfterProtocol) ||
|
||||
nonLocalhostDomainRE.test(everythingAfterProtocol)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user