All files / libs/ext/web/src/lib colors.ts

88.23% Statements 15/17
50% Branches 1/2
100% Functions 1/1
88.23% Lines 15/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 181x 7x 7x 7x     7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x  
export const hexToRgb = (hexRaw: string): { r: number; g: number; b: number } | null => {
  const hex = hexRaw.replace('#', '');
 
  if (!/^[0-9a-fA-F]{6}$/u.test(hex)) {
    return null;
  }
 
  const bigint = Number.parseInt(hex, 16);
  // eslint-disable-next-line no-bitwise
  const r = (bigint >> 16) & 255;
  // eslint-disable-next-line no-bitwise
  const g = (bigint >> 8) & 255;
  // eslint-disable-next-line no-bitwise
  const b = bigint & 255;
 
  return { r, g, b };
};