Skip to content

Commit

Permalink
Improve styleToObj
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeti-or committed Apr 18, 2017
1 parent 874f302 commit 008f7d2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ module.exports.defaultPlugins = [
if(~blackList.indexOf(k)) { return; }
if(k === 'attrs') {
bemjson[k]['style'] && (jsx.props['style'] = bemjson[k]['style']);
delete bemjson[k]['style'];
}

jsx.props[k] = bemjson[k];
});
},
function styleToObj(jsx) {
jsx.props['style'] && (jsx.props['style'] = styleObj(jsx.props['style']));
jsx.props['style'] &&
(jsx.props['attrs']['style'] = jsx.props['style'] = styleObj(jsx.props['style']));
}
];

Expand All @@ -37,11 +37,14 @@ module.exports.whiteList = function(options) {
};

function styleObj(style) {
return style.split(';').reduce((acc, st) => {
if (st.length) {
var prop = st.split(':');
acc[prop[0]] = prop[1];
}
return acc;
}, {});
if (typeof style === 'string') {
return style.split(';').reduce((acc, st) => {
if (st.length) {
var prop = st.split(':');
acc[prop[0]] = prop[1];
}
return acc;
}, {});
}
return style;
}

0 comments on commit 008f7d2

Please sign in to comment.