UNPKG

@fluent-windows/core

Version:

React components that inspired by Microsoft's Fluent Design System.

6 lines 425 B
// Learn from https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb export const rgbToHex = (r, g, b) => '#' + [r, g, b].map(x => { const hex = x.toString(16); return hex.length === 1 ? '0' + hex : hex; }).join(''); export const hexToRgb = hex => hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_, r, g, b) => '#' + r + r + g + g + b + b).substring(1).match(/.{2}/g).map(x => parseInt(x, 16)).join(', ');