function rgb2hex(sRGB) { const rgb=sRGB.match(/\d+/g) if(!rgb||rgb.length!=3){ return sRGB } let res='#' rgb.forEach((el)=>{ const p= parseInt(el).toString(16,2) res+=p.length==2?p:'0'+p }) return res }