@@ -168,7 +168,7 @@ module.exports = function(css, options){
168168 function selector ( ) {
169169 var m = match ( / ^ ( [ ^ { ] + ) / ) ;
170170 if ( ! m ) return ;
171- return m [ 0 ] . replace ( / ^ \s + | \s + $ / g , '' ) . split ( / \s * , \s * / ) ;
171+ return trim ( m [ 0 ] ) . split ( / \s * , \s * / ) ;
172172 }
173173
174174 /**
@@ -181,7 +181,7 @@ module.exports = function(css, options){
181181 // prop
182182 var prop = match ( / ^ ( \* ? [ - \/ \* \w ] + ) \s * / ) ;
183183 if ( ! prop ) return ;
184- prop = prop [ 0 ] . replace ( / ^ \s + | \s + $ / g , '' ) ;
184+ prop = trim ( prop [ 0 ] ) ;
185185
186186 // :
187187 if ( ! match ( / ^ : \s * / ) ) return error ( "property missing ':'" ) ;
@@ -193,7 +193,7 @@ module.exports = function(css, options){
193193 var ret = pos ( {
194194 type : 'declaration' ,
195195 property : prop ,
196- value : val [ 0 ] . replace ( / ^ \s + | \s + $ / g , '' )
196+ value : trim ( val [ 0 ] )
197197 } ) ;
198198
199199 // ;
@@ -290,7 +290,7 @@ module.exports = function(css, options){
290290 var m = match ( / ^ @ s u p p o r t s * ( [ ^ { ] + ) / ) ;
291291
292292 if ( ! m ) return ;
293- var supports = m [ 1 ] . replace ( / ^ \s + | \s + $ / g , '' ) ;
293+ var supports = trim ( m [ 1 ] ) ;
294294
295295 if ( ! open ( ) ) return error ( "@supports missing '{'" ) ;
296296
@@ -314,7 +314,7 @@ module.exports = function(css, options){
314314 var m = match ( / ^ @ m e d i a * ( [ ^ { ] + ) / ) ;
315315
316316 if ( ! m ) return ;
317- var media = m [ 1 ] . replace ( / ^ \s + | \s + $ / g , '' ) ;
317+ var media = trim ( m [ 1 ] ) ;
318318
319319 if ( ! open ( ) ) return error ( "@media missing '{'" ) ;
320320
@@ -368,8 +368,8 @@ module.exports = function(css, options){
368368 var m = match ( / ^ @ ( [ - \w ] + ) ? d o c u m e n t * ( [ ^ { ] + ) / ) ;
369369 if ( ! m ) return ;
370370
371- var vendor = ( m [ 1 ] || '' ) . replace ( / ^ \s + | \s + $ / g , '' ) ;
372- var doc = m [ 2 ] . replace ( / ^ \s + | \s + $ / g , '' ) ;
371+ var vendor = trim ( m [ 1 ] ) ;
372+ var doc = trim ( m [ 2 ] ) ;
373373
374374 if ( ! open ( ) ) return error ( "@document missing '{'" ) ;
375375
@@ -418,7 +418,7 @@ module.exports = function(css, options){
418418 var m = match ( new RegExp ( '^@' + name + ' *([^;\\n]+);' ) ) ;
419419 if ( ! m ) return ;
420420 var ret = { type : name } ;
421- ret [ name ] = m [ 1 ] . replace ( / ^ \s + | \s + $ / g , '' ) ;
421+ ret [ name ] = trim ( m [ 1 ] ) ;
422422 return pos ( ret ) ;
423423 }
424424
@@ -458,3 +458,10 @@ module.exports = function(css, options){
458458 return stylesheet ( ) ;
459459} ;
460460
461+ /**
462+ * Trim `str`.
463+ */
464+
465+ function trim ( str ) {
466+ return ( str || '' ) . replace ( / ^ \s + | \s + $ / g, '' ) ;
467+ }
0 commit comments