UNPKG

@atlaskit/adf-schema

Version:

Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs

21 lines (19 loc) 657 B
// eslint-disable-line import/no-namespace import { isHex } from './is-hex'; /** * 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) */ export function hexToRgb(color) { if (!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, ")"); }