"use strict";

exports.__esModule = true;
exports.validateHex = exports.normalizeHexInput = exports.extractHex = void 0;
var contains = function contains() {
  for (var _len = arguments.length, array = new Array(_len), _key = 0; _key < _len; _key++) {
    array[_key] = arguments[_key];
  }
  return number => array.includes(number);
};
var hexRules = [{
  when: contains(0),
  make: () => ''
}, {
  when: contains(1),
  make: hex => '#' + hex[0].repeat(6)
}, {
  when: contains(2),
  make: hex => '#' + (hex[0] + hex[1]).repeat(3)
}, {
  when: contains(3, 4, 5),
  make: hex => '#' + hex[0].repeat(2) + hex[1].repeat(2) + hex[2].repeat(2)
}, {
  when: length => contains(6)(length) || length > 6,
  make: hex => '#' + hex.slice(0, 6)
}];
var validateHex = hex => {
  if (hex === '' || !hex) {
    return hex;
  }
  var hexArray = hex.replace('#', '');
  var hexLength = hexArray.length;
  return hexRules.find(_ref => {
    var {
      when
    } = _ref;
    return when(hexLength);
  }).make(hexArray);
};
exports.validateHex = validateHex;
var extractHex = hex => "#".concat(hex.toUpperCase().replace(/[^A-F0-9]/g, ''));
exports.extractHex = extractHex;
var normalizeHexInput = hex => {
  var value = extractHex(hex);
  return value === '#' ? '' : value;
};
exports.normalizeHexInput = normalizeHexInput;
//# sourceMappingURL=hex-helpers.js.map