RGB to hex and hex to RGB -javascript- Stack Overflow

PHOTO EMBED

Sun Nov 06 2022 08:21:10 GMT+0000 (Coordinated Universal Time)

Saved by @AZbrahim #javascript

const hexToRgb = hex =>
  hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i
             ,(m, r, g, b) => '#' + r + r + g + g + b + b)
    .substring(1).match(/.{2}/g)
    .map(x => parseInt(x, 16))

console.log(hexToRgb("#0033ff")) // [0, 51, 255]
console.log(hexToRgb("#03f")) // [0, 51, 255]
content_copyCOPY

https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb