summaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/util/URLAbsoluteSpecifier.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-11-05 17:16:09 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-11-05 17:16:09 +0800
commitd1d9f00b1bd660842addf5e6b1d1b64c852a9eea (patch)
tree60fb37ae73a1109d95301de5ec9b61b5726a4b61 /node_modules/webpack/lib/util/URLAbsoluteSpecifier.js
parent7c85166c4cbdd862fc4252007d2df5befcbc2a58 (diff)
added hover prefixer
Diffstat (limited to 'node_modules/webpack/lib/util/URLAbsoluteSpecifier.js')
-rw-r--r--node_modules/webpack/lib/util/URLAbsoluteSpecifier.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/node_modules/webpack/lib/util/URLAbsoluteSpecifier.js b/node_modules/webpack/lib/util/URLAbsoluteSpecifier.js
new file mode 100644
index 00000000..164d37e4
--- /dev/null
+++ b/node_modules/webpack/lib/util/URLAbsoluteSpecifier.js
@@ -0,0 +1,87 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Ivan Kopeykin @vankop
+*/
+
+"use strict";
+
+/** @typedef {import("./fs").InputFileSystem} InputFileSystem */
+/** @typedef {(error: Error|null, result?: Buffer) => void} ErrorFirstCallback */
+
+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);
+/**
+ * Get scheme if specifier is an absolute URL specifier
+ * e.g. Absolute specifiers like 'file:///user/webpack/index.js'
+ * https://tools.ietf.org/html/rfc3986#section-3.1
+ * @param {string} specifier specifier
+ * @returns {string|undefined} scheme if absolute URL specifier provided
+ */
+function getScheme(specifier) {
+ const start = specifier.charCodeAt(0);
+
+ // First char maybe only a letter
+ 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);
+ }
+
+ // Scheme must end with colon
+ if (ch !== colonCharCode) return undefined;
+
+ // Check for Windows absolute path
+ // https://url.spec.whatwg.org/#url-miscellaneous
+ 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();
+}
+
+/**
+ * @param {string} specifier specifier
+ * @returns {string | null | undefined} protocol if absolute URL specifier provided
+ */
+function getProtocol(specifier) {
+ const scheme = getScheme(specifier);
+ return scheme === undefined ? undefined : scheme + ":";
+}
+
+exports.getScheme = getScheme;
+exports.getProtocol = getProtocol;