.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / isStandardSyntaxUrl.js
1 /* @flow */
2 "use strict";
3
4 const hasLessInterpolation = require("../utils/hasLessInterpolation");
5 const hasPsvInterpolation = require("../utils/hasPsvInterpolation");
6 const hasScssInterpolation = require("../utils/hasScssInterpolation");
7
8 /**
9  * Check whether a URL is standard
10  */
11 module.exports = function(url /*: string*/) /*: boolean*/ {
12   if (url.length === 0) {
13     return true;
14   }
15
16   // Sass interpolation works anywhere
17   if (hasScssInterpolation(url) || hasPsvInterpolation(url)) {
18     return false;
19   }
20
21   // Inside `'` and `"` work only LESS interpolation
22   if (
23     (url[0] === "'" && url[url.length - 1] === "'") ||
24     (url[0] === '"' && url[url.length - 1] === '"')
25   ) {
26     if (hasLessInterpolation(url)) {
27       return false;
28     }
29
30     return true;
31   }
32
33   // Less variable works only at the beginning
34   // Check is less variable, allow use '@url/some/path'
35   // https://github.com/less/less.js/blob/3.x/lib/less/parser/parser.js#L547
36   if (url[0] === "@" && /^@@?[\w-]+$/.test(url)) {
37     return false;
38   }
39
40   // In url without quotes scss variable can be everywhere
41   // But in this case it is allowed to use only specific characters
42   // Also forbidden "/" at the end of url
43   if (
44     url.indexOf("$") !== -1 &&
45     /^[$\sA-Za-z0-9+-/*_'"/]+$/.test(url) &&
46     url[url.length - 1] !== "/"
47   ) {
48     return false;
49   }
50
51   return true;
52 };