File tree Expand file tree Collapse file tree 2 files changed +30
-10
lines changed Expand file tree Collapse file tree 2 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,4 @@ var parse = require('css-parse')
9
9
, read = fs . readFileSync
10
10
, css = read ( 'examples/dialog.css' , 'utf8' ) ;
11
11
12
- console . log ( stringify ( parse ( css ) ) ) ;
12
+ console . log ( stringify ( parse ( css ) , { compress : true } ) ) ;
Original file line number Diff line number Diff line change 1
1
2
- module . exports = function ( node ) {
3
- return node . stylesheet . rules . map ( rule ) . join ( '\n\n' ) ;
2
+ module . exports = function ( node , options ) {
3
+ options = options || { } ;
4
+ return node . stylesheet . rules . map ( rule ( options ) ) . join ( '\n\n' ) ;
4
5
} ;
5
6
6
- function rule ( rule ) {
7
- return rule . selector
8
- + ' {\n'
9
- + rule . declarations . map ( declaration ) . join ( '\n' )
10
- + '\n}' ;
7
+ function rule ( options ) {
8
+ if ( options . compress ) {
9
+ return function ( rule ) {
10
+ return rule . selector
11
+ + '{'
12
+ + rule . declarations . map ( declaration ( options ) ) . join ( ';' )
13
+ + '}' ;
14
+ }
15
+ }
16
+
17
+ return function ( rule ) {
18
+ return rule . selector
19
+ + ' {\n'
20
+ + rule . declarations . map ( declaration ( options ) ) . join ( '\n' )
21
+ + '\n}' ;
22
+ }
11
23
}
12
24
13
- function declaration ( decl ) {
14
- return ' ' + decl . property + ': ' + decl . value + ';' ;
25
+ function declaration ( options ) {
26
+ if ( options . compress ) {
27
+ return function ( decl ) {
28
+ return decl . property + ':' + decl . value ;
29
+ }
30
+ }
31
+
32
+ return function ( decl ) {
33
+ return ' ' + decl . property + ': ' + decl . value + ';' ;
34
+ }
15
35
}
You can’t perform that action at this time.
0 commit comments