toStyle
toStyle copied to clipboard
toObject will fail for background property with url
var toObject = function(str){
str = (str || '').split(';')
var result = {}
str.forEach(function(item){
var split = item.split(':')
if (split.length == 2){
result[split[0].trim()] = split[1].trim()
}
})
return result
}
this would fail for "background: url('http://myurl.com/img.jpg') center / cover". It should parse everything following the ':' up until the next ';'.
I'm having this issue myself, but it can get quite trickier than just what @brokenalarms suggests!
Base 64 images will have serious parsing issues using the current approach:
background-image: url("data:image/jpeg;base64,dsdfsdfsdf");
As you can see, there is a ":" and a ";" inside the url, thus making this quite harder to split without proper balanced parsing.
Having said that, I wonder if adding a postcss dependency would be ok with the package owner, as we could use it to properly parse strings.