4 const hasLessInterpolation = require("../utils/hasLessInterpolation");
5 const hasPsvInterpolation = require("../utils/hasPsvInterpolation");
6 const hasScssInterpolation = require("../utils/hasScssInterpolation");
9 * Check whether a URL is standard
11 module.exports = function(url /*: string*/) /*: boolean*/ {
12 if (url.length === 0) {
16 // Sass interpolation works anywhere
17 if (hasScssInterpolation(url) || hasPsvInterpolation(url)) {
21 // Inside `'` and `"` work only LESS interpolation
23 (url[0] === "'" && url[url.length - 1] === "'") ||
24 (url[0] === '"' && url[url.length - 1] === '"')
26 if (hasLessInterpolation(url)) {
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)) {
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
44 url.indexOf("$") !== -1 &&
45 /^[$\sA-Za-z0-9+-/*_'"/]+$/.test(url) &&
46 url[url.length - 1] !== "/"