Last active
April 29, 2023 22:20
-
-
Save kistaaa/7ba71f3500bfc3bdcdaf44e0359ee11a to your computer and use it in GitHub Desktop.
Object and CSS conversion, for using on "style=" in html elements
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
// object to css | |
Object.prototype.css = function() {return Object.entries(this).map(([k, v]) => `${k}:${v}`).join(';')} | |
// css to object | |
String.prototype.obj = function() { | |
let obj = {} | |
let parts = this.split(";") | |
for(let part of parts){ | |
let prop = part.split(':') | |
obj[prop[0]] = prop[1] | |
} | |
return obj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment