//const log   = require('../utils/log.utils');

import { logger } from "./logger.utils";

function removeNonAlphanumeric(inputString: string) {
  logger.debug("removeNonAlphanumeric: Sanitizing string")
  return inputString.replace(/[^a-zA-Z0-9]/g, "");
}

function removeNonAlpha(inputString: string) {
  logger.debug("removeNonAlpha: Sanitizing string")
  return inputString.replace(/[^a-zA-Z]/g, "");
}

function removeNonNumeric(inputString: string) {
  logger.debug("removeNonNumeric: Sanitizing string")
  return inputString.replace(/[^0-9]/g, "");
}

const cleanApiEndpointTxt = removeNonAlpha;
const cleanApiEndpointNum = removeNonAlphanumeric;

function cleanNrcc(input: string) {
  logger.error("DEPRECATED FUNCTION","cleanNrcc: Converting NRCC Data")
  // Remove newlines and then <p> tags from input
  const cleanInput = input.replace(/[\n\r]/g, "").replace(/<\/?p[^>]*>/g, "");
  return cleanInput;
}

function getDomainFromEmail(mail: string) {
  logger.debug("getDomainFromEmail: Obtaining domain from email address")
  // Needs testing
  let split = mail.split("@");
  return split[1].toLowerCase();
}

module.exports = {
  cleanApiEndpointTxt,
  cleanApiEndpointNum,
  removeNonAlpha,
  removeNonAlphanumeric,
  removeNonNumeric,
  cleanNrcc,
  getDomainFromEmail,
};

export {
  cleanApiEndpointTxt,
  cleanApiEndpointNum,
  removeNonAlpha,
  removeNonAlphanumeric,
  removeNonNumeric,
  cleanNrcc,
  getDomainFromEmail,
};
