react-toolbox
Version:
A set of complementary tools to ReactJS.
42 lines (33 loc) • 838 B
JavaScript
;
var WEBKIT = 'Webkit';
var MICROSOFT = 'Ms';
var properties = {
transform: [WEBKIT, MICROSOFT]
};
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.substr(1);
}
function getPrefixes(property, value) {
return properties[property].reduce(function (acc, item) {
acc['' + item + capitalize(property)] = value;
return acc;
}, {});
}
function addPrefixesTo(style, property, value) {
var vendor = getPrefixes(property, value);
for (var prefix in vendor) {
style[prefix] = vendor[prefix];
}
return style;
}
function prefixer(style) {
var _style = {};
for (var property in style) {
_style[property] = style[property];
if (properties[property]) {
addPrefixesTo(_style, property, style[property]);
}
}
return _style;
}
module.exports = prefixer;