module.exports = function RGBToHex(data) {
return {
process: function() {
- return data.replace(/rgb\((\d+),(\d+),(\d+)\)/g, function(match, red, green, blue) {
+ return data.replace(/rgb\((\-?\d+),(\-?\d+),(\-?\d+)\)/g, function(match, red, green, blue) {
+ red = Math.max(0, Math.min(~~red, 255));
+ green = Math.max(0, Math.min(~~green, 255));
+ blue = Math.max(0, Math.min(~~blue, 255));
+
// Credit: Asen http://jsbin.com/UPUmaGOc/2/edit?js,console
return '#' + ('00000' + (red << 16 | green << 8 | blue).toString(16)).slice(-6);
});
'hsl out of bounds #7': [
'a{color:hsl(0,0%,-10%)}',
'a{color:#000}'
+ ],
+ 'rgb out of a lower bound': [
+ 'a{color:rgb(-1,-1,-1)}',
+ 'a{color:#000}'
+ ],
+ 'rgb out of an upper bound': [
+ 'a{color:rgb(256,256,256)}',
+ 'a{color:#fff}'
]
}),
'shortening colors': colorShorteningContext(),