@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
26 lines (24 loc) • 770 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hexToRgb = hexToRgb;
var _isHex = require("./is-hex");
// eslint-disable-line import/no-namespace
/**
* Converts hex color format to rgb.
* Works well with full hex color format and shortcut as well.
*
* @param hex - hex color string (#xxx, or #xxxxxx)
*/
function hexToRgb(color) {
if (!(0, _isHex.isHex)(color)) {
return null;
}
var colorBits = color.substring(1).split('');
if (colorBits.length === 3) {
colorBits = [colorBits[0], colorBits[0], colorBits[1], colorBits[1], colorBits[2], colorBits[2]];
}
var rgb = Number("0x".concat(colorBits.join('')));
return "rgb(".concat(rgb >> 16 & 255, ",").concat(rgb >> 8 & 255, ",").concat(rgb & 255, ")");
}