Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
817 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | module.exports = function (url, options) {
|
---|
| 4 | if (!options) {
|
---|
| 5 | // eslint-disable-next-line no-param-reassign
|
---|
| 6 | options = {};
|
---|
| 7 | }
|
---|
| 8 |
|
---|
| 9 | if (!url) {
|
---|
| 10 | return url;
|
---|
| 11 | } // eslint-disable-next-line no-underscore-dangle, no-param-reassign
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | url = String(url.__esModule ? url.default : url); // If url is already wrapped in quotes, remove them
|
---|
| 15 |
|
---|
| 16 | if (/^['"].*['"]$/.test(url)) {
|
---|
| 17 | // eslint-disable-next-line no-param-reassign
|
---|
| 18 | url = url.slice(1, -1);
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | if (options.hash) {
|
---|
| 22 | // eslint-disable-next-line no-param-reassign
|
---|
| 23 | url += options.hash;
|
---|
| 24 | } // Should url be wrapped?
|
---|
| 25 | // See https://drafts.csswg.org/css-values-3/#urls
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) {
|
---|
| 29 | return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, "\\n"), "\"");
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | return url;
|
---|
| 33 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.