source: trip-planner-front/node_modules/webpack/lib/util/URLAbsoluteSpecifier.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[6a3a178]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Ivan Kopeykin @vankop
4*/
5
6"use strict";
7
8/** @typedef {import("./fs").InputFileSystem} InputFileSystem */
9/** @typedef {(error: Error|null, result?: Buffer) => void} ErrorFirstCallback */
10
11const backSlashCharCode = "\\".charCodeAt(0);
12const slashCharCode = "/".charCodeAt(0);
13const aLowerCaseCharCode = "a".charCodeAt(0);
14const zLowerCaseCharCode = "z".charCodeAt(0);
15const aUpperCaseCharCode = "A".charCodeAt(0);
16const zUpperCaseCharCode = "Z".charCodeAt(0);
17const _0CharCode = "0".charCodeAt(0);
18const _9CharCode = "9".charCodeAt(0);
19const plusCharCode = "+".charCodeAt(0);
20const hyphenCharCode = "-".charCodeAt(0);
21const colonCharCode = ":".charCodeAt(0);
22const hashCharCode = "#".charCodeAt(0);
23const queryCharCode = "?".charCodeAt(0);
24/**
25 * Get scheme if specifier is an absolute URL specifier
26 * e.g. Absolute specifiers like 'file:///user/webpack/index.js'
27 * https://tools.ietf.org/html/rfc3986#section-3.1
28 * @param {string} specifier specifier
29 * @returns {string|undefined} scheme if absolute URL specifier provided
30 */
31function getScheme(specifier) {
32 const start = specifier.charCodeAt(0);
33
34 // First char maybe only a letter
35 if (
36 (start < aLowerCaseCharCode || start > zLowerCaseCharCode) &&
37 (start < aUpperCaseCharCode || start > zUpperCaseCharCode)
38 ) {
39 return undefined;
40 }
41
42 let i = 1;
43 let ch = specifier.charCodeAt(i);
44
45 while (
46 (ch >= aLowerCaseCharCode && ch <= zLowerCaseCharCode) ||
47 (ch >= aUpperCaseCharCode && ch <= zUpperCaseCharCode) ||
48 (ch >= _0CharCode && ch <= _9CharCode) ||
49 ch === plusCharCode ||
50 ch === hyphenCharCode
51 ) {
52 if (++i === specifier.length) return undefined;
53 ch = specifier.charCodeAt(i);
54 }
55
56 // Scheme must end with colon
57 if (ch !== colonCharCode) return undefined;
58
59 // Check for Windows absolute path
60 // https://url.spec.whatwg.org/#url-miscellaneous
61 if (i === 1) {
62 const nextChar = i + 1 < specifier.length ? specifier.charCodeAt(i + 1) : 0;
63 if (
64 nextChar === 0 ||
65 nextChar === backSlashCharCode ||
66 nextChar === slashCharCode ||
67 nextChar === hashCharCode ||
68 nextChar === queryCharCode
69 ) {
70 return undefined;
71 }
72 }
73
74 return specifier.slice(0, i).toLowerCase();
75}
76
77/**
78 * @param {string} specifier specifier
79 * @returns {string|null} protocol if absolute URL specifier provided
80 */
81function getProtocol(specifier) {
82 const scheme = getScheme(specifier);
83 return scheme === undefined ? undefined : scheme + ":";
84}
85
86exports.getScheme = getScheme;
87exports.getProtocol = getProtocol;
Note: See TracBrowser for help on using the repository browser.