export const regex = {
  boolean: /boolean/g,
  number: /number/g,
  string: /string/g,
  arrayModel: /^(?=(.*[[]]+))(^((?!number|string|boolean).)*$)/g, // []Model
  uuid: /(^[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}$)/, // 00002aa1-0000-1000-8000-00805f9b34fb
  mac: /(^(?:[a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}$)/, // AA:A8:AC:31:31:FB
};

/**
 * Converts a string to snake case
 *
 * @param {string} words String containing the words
 */
export function toSnakeCase(words: string) {
  /* eslint-disable indent */
  return typeof words === 'string'
    ? words
        .replace(/\W+/g, ' ')
        .split(/ |\B(?=[A-Z])/)
        .map((word) => word.toLowerCase())
        .join('_')
    : '';
  /* eslint-enable indent */
}

/**
 * Checks if it's an object.
 *
 * @param {any} obj Thing to check.
 */
export function isObject(obj: any) {
  return typeof obj === 'object' && obj !== null;
}

/**
 * Parse a string to boolean.
 *
 * @param {string} bool String to check.
 */
export function parseBoolean(bool: string) {
  return ['1', 'True', 'true'].includes(bool);
}

/**
 * Select a value from the values object.
 *
 * @param {Values} values Object values
 * @param {string} condition Condition
 */
type Values = { [k: string]: string; default: string };
export function select(values: Values, condition: string) {
  return condition in values ? values[condition] : values.default;
}
