agsamantha/node_modules/tldts/dist/index.esm.min.js.map

1 line
375 KiB
Text
Raw Normal View History

2024-10-02 15:15:21 -05:00
{"version":3,"file":"index.esm.min.js","sources":["../../tldts-core/src/extract-hostname.ts","../../tldts-core/src/is-valid.ts","../../tldts-core/src/options.ts","../../tldts-core/src/factory.ts","../../tldts-core/src/is-ip.ts","../../tldts-core/src/domain.ts","../../tldts-core/src/subdomain.ts","../../tldts-core/src/domain-without-suffix.ts","../src/data/trie.ts","../src/suffix-trie.ts","../../tldts-core/src/lookup/fast-path.ts","../index.ts"],"sourcesContent":["/**\n * @param url - URL we want to extract a hostname from.\n * @param urlIsValidHostname - hint from caller; true if `url` is already a valid hostname.\n */\nexport default function extractHostname(\n url: string,\n urlIsValidHostname: boolean,\n): string | null {\n let start = 0;\n let end: number = url.length;\n let hasUpper = false;\n\n // If url is not already a valid hostname, then try to extract hostname.\n if (!urlIsValidHostname) {\n // Special handling of data URLs\n if (url.startsWith('data:')) {\n return null;\n }\n\n // Trim leading spaces\n while (start < url.length && url.charCodeAt(start) <= 32) {\n start += 1;\n }\n\n // Trim trailing spaces\n while (end > start + 1 && url.charCodeAt(end - 1) <= 32) {\n end -= 1;\n }\n\n // Skip scheme.\n if (\n url.charCodeAt(start) === 47 /* '/' */ &&\n url.charCodeAt(start + 1) === 47 /* '/' */\n ) {\n start += 2;\n } else {\n const indexOfProtocol = url.indexOf(':/', start);\n if (indexOfProtocol !== -1) {\n // Implement fast-path for common protocols. We expect most protocols\n // should be one of these 4 and thus we will not need to perform the\n // more expansive validity check most of the time.\n const protocolSize = indexOfProtocol - start;\n const c0 = url.charCodeAt(start);\n const c1 = url.charCodeAt(start + 1);\n const c2 = url.charCodeAt(start + 2);\n const c3 = url.charCodeAt(start + 3);\n const c4 = url.charCodeAt(start + 4);\n\n if (\n protocolSize === 5 &&\n c0 === 104 /* 'h' */ &&\n c1 === 116 /* 't' */ &&\n c2 === 116 /* 't' */ &&\n c3 === 112 /* 'p' */ &&\n c4 === 115 /* 's' */\n ) {\n // https\n } else if (\n protocolSize === 4 &&\n c0 === 104 /* 'h' */ &&\n c1 === 116 /* 't' */ &&\n c2 === 116 /* 't' */ &&\n c3 === 112 /* 'p' */\n ) {\n // http\n } else if (\n protocolSize === 3 &&\n c0 === 119 /* 'w' */ &&\n c1 === 115 /* 's' */ &&\n c2 === 115 /* 's' */\n ) {\n // wss\n } else if (\n protocolSize === 2 &&\n c0 === 119 /* 'w' */ &&\n c1 === 115 /* 's' */\n ) {\n // ws\n } else {\n // Check that scheme is valid\n for (let i = start; i < indexOfProtocol; i += 1) {\n const lowerCaseCode = url.charCodeAt(i) | 32;\n if (\n !(\n (\n (lowerCaseCode >= 97 && lowerCaseCode <= 122) || // [a, z]\n (lowerCaseCode >= 48 && lowerCaseCode <= 57) || // [0, 9]\n lowerCaseCode === 46 || // '.'\n lowerCaseCode === 45 || // '-'\n lowerCaseCode === 43\n ) // '+'\n )\n ) {\n return null;\n }\n }\n }\n\n // Skip 0, 1 or more '/' after ':/'\n start = indexOfProtocol + 2;\n while (url.charCodeAt(start) === 47 /* '/' */) {\n start += 1;\n }\n }\n }\n\n // Detect first occurrence of '/', '?' or '#'. We also keep track of the\n // last occurrence of '@', ']' or ':' to speed-up subsequent parsing of\n // (respectively), identifier, ipv6 or port.\n let indexOfIdentifier = -1;\n let indexOfClosingBracket = -1;\n let indexOfPort = -1;\n for (let i = start; i < end; i += 1) {\n const code: number = url.charCodeAt(i);\n