Created
February 20, 2018 20:28
-
-
Save jm2242/1e9db4d65242ec33094cf55b4aeb699c to your computer and use it in GitHub Desktop.
Encode Styles object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Encode an object of styles for the browser to understand | |
* @param {Object} styles - styles to decode | |
* @returns {Object} - Something | |
*/ | |
export const encodeStyles = styles => { | |
const encodedStyles = {} | |
Object.entries(styles).forEach( | |
([key, value]) => { | |
// add the pixels back in if the value is a number | |
encodedStyles[key] = (typeof(value) === "number") ? `${value}px` : value | |
} | |
) | |
return encodedStyles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment