2020-10-03 15:17:04 +03:00
|
|
|
function RGBToHex (r, g, b) {
|
|
|
|
|
if (
|
|
|
|
|
typeof r !== 'number' ||
|
|
|
|
|
typeof g !== 'number' ||
|
|
|
|
|
typeof b !== 'number'
|
|
|
|
|
) {
|
|
|
|
|
throw new TypeError('argument is not a Number')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toHex = n => (n || '0').toString(16).padStart(2, '0')
|
|
|
|
|
|
|
|
|
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-09 18:15:30 +02:00
|
|
|
export { RGBToHex }
|
|
|
|
|
|
|
|
|
|
// > RGBToHex(255, 255, 255)
|
|
|
|
|
// '#ffffff'
|
|
|
|
|
|
|
|
|
|
// > RGBToHex(255, 99, 71)
|
|
|
|
|
// '#ff6347'
|