```bash
cleancss --O2 one.css
-cleancss --O2 mediaMerging:false;restructuring:false;semanticMerging:true;shorthandCompacting:false one.css
-# `mediaMerging` controls `@media` merging behavior; defaults to true
-# `restructuring` controls content restructuring behavior; defaults to true
-# `semanticMerging` controls semantic merging behavior; defaults to false
-# `shorthandCompacting` controls shorthand compacting behavior; defaults to true
+cleancss --O2 mediaMerging:off;restructuring:off;semanticMerging:on;shorthandCompacting:off one.css
+# `mediaMerging` controls `@media` merging behavior; defaults to `on` (alias to `true`)
+# `restructuring` controls content restructuring behavior; defaults `on` (alias to `true`)
+# `semanticMerging` controls semantic merging behavior; defaults to `off` (alias to `false`)
+# `shorthandCompacting` controls shorthand compacting behavior; defaults to `on` (alias to `true`)
```
### How to use clean-css API?
console.log('');
console.log(' Level 2 optimizations:');
console.log(' %> cleancss --O2 one.css');
- console.log(' %> cleancss --O2 mediaMerging:false;restructuring:false;semanticMerging:true;shorthandCompacting:false one.css');
- console.log(' %> # `mediaMerging` controls `@media` merging behavior; defaults to true');
- console.log(' %> # `restructuring` controls content restructuring behavior; defaults to true');
- console.log(' %> # `semanticMerging` controls semantic merging behavior; defaults to false');
- console.log(' %> # `shorthandCompacting` controls shorthand compacting behavior; defaults to true');
+ console.log(' %> cleancss --O2 mediaMerging:off;restructuring:off;semanticMerging:on;shorthandCompacting:off one.css');
+ console.log(' %> # `mediaMerging` controls `@media` merging behavior; defaults to `on` (alias to `true`)');
+ console.log(' %> # `restructuring` controls content restructuring behavior; defaults to `on` (alias to `true`)');
+ console.log(' %> # `semanticMerging` controls semantic merging behavior; defaults to `off` (alias to `false`)');
+ console.log(' %> # `shorthandCompacting` controls shorthand compacting behavior; defaults to `on` (alias to `true`)');
process.exit();
});
var ALL_KEYWORD_1 = '*';
var ALL_KEYWORD_2 = 'all';
+var FALSE_KEYWORD_1 = 'false';
+var FALSE_KEYWORD_2 = 'off';
+var TRUE_KEYWORD_1 = 'true';
+var TRUE_KEYWORD_2 = 'on';
+
var OPTION_SEPARATOR = ';';
var OPTION_VALUE_SEPARATOR = ':';
function normalizeValue(value) {
switch (value) {
- case 'false':
+ case FALSE_KEYWORD_1:
+ case FALSE_KEYWORD_2:
return false;
- case 'true':
+ case TRUE_KEYWORD_1:
+ case TRUE_KEYWORD_2:
return true;
default:
return value;
})
})
.addBatch({
- 'skip restructuring optimizations': pipedContext('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}', '--O2 restructuring:false', {
+ 'skip restructuring optimizations': pipedContext('div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}', '--O2 restructuring:off', {
'should do basic optimizations only': function (error, stdout) {
assert.equal(stdout, 'div{margin-top:0}.one{margin:0}.two{display:block;margin-top:0}');
}
}
})
.addBatch({
- '@media merging': pipedContext('@media screen{a{color:red}}@media screen{a{display:block}}', '--O2 mediaMerging:false', {
+ '@media merging': pipedContext('@media screen{a{color:red}}@media screen{a{display:block}}', '--O2 mediaMerging:off', {
'gets right result': function (error, stdout) {
assert.equal(stdout, '@media screen{a{color:red}}@media screen{a{display:block}}');
}
})
.addBatch({
'shorthand compacting': {
- 'of (yet) unmergeable properties': pipedContext('a{background:url(image.png);background-color:red}', '--O2 shorthandCompacting:false', {
+ 'of (yet) unmergeable properties': pipedContext('a{background:url(image.png);background-color:red}', '--O2 shorthandCompacting:off', {
'gets right result': function (error, stdout) {
assert.equal(stdout, 'a{background:url(image.png);background-color:red}');
}
assert.equal(stdout, '.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}');
}
}),
- 'enabled': pipedContext('.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}', '--O2 semanticMerging:true', {
+ 'enabled': pipedContext('.a{margin:0}.b{margin:10px;padding:0}.c{margin:0}', '--O2 semanticMerging:on', {
'should output right data': function (error, stdout) {
assert.equal(stdout, '.a,.c{margin:0}.b{margin:10px;padding:0}');
}
});
}
},
+ 'a hash with options as strings with boolean values as on/off': {
+ 'topic': function () {
+ return optimizationLevelFrom({ 2: 'mediaMerging:off;semanticMerging:on' });
+ },
+ 'has all options': function (levelOptions) {
+ assert.deepEqual(Object.keys(levelOptions), ['0', '1', '2']);
+ },
+ 'has level 0 options': function (levelOptions) {
+ assert.deepEqual(levelOptions['0'], {});
+ },
+ 'has level 1 options': function (levelOptions) {
+ assert.deepEqual(levelOptions['1'], {
+ roundingPrecision: roundingPrecisionFrom(undefined),
+ specialComments: 'all'
+ });
+ },
+ 'has level 2 options': function (levelOptions) {
+ assert.deepEqual(levelOptions['2'], {
+ mediaMerging: false,
+ restructuring: true,
+ semanticMerging: true,
+ shorthandCompacting: true
+ });
+ }
+ },
'a hash with options as strings with all keyword': {
'topic': function () {
return optimizationLevelFrom({ 2: 'all:false;mediaMerging:true;semanticMerging:true' });