I need to edit a string from:
rgb(250, 0, 0) 10px 10px 50px 0px
to:
rgba(250, 0, 0, 1) 10px 10px 50px 0px
Assuming the input value is always correct, I need to add alpha channel of 1.
The follow script I created works, but I was wondering about the double replace.
I would like to know if you perform a better way, maybe using only one regex and avoiding using replace twice or a better alternative.
var _convertBoxShadowToTgba = function (boxShadow) {
return boxShadow.replace(/rgb/i, 'rgba').replace(/\)/i, ', 1)');
};
var original = "rgb(250, 0, 0) 10px 10px 50px 0px";
var final = _convertBoxShadowToTgba(original);
console.log('original', original);
console.log('final', final);