(url)
| 73 | * @returns {Boolean} True if the passed-in url is external |
| 74 | */ |
| 75 | export function isExternal(url) { |
| 76 | let match = url.match( |
| 77 | /^([^:/?#]+:)?(?:\/{2,}([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/ |
| 78 | ); |
| 79 | |
| 80 | if ( |
| 81 | typeof match[1] === 'string' && |
| 82 | match[1].length > 0 && |
| 83 | match[1].toLowerCase() !== location.protocol |
| 84 | ) { |
| 85 | return true; |
| 86 | } |
| 87 | if ( |
| 88 | typeof match[2] === 'string' && |
| 89 | match[2].length > 0 && |
| 90 | match[2].replace( |
| 91 | new RegExp( |
| 92 | ':(' + { 'http:': 80, 'https:': 443 }[location.protocol] + ')?$' |
| 93 | ), |
| 94 | '' |
| 95 | ) !== location.host |
| 96 | ) { |
| 97 | return true; |
| 98 | } |
| 99 | if (/^\/\\/.test(url)) { |
| 100 | return true; |
| 101 | } |
| 102 | return false; |
| 103 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…