JSFiddle - React, Tailwind, and code Playground

by lid0

JavaScript

function rgb_color(r,g,b){
 this.r = r;
 this.g = g;
 this.b = b;
 this.arr = [r,g,b];
 this.min = Math.min.apply(null,this.arr);
 this.max = Math.max.apply(null,this.arr);
 this.light = (this.max/255 + this.min/255)/2;
}


function hex_to_rgb(str){
    var m = str.match(/#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})/);
    var rgb = new rgb_color( parseInt(m[1],16),parseInt(m[2],16),parseInt(m[3],16))
    console.log(m)
    console.log(rgb);
    
}

hex_to_rgb("#F0F0F0");
hex_to_rgb("#787878");
hex_to_rgb("#202020");