1 |
|
2 |
|
3 | const FLEX_REGEXP = [
|
4 | { key: 'flex', regexp: /\d+/ },
|
5 | { key: 'flexDirection', regexp: /(row(?!-)|row-reverse|column(?!-)|column-reverse)/ },
|
6 | { key: 'flexWrap', regexp: /(wrap|nowrap)/ },
|
7 | { key: 'justifyContent', regexp: /(flex-start|flex-end|center|space-between|space-around)/ },
|
8 | { key: 'alignItems', regexp: /(flex-start|flex-end|center|stretch)/ },
|
9 | { key: 'alignSelf', regexp: /(auto|flex-start|flex-end|center|stretch)/ },
|
10 | ];
|
11 | export default function getFlexStr(flexStr) {
|
12 | let flexStr$ = flexStr.toString();
|
13 | const flex = {};
|
14 | for (let i = 0; i < FLEX_REGEXP.length; i += 1) {
|
15 | const prop = FLEX_REGEXP[i];
|
16 | if (prop.regexp.test(flexStr$)) {
|
17 | flexStr$ = flexStr$.replace(prop.regexp, (match) => {
|
18 | flex[prop.key] = prop.key === 'flex' ? +match : match;
|
19 | return null;
|
20 | });
|
21 | }
|
22 | }
|
23 | return flex;
|
24 | }
|
25 |
|
\ | No newline at end of file |