Created
June 30, 2015 08:32
-
-
Save niksumeiko/f1853d62c042903e3835 to your computer and use it in GitHub Desktop.
Converts style object into the corresponding CSS `style` attribute value
This file contains hidden or 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
/** | |
* Takes a style object and returns the corresponding | |
* attribute value. Converts camel case property names | |
* to proper CSS selector names. | |
* @param {Object} obj Map of CSS properties to values. | |
* @return {string} The style attribute value. | |
*/ | |
function toStyleAttribute = function(obj) { | |
return Object.keys(obj).map(function(key) { | |
// Camel case property names to CSS selector names. | |
return (key.replace(/([A-Z])/g, '-$1').toLowerCase()) + | |
':' + obj[key]; | |
}).join(';'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment