UNPKG

841 BJavaScriptView Raw
1/* @flow */
2
3const _camelCaseRegex = /([a-z])?([A-Z])/g;
4
5const _camelCaseReplacer = function(match, p1, p2) {
6 return (p1 || '') + '-' + p2.toLowerCase();
7};
8
9const _camelCaseToDashCase = function(s) {
10 return s.replace(_camelCaseRegex, _camelCaseReplacer);
11};
12
13const camelCasePropsToDashCase = function(prefixedStyle: Object): Object {
14 // Since prefix is expected to work on inline style objects, we must
15 // translate the keys to dash case for rendering to CSS.
16 return Object.keys(prefixedStyle).reduce(
17 (result, key) => {
18 let dashCaseKey = _camelCaseToDashCase(key);
19
20 // Fix IE vendor prefix
21 if (/^ms-/.test(dashCaseKey)) {
22 dashCaseKey = `-${dashCaseKey}`;
23 }
24
25 result[dashCaseKey] = prefixedStyle[key];
26 return result;
27 },
28 {},
29 );
30};
31
32export default camelCasePropsToDashCase;