.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / getSchemeFromUrl.js
1 /* @flow */
2 "use strict";
3
4 const parse = require("url").parse;
5
6 /**
7  * Get unit from value node
8  *
9  * Returns `null` if the unit is not found.
10  */
11 module.exports = function(urlString /*: string*/) /*: ?string*/ {
12   const url = parse(urlString);
13   const protocol = url.protocol;
14   if (protocol === null || typeof protocol === "undefined") {
15     return null;
16   }
17
18   const scheme = protocol.slice(0, -1); // strip trailing `:`
19
20   // The URL spec does not require a scheme to be followed by `//`, but checking
21   // for it allows this rule to differentiate <scheme>:<hostname> urls from
22   // <hostname>:<port> urls. `data:` scheme urls are an exception to this rule.
23   const slashIndex = protocol.length;
24   const expectedSlashes = urlString.slice(slashIndex, slashIndex + 2);
25   const isSchemeLessUrl = expectedSlashes !== "//" && scheme !== "data";
26
27   if (isSchemeLessUrl) {
28     return null;
29   }
30
31   return scheme;
32 };