forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefixer.js
More file actions
40 lines (32 loc) · 869 Bytes
/
prefixer.js
File metadata and controls
40 lines (32 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const WEBKIT = 'Webkit';
const MICROSOFT = 'Ms';
const 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) {
const vendor = getPrefixes(property, value);
for (const prefix in vendor) {
style[prefix] = vendor[prefix];
}
return style;
}
function prefixer (style, defaultValue = {}) {
const _style = defaultValue;
for (const property in style) {
_style[property] = style[property];
if (properties[property]) {
addPrefixesTo(_style, property, style[property]);
}
}
return _style;
}
export default prefixer;