UNPKG

598 BJavaScriptView Raw
1"use strict";
2
3module.exports = function (url, options) {
4 if (!options) {
5 options = {};
6 }
7
8 if (!url) {
9 return url;
10 }
11
12 url = String(url.__esModule ? url.default : url); // If url is already wrapped in quotes, remove them
13
14 if (/^['"].*['"]$/.test(url)) {
15 url = url.slice(1, -1);
16 }
17
18 if (options.hash) {
19 url += options.hash;
20 } // Should url be wrapped?
21 // See https://drafts.csswg.org/css-values-3/#urls
22
23
24 if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) {
25 return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, "\\n"), "\"");
26 }
27
28 return url;
29};
\No newline at end of file