source: trip-planner-front/node_modules/csso/lib/replace/Url.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1var UNICODE = '\\\\[0-9a-f]{1,6}(\\r\\n|[ \\n\\r\\t\\f])?';
2var ESCAPE = '(' + UNICODE + '|\\\\[^\\n\\r\\f0-9a-fA-F])';
3var NONPRINTABLE = '\u0000\u0008\u000b\u000e-\u001f\u007f';
4var SAFE_URL = new RegExp('^(' + ESCAPE + '|[^\"\'\\(\\)\\\\\\s' + NONPRINTABLE + '])*$', 'i');
5
6module.exports = function(node) {
7 var value = node.value;
8
9 if (value.type !== 'String') {
10 return;
11 }
12
13 var quote = value.value[0];
14 var url = value.value.substr(1, value.value.length - 2);
15
16 // convert `\\` to `/`
17 url = url.replace(/\\\\/g, '/');
18
19 // remove quotes when safe
20 // https://www.w3.org/TR/css-syntax-3/#url-unquoted-diagram
21 if (SAFE_URL.test(url)) {
22 node.value = {
23 type: 'Raw',
24 loc: node.value.loc,
25 value: url
26 };
27 } else {
28 // use double quotes if string has no double quotes
29 // otherwise use original quotes
30 // TODO: make better quote type selection
31 node.value.value = url.indexOf('"') === -1 ? '"' + url + '"' : quote + url + quote;
32 }
33};
Note: See TracBrowser for help on using the repository browser.