@@ -10,7 +10,8 @@ const defaults = {
1010 replace : true ,
1111 mediaQuery : false ,
1212 minPixelValue : 0 ,
13- exclude : null
13+ exclude : null ,
14+ unit : "px" ,
1415} ;
1516
1617const legacyOptions = {
@@ -19,7 +20,7 @@ const legacyOptions = {
1920 selector_black_list : "selectorBlackList" ,
2021 prop_white_list : "propList" ,
2122 media_query : "mediaQuery" ,
22- propWhiteList : "propList"
23+ propWhiteList : "propList" ,
2324} ;
2425
2526function convertLegacyOptions ( options ) {
@@ -35,7 +36,7 @@ function convertLegacyOptions(options) {
3536 delete options [ "prop_white_list" ] ;
3637 delete options . propWhiteList ;
3738 }
38- Object . keys ( legacyOptions ) . forEach ( key => {
39+ Object . keys ( legacyOptions ) . forEach ( ( key ) => {
3940 if ( Reflect . has ( options , key ) ) {
4041 options [ legacyOptions [ key ] ] = options [ key ] ;
4142 delete options [ key ] ;
@@ -60,12 +61,12 @@ function toFixed(number, precision) {
6061}
6162
6263function declarationExists ( decls , prop , value ) {
63- return decls . some ( decl => decl . prop === prop && decl . value === value ) ;
64+ return decls . some ( ( decl ) => decl . prop === prop && decl . value === value ) ;
6465}
6566
6667function blacklistedSelector ( blacklist , selector ) {
6768 if ( typeof selector !== "string" ) return ;
68- return blacklist . some ( regex => {
69+ return blacklist . some ( ( regex ) => {
6970 if ( typeof regex === "string" ) {
7071 return selector . indexOf ( regex ) !== - 1 ;
7172 }
@@ -84,31 +85,31 @@ function createPropListMatcher(propList) {
8485 notExact : filterPropList . notExact ( propList ) ,
8586 notContain : filterPropList . notContain ( propList ) ,
8687 notStartWith : filterPropList . notStartWith ( propList ) ,
87- notEndWith : filterPropList . notEndWith ( propList )
88+ notEndWith : filterPropList . notEndWith ( propList ) ,
8889 } ;
89- return prop => {
90+ return ( prop ) => {
9091 if ( matchAll ) return true ;
9192 return (
9293 ( hasWild ||
9394 lists . exact . indexOf ( prop ) > - 1 ||
94- lists . contain . some ( function ( m ) {
95+ lists . contain . some ( function ( m ) {
9596 return prop . indexOf ( m ) > - 1 ;
9697 } ) ||
97- lists . startWith . some ( function ( m ) {
98+ lists . startWith . some ( function ( m ) {
9899 return prop . indexOf ( m ) === 0 ;
99100 } ) ||
100- lists . endWith . some ( function ( m ) {
101+ lists . endWith . some ( function ( m ) {
101102 return prop . indexOf ( m ) === prop . length - m . length ;
102103 } ) ) &&
103104 ! (
104105 lists . notExact . indexOf ( prop ) > - 1 ||
105- lists . notContain . some ( function ( m ) {
106+ lists . notContain . some ( function ( m ) {
106107 return prop . indexOf ( m ) > - 1 ;
107108 } ) ||
108- lists . notStartWith . some ( function ( m ) {
109+ lists . notStartWith . some ( function ( m ) {
109110 return prop . indexOf ( m ) === 0 ;
110111 } ) ||
111- lists . notEndWith . some ( function ( m ) {
112+ lists . notEndWith . some ( function ( m ) {
112113 return prop . indexOf ( m ) === prop . length - m . length ;
113114 } )
114115 )
@@ -145,20 +146,20 @@ module.exports = (options = {}) => {
145146 pxReplace = createPxReplace (
146147 rootValue ,
147148 opts . unitPrecision ,
148- opts . minPixelValue
149+ opts . minPixelValue ,
149150 ) ;
150151 } ,
151152 Declaration ( decl ) {
152153 if ( isExcludeFile ) return ;
153154
154155 if (
155- decl . value . indexOf ( "px" ) === - 1 ||
156+ decl . value . indexOf ( opts . unit ) === - 1 ||
156157 ! satisfyPropList ( decl . prop ) ||
157158 blacklistedSelector ( opts . selectorBlackList , decl . parent . selector )
158159 )
159160 return ;
160161
161- const value = decl . value . replace ( pxRegex , pxReplace ) ;
162+ const value = decl . value . replace ( pxRegex ( opts . unit ) , pxReplace ) ;
162163
163164 // if rem unit already exists, do not add or replace
164165 if ( declarationExists ( decl . parent , decl . prop , value ) ) return ;
@@ -173,10 +174,10 @@ module.exports = (options = {}) => {
173174 if ( isExcludeFile ) return ;
174175
175176 if ( opts . mediaQuery && atRule . name === "media" ) {
176- if ( atRule . params . indexOf ( "px" ) === - 1 ) return ;
177- atRule . params = atRule . params . replace ( pxRegex , pxReplace ) ;
177+ if ( atRule . params . indexOf ( opts . unit ) === - 1 ) return ;
178+ atRule . params = atRule . params . replace ( pxRegex ( opts . unit ) , pxReplace ) ;
178179 }
179- }
180+ } ,
180181 } ;
181182} ;
182183module . exports . postcss = true ;
0 commit comments