File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import postcss from 'postcss' ;
2
+
3
+ const METHOD = 'map-get' ;
4
+
5
+ const valResolve = value => {
6
+ const map = value . substring (
7
+ value . indexOf ( '((' ) + 2 ,
8
+ value . indexOf ( '),' )
9
+ )
10
+ . split ( ',' )
11
+ . reduce ( ( map , string ) => {
12
+ const [ key , value ] = string . split ( ':' ) ;
13
+ return Object . assign ( map , { [ key ] : value } )
14
+ } , { } ) ;
15
+
16
+ const key = value . substring (
17
+ value . indexOf ( '),' ) + 2 ,
18
+ value . lastIndexOf ( ')' )
19
+ ) ;
20
+
21
+ return map [ key ] ;
22
+ }
23
+
24
+ const normalize = value => value . replace ( / ( \s | ! d e f a u l t ) / g, '' ) ;
25
+
26
+ export default postcss . plugin ( 'postcss-map-get' , ( ) => {
27
+ return nodes => {
28
+ nodes . walkDecls ( decl => {
29
+ let { value} = decl ;
30
+
31
+ if ( value . startsWith ( METHOD ) ) {
32
+ decl . value = valResolve ( normalize ( decl . value ) ) ;
33
+ }
34
+ } ) ;
35
+ } ;
36
+ } ) ;
You can’t perform that action at this time.
0 commit comments