Urara-Blog/node_modules/.pnpm-store/v3/files/61/5860669926690d3e5a435918c1b85b0d724bdec029fc2b49a251d493b3fe1de11f615da6a51f25ef6d8adc9b227f5149186591cca928db87d49cea7dfed85d
2022-08-14 01:14:53 +08:00

18 lines
503 B
Text

// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;
// Windows paths like `c:\`
const WINDOWS_PATH_REGEX = /^[a-zA-Z]:\\/;
export default function isAbsoluteUrl(url) {
if (typeof url !== 'string') {
throw new TypeError(`Expected a \`string\`, got \`${typeof url}\``);
}
if (WINDOWS_PATH_REGEX.test(url)) {
return false;
}
return ABSOLUTE_URL_REGEX.test(url);
}