Created
August 17, 2016 03:54
-
-
Save alexsasharegan/ce3a8ba4cb95d7fb6d4e775edea17ca0 to your computer and use it in GitHub Desktop.
Get an inline style string by passing in a hash of camelCased style attributes.
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
//es5 | |
function mapObjStyleAttrs(obj) { | |
return Object.keys(obj) | |
.map(function (key) { | |
return [key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(), obj[key]] | |
.join(':'); | |
}) | |
.join(';'); | |
} | |
//es6 | |
const mapObjStyleAttrs = (obj) => Object.keys(obj).map((key) => [key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(), obj[key]].join(':')).join(';'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment