<commit_before>import { HEXA_COLOR } from './color-regex';

const ColorUtil = {
  getRGB(color: string): number[] {
    let rgb: any[] = [];
    if (color.match(HEXA_COLOR)) {
      rgb = /#(.+)/gi.exec(color);
      if (rgb[1].length === 3) {
        return rgb[1].split('').map(_ => parseInt(_ + _, 16));
      }
      rgb = rgb[1].split('').map(_ => parseInt(_, 16));
      return [16 * rgb[0] + rgb[1], 16 * rgb[2] + rgb[3], 16 * rgb[4] + rgb[5]];
    }
    return [];
  },

  luminance(color: string): number {
    let rgb = this.getRGB(color);
    if (!rgb) {
      return null;
    }
    rgb = rgb.map(_ => {
      _ = _ / 255;
      if (_ < 0.03928) {
        _ = _ / 12.92;
      } else {
        _ = (_ + .055) / 1.055;
        _ = Math.pow(_, 2.4);
      }
      return _;
    });
    return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
  }
};
export default ColorUtil;<commit_msg>Move to full class syntax + add method<commit_after>import { HEXA_COLOR } from './color-regex';
import Color from './color';

class ColorUtil {
  public static getRGB(color: Color): number[] {
    let rgb: any[] = [];
    if (color.model === 'hexa') {
      rgb = /#(.+)/gi.exec(color.value);
      if (rgb[1].length === 3) {
        return rgb[1].split('').map(_ => parseInt(_ + _, 16));
      }
      rgb = rgb[1].split('').map(_ => parseInt(_, 16));
      return [16 * rgb[0] + rgb[1], 16 * rgb[2] + rgb[3], 16 * rgb[4] + rgb[5]];
    }
    return [];
  }

  public static luminance(color: Color): number {
    let rgb = this.getRGB(color);
    if (!rgb) {
      return null;
    }
    rgb = rgb.map(_ => {
      _ = _ / 255;
      if (_ < 0.03928) {
        _ = _ / 12.92;
      } else {
        _ = (_ + .055) / 1.055;
        _ = Math.pow(_, 2.4);
      }
      return _;
    });
    return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
  }

  public static extractColor(text: string):Color[] {
    let colors:Color[] = [];
    colors = colors.concat(this._extractHexa(text));
    return colors;
  }

  public static match(text: string, model: string):boolean {
    switch(model) {
      case 'hexa':
        return !!text.match(HEXA_COLOR);
      default:
        return false;
    }
  }
  
  private static _extractHexa(text: string): Color[] {
    let match = null;
    let colors:Color[] = [];
    while((match = HEXA_COLOR.exec(text)) !== null) {
      colors.push(new Color('hexa', match[1], match.index))
    }
    return colors;
  }
};
export default ColorUtil;
{'fraction_non_alphanumeric': 0.19500402900886382, 'fraction_numerical': 0.048751007252215955, 'mean_word_length': 2.13510101010101, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '719891', 'n_tokens_mistral': 1011, 'n_tokens_neox': 897, 'n_words': 197}