<commit_before>'use strict';

const util = require('util');
const fs = require('fs');
const themes = [];

var itv, ws281x, colorName = '';

function init(_ws281x) {
  ws281x = _ws281x;
  stop();
}

function setColorWithRgb(r, g, b, count) {
  colorName = [r, g, b];
  ws281x.setBrightness(255);
  var pixelData = new Uint32Array(count);
  for (var i = 0; i < count; i++) {
    pixelData[i] = rgb2Int(r, g, b);
  }
  ws281x.render(pixelData);
}

function setColorWithHex(hex, count) {
  var rgb = hexToRGB(hex);
  setColorWithRgb(rgb[0], rgb[1], rgb[2], count);
}

function stop() {
  colorName = '';
}

function getColorName() {
  return colorName;
}

function hexToRGB(hex) {
  var r = hex >> 16;
  var g = hex >> 8 & 0xFF;
  var b = hex & 0xFF;

  console.log('hex to rgb', hex, r, g, b);
  return [r, g, b];
}

function rgb2Int(r, g, b) {
  return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
}

module.exports = {
  init: init,<commit_msg>add rgb and hex<commit_after>'use strict';

const util = require('util');
const fs = require('fs');
const themes = [];

var itv, ws281x, colorName = '';

function init(_ws281x) {
  ws281x = _ws281x;
  stop();
}

function setColorWithRgb(r, g, b, count) {
  colorName = [r, g, b];
  ws281x.setBrightness(255);
  var pixelData = new Uint32Array(count);
  for (var i = 0; i < count; i++) {
    pixelData[i] = rgb2Int(r, g, b);
  }
  ws281x.render(pixelData);
}

function setColorWithHex(hex, count) {
  var rgb = hexToRGB(hex);
  if (rgb) {
    setColorWithRgb(rgb.r, rgb.g, rgb.b, count);
  }
}

function stop() {
  colorName = '';
}

function getColorName() {
  return colorName;
}

function hexToRGB(hex) {
  // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
  var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  hex = hex.replace(shorthandRegex, function(m, r, g, b) {
    return r + r + g + g + b + b;
  });

  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  console.log('hex to rgb', hex, result);
  return result ? {
    r: parseInt(result[1], 16),
    g: parseInt(result[2], 16),
    b: parseInt(result[3], 16)
  } : null;
}

function rgb2Int(r, g, b) {
  return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
}

module.exports = {
  init: init,
{'fraction_non_alphanumeric': 0.2010652463382157, 'fraction_numerical': 0.03994673768308921, 'mean_word_length': 3.445759368836292, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5469383', 'n_tokens_mistral': 1027, 'n_tokens_neox': 947, 'n_words': 234}