1 |
|
2 |
|
3 | const _camelCaseRegex = /([a-z])?([A-Z])/g;
|
4 |
|
5 | const _camelCaseReplacer = function(match, p1, p2) {
|
6 | return (p1 || '') + '-' + p2.toLowerCase();
|
7 | };
|
8 |
|
9 | const _camelCaseToDashCase = function(s) {
|
10 | return s.replace(_camelCaseRegex, _camelCaseReplacer);
|
11 | };
|
12 |
|
13 | const camelCasePropsToDashCase = function(prefixedStyle: Object): Object {
|
14 |
|
15 |
|
16 | return Object.keys(prefixedStyle).reduce(
|
17 | (result, key) => {
|
18 | let dashCaseKey = _camelCaseToDashCase(key);
|
19 |
|
20 |
|
21 | if (/^ms-/.test(dashCaseKey)) {
|
22 | dashCaseKey = `-${dashCaseKey}`;
|
23 | }
|
24 |
|
25 | result[dashCaseKey] = prefixedStyle[key];
|
26 | return result;
|
27 | },
|
28 | {},
|
29 | );
|
30 | };
|
31 |
|
32 | export default camelCasePropsToDashCase;
|