@fluent-windows/core
Version:
React components that inspired by Microsoft's Fluent Design System.
26 lines (21 loc) • 715 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hexToRgb = exports.rgbToHex = void 0;
// Learn from https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
var rgbToHex = function rgbToHex(r, g, b) {
return '#' + [r, g, b].map(function (x) {
var hex = x.toString(16);
return hex.length === 1 ? '0' + hex : hex;
}).join('');
};
exports.rgbToHex = rgbToHex;
var hexToRgb = function hexToRgb(hex) {
return hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (_, r, g, b) {
return '#' + r + r + g + g + b + b;
}).substring(1).match(/.{2}/g).map(function (x) {
return parseInt(x, 16);
}).join(', ');
};
exports.hexToRgb = hexToRgb;