UNPKG

832 BJavaScriptView Raw
1var postcss = require('postcss');
2
3module.exports = function(decl) {
4 var regex = /(\d{1,}) (\d{1,}) (calc\(.*?\))/g;
5 var matches = regex.exec(decl.value);
6 if (decl.prop === 'flex' && matches) {
7 var grow = postcss.decl({
8 prop: 'flex-grow',
9 value: matches[1],
10 source: decl.source
11 });
12 var shrink = postcss.decl({
13 prop: 'flex-shrink',
14 value: matches[2],
15 source: decl.source
16 });
17 var basis = postcss.decl({
18 prop: 'flex-basis',
19 value: matches[3],
20 source: decl.source
21 });
22 decl.parent.insertBefore(decl, grow);
23 decl.parent.insertBefore(decl, shrink);
24 decl.parent.insertBefore(decl, basis);
25 decl.remove();
26 }
27};