Skip to content

Commit c21e9db

Browse files
committed
Allow boolean values in CSS (fixes styled-components#26)
1 parent ac4ee18 commit c21e9db

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ const transforms = require('./transforms');
55
const TokenStream = require('./TokenStream');
66

77
// Note if this is wrong, you'll need to change tokenTypes.js too
8-
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/;
8+
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i;
9+
const boolRe = /^true|false$/i;
910

1011
// Undocumented export
1112
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;
1422
};
1523

1624
export const getStylesForProperty = (propName, inputValue, allowShorthand) => {

0 commit comments

Comments
 (0)