source: imaps-frontend/node_modules/clean-css/lib/optimizer/level-1/value-optimizers/whitespace.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.5 KB
Line 
1var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
2
3var Marker = require('../../../tokenizer/marker');
4
5var CALC_DIVISION_WHITESPACE_PATTERN = /\) ?\/ ?/g;
6var COMMA_AND_SPACE_PATTERN = /, /g;
7var LINE_BREAK_PATTERN = /\r?\n/g;
8var MULTI_WHITESPACE_PATTERN = /\s+/g;
9var FUNCTION_CLOSING_BRACE_WHITESPACE_PATTERN = /\s+(;?\))/g;
10var FUNCTION_OPENING_BRACE_WHITESPACE_PATTERN = /(\(;?)\s+/g;
11var VARIABLE_NAME_PATTERN = /^--\S+$/;
12var VARIABLE_VALUE_PATTERN = /^var\(\s*--\S+\s*\)$/;
13
14var plugin = {
15 level1: {
16 value: function whitespace(name, value, options) {
17 if (!options.level[OptimizationLevel.One].removeWhitespace) {
18 return value;
19 }
20
21 if (VARIABLE_NAME_PATTERN.test(name) && !VARIABLE_VALUE_PATTERN.test(value)) {
22 return value;
23 }
24
25 if ((value.indexOf(' ') == -1 && value.indexOf('\n') == -1) || value.indexOf('expression') === 0) {
26 return value;
27 }
28
29 if (value.indexOf(Marker.SINGLE_QUOTE) > -1 || value.indexOf(Marker.DOUBLE_QUOTE) > -1) {
30 return value;
31 }
32
33 value = value.replace(LINE_BREAK_PATTERN, '');
34 value = value.replace(MULTI_WHITESPACE_PATTERN, ' ');
35
36 if (value.indexOf('calc') > -1) {
37 value = value.replace(CALC_DIVISION_WHITESPACE_PATTERN, ')/ ');
38 }
39
40 return value
41 .replace(FUNCTION_OPENING_BRACE_WHITESPACE_PATTERN, '$1')
42 .replace(FUNCTION_CLOSING_BRACE_WHITESPACE_PATTERN, '$1')
43 .replace(COMMA_AND_SPACE_PATTERN, ',');
44 }
45 }
46};
47
48module.exports = plugin;
Note: See TracBrowser for help on using the repository browser.