Skip to content

Instantly share code, notes, and snippets.

@jm2242
Created February 20, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jm2242/1e9db4d65242ec33094cf55b4aeb699c to your computer and use it in GitHub Desktop.
Save jm2242/1e9db4d65242ec33094cf55b4aeb699c to your computer and use it in GitHub Desktop.
Encode Styles object
/**
* 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