UNPKG

1.12 kBJavaScriptView Raw
1// why not Object, See Here http://t.cn/RKQqS4n
2// !! justifyContent alignItems alignSelf 一定要照这个顺序来!,且前面的不能省略
3const 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];
11export 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; // no use but fixed [ts] error
20 });
21 }
22 }
23 return flex;
24}
25//# sourceMappingURL=util.js.map
\No newline at end of file