forked from vault-development/react-native-svg-uri
-
Notifications
You must be signed in to change notification settings - Fork 17
/
utils.js
31 lines (27 loc) · 904 Bytes
/
utils.js
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
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));