Utils/hexToRgb.js

/**
 * Converts hex values to rgb values
 *
 * @function hexToRgb
 * @since 1.0.0
 * @memberof module:Utils
 * @license Adapted from David on {@link https://stackoverflow.com/a/11508164/7019650|stackoverflow}
 *
 * @param {Number} hex - the hex value you want to convert
 *
 * @returns {String} A string representing the rgb value after conversion.
 * @example
 * import { hexToRgb } from 'fenix-tools'
 *
 * hexToRgb('42f48c') // => 66,244,140'
 *
 */
export default function hexToRgb (hex) {
  const integer = parseInt(hex, 16)
  const r = (integer >> 16) & 255
  const g = (integer >> 8) & 255
  const b = integer & 255
  return [r, g, b].join()
}