// @flow
import Color from 'color';

export const BRACKET_REGEX = /\((.*)\)/;

export const fadeColor = (color: string, fade: number) => {
  const colorObject = Color(color).fade(fade).string();

  const rgba = colorObject.match(BRACKET_REGEX)[1].split(', ');

  const roundedValpha = parseFloat(rgba[3]).toFixed(2);
  return `rgba(${rgba[0]}, ${rgba[1]}, ${rgba[2]}, ${roundedValpha})`;
};
