forked from chaitanyadeorukhkar/react-native-svg-uri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
21 lines (17 loc) · 869 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export const camelCase = value => value.replace(/-([a-z])/g, g => g[1].toUpperCase());
export const camelCaseNodeName = ({nodeName, nodeValue}) => ({nodeName: camelCase(nodeName), nodeValue});
export const removePixelsFromNodeValue = ({nodeName, nodeValue}) => ({nodeName, nodeValue: nodeValue.replace('px', '')});
export const transformStyle = ({nodeName, nodeValue, fillProp}) => {
if (nodeName === 'style') {
return nodeValue.split(';')
.reduce((acc, attribute) => {
const [property, value] = attribute.split(':');
if (property == "")
return acc;
else
return {...acc, [camelCase(property)]: fillProp && property === 'fill' ? fillProp : value};
}, {});
}
return null;
};
export const getEnabledAttributes = enabledAttributes => ({nodeName}) => enabledAttributes.includes(camelCase(nodeName));