{"size": 1375, "ext": "js", "max_stars_repo_path": "input/app/scripts/utils/ColorUtils.js", "max_stars_repo_name": "inigoBereciartua/WacLine", "max_stars_repo_stars_event_min_datetime": "2020-10-22T07:44:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T17:41:14.000Z", "max_issues_repo_path": "input/app/scripts/utils/ColorUtils.js", "max_issues_repo_name": "aitord97/WacLine", "max_issues_repo_issues_event_min_datetime": "2020-03-04T14:38:21.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-08T09:08:50.000Z", "max_forks_repo_path": "input/app/scripts/utils/ColorUtils.js", "max_forks_repo_name": "aitord97/WacLine", "max_forks_repo_forks_event_min_datetime": "2020-04-07T06:53:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-14T15:07:16.000Z"}
{"max_stars_count": 6, "max_issues_count": 88, "max_forks_count": 4, "avg_line_length": 24.5535714286, "max_line_length": 107, "alphanum_fraction": 0.6109090909}
import ColorHash from 'color-hash'
import Color from 'color'
import UniqueColors from 'unique-colors'

class ColorUtils {
  static getDefaultColor () {
    return 'rgba(150,150,150,0.5)'
  }

  static getRandomColor () {
    const red = (Math.floor(Math.random() * 256))
    const green = (Math.floor(Math.random() * 256))
    const blue = (Math.floor(Math.random() * 256))
    let alpha = Math.random()
    if (alpha < 0.5) {
      alpha = 0.5
    }
    return 'rgba(' + red + ',' + green + ',' + blue + ', ' + alpha + ')'
  }

  static colorFromString (str) {
    return new Color(str)
  }

  static getHashColor (text, alpha) {
    const colorHash = new ColorHash({ hash: ColorUtils.customHash })
    const resultArray = colorHash.rgb(text)
    const alphaValue = alpha || 0.5
    return 'rgba(' + resultArray[0] + ',' + resultArray[1] + ',' + resultArray[2] + ', ' + alphaValue + ')'
  }

  static setAlphaToColor (color, alpha) {
    return Color(color).alpha(alpha).rgb().string()
  }

  static customHash (str) {
    let hash = 0
    for (let i = 0; i < str.length; i++) {
      const char = str.charCodeAt(i)
      hash += char
    }
    return hash
  }

  static hasAlpha (str) {
    const color = new Color(str)
    return color.valpha !== 1
  }

  static getDifferentColors (number) {
    return UniqueColors.unique_colors(number)
  }
}

export default ColorUtils
