UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

33 lines (32 loc) 686 B
const protocols = [ 'http', 'https', 'ftp', 'ftps', 'file', 'data', 'mailto', 'tel', 'sms', 'ws', 'wss', ]; /** * Check if a URL is absolute * @param url - The URL to check * @returns True if the URL is absolute, false otherwise */ export const isAbsoluteUrl = (url) => { if (!url || typeof url !== 'string') return false; try { if (typeof URL.canParse === 'function' && !URL.canParse(url)) return false; const parsedUrl = new URL(url); const protocol = parsedUrl.protocol.slice(0, -1); return protocols.includes(protocol); } catch (_a) { return false; } };