123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- "use strict";
- const backSlashCharCode = "\\".charCodeAt(0);
- const slashCharCode = "/".charCodeAt(0);
- const aLowerCaseCharCode = "a".charCodeAt(0);
- const zLowerCaseCharCode = "z".charCodeAt(0);
- const aUpperCaseCharCode = "A".charCodeAt(0);
- const zUpperCaseCharCode = "Z".charCodeAt(0);
- const _0CharCode = "0".charCodeAt(0);
- const _9CharCode = "9".charCodeAt(0);
- const plusCharCode = "+".charCodeAt(0);
- const hyphenCharCode = "-".charCodeAt(0);
- const colonCharCode = ":".charCodeAt(0);
- const hashCharCode = "#".charCodeAt(0);
- const queryCharCode = "?".charCodeAt(0);
- function getScheme(specifier) {
- const start = specifier.charCodeAt(0);
-
- if (
- (start < aLowerCaseCharCode || start > zLowerCaseCharCode) &&
- (start < aUpperCaseCharCode || start > zUpperCaseCharCode)
- ) {
- return undefined;
- }
- let i = 1;
- let ch = specifier.charCodeAt(i);
- while (
- (ch >= aLowerCaseCharCode && ch <= zLowerCaseCharCode) ||
- (ch >= aUpperCaseCharCode && ch <= zUpperCaseCharCode) ||
- (ch >= _0CharCode && ch <= _9CharCode) ||
- ch === plusCharCode ||
- ch === hyphenCharCode
- ) {
- if (++i === specifier.length) return undefined;
- ch = specifier.charCodeAt(i);
- }
-
- if (ch !== colonCharCode) return undefined;
-
-
- if (i === 1) {
- const nextChar = i + 1 < specifier.length ? specifier.charCodeAt(i + 1) : 0;
- if (
- nextChar === 0 ||
- nextChar === backSlashCharCode ||
- nextChar === slashCharCode ||
- nextChar === hashCharCode ||
- nextChar === queryCharCode
- ) {
- return undefined;
- }
- }
- return specifier.slice(0, i).toLowerCase();
- }
- function getProtocol(specifier) {
- const scheme = getScheme(specifier);
- return scheme === undefined ? undefined : scheme + ":";
- }
- exports.getScheme = getScheme;
- exports.getProtocol = getProtocol;
|