// eslint-disable-next-line security/detect-unsafe-regex
const ENS_NAME_REGEX = /^(([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\.)+)eth(\/.*)?$/

export default function parseENSAddress(ensAddress: string): { ensName: string; ensPath?: string } | undefined {
  const match = ensAddress.match(ENS_NAME_REGEX)
  if (!match) {
    return undefined
  }
  return { ensName: `${match[1].toLowerCase()}eth`, ensPath: match[4] }
}
