File tree 2 files changed +23
-3
lines changed 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,20 @@ const transforms = require('./transforms');
5
5
const TokenStream = require ( './TokenStream' ) ;
6
6
7
7
// Note if this is wrong, you'll need to change tokenTypes.js too
8
- const numberOrLengthRe = / ^ ( [ + - ] ? (?: \d * \. ) ? \d + (?: [ E e ] [ + - ] ? \d + ) ? ) (?: p x ) ? $ / ;
8
+ const numberOrLengthRe = / ^ ( [ + - ] ? (?: \d * \. ) ? \d + (?: [ E e ] [ + - ] ? \d + ) ? ) (?: p x ) ? $ / i;
9
+ const boolRe = / ^ t r u e | f a l s e $ / i;
9
10
10
11
// Undocumented export
11
12
export const transformRawValue = ( input ) => {
12
- const value = input . trim ( ) . match ( numberOrLengthRe ) ;
13
- return value ? Number ( value [ 1 ] ) : input ;
13
+ const value = input . trim ( ) ;
14
+
15
+ const numberMatch = value . match ( numberOrLengthRe ) ;
16
+ if ( numberMatch ) return Number ( numberMatch [ 1 ] ) ;
17
+
18
+ const boolMatch = input . match ( boolRe ) ;
19
+ if ( boolMatch ) return boolMatch [ 0 ] . toLowerCase ( ) === 'true' ;
20
+
21
+ return value ;
14
22
} ;
15
23
16
24
const baseTransformShorthandValue = ( propName , inputValue ) => {
Original file line number Diff line number Diff line change @@ -17,6 +17,18 @@ it('allows pixels in unspecialized transform', () => runTest([
17
17
[ 'top' , '0px' ] ,
18
18
] , { top : 0 } ) ) ;
19
19
20
+ it ( 'allows boolean values values' , ( ) => runTest ( [
21
+ [ 'boolTrue1' , 'true' ] ,
22
+ [ 'boolTrue2' , 'TRUE' ] ,
23
+ [ 'boolFalse1' , 'false' ] ,
24
+ [ 'boolFalse2' , 'FALSE' ] ,
25
+ ] , {
26
+ boolTrue1 : true ,
27
+ boolTrue2 : true ,
28
+ boolFalse1 : false ,
29
+ boolFalse2 : false ,
30
+ } ) ) ;
31
+
20
32
it ( 'allows percent in unspecialized transform' , ( ) => runTest ( [
21
33
[ 'top' , '0%' ] ,
22
34
] , { top : '0%' } ) ) ;
You can’t perform that action at this time.
0 commit comments