function lojban2loglan(text,gentufa){
  text=text.toLowerCase().replace(/[^a-z'\. ]/g, '');
  const logl = require('./loglan.js');
  const items = logl.loglandic();
  let i, myregexp, j;
      text = gentufa(text).map(a => a[1].replace(/-/g,'')).filter(a => a!==' ');
      for (i = 0; i < items.length; i++) {
        myregexp = new RegExp(`^${items[i][0]}$`, "gm");
        for (j = 0; j < text.length; j++) {
          if (text[j].match(myregexp) !== null) {
            text[j] = items[i][1].replace(/ /gm, "A ").replace(/$/gm, "A");
          }
        }
      }
      text = text.join(" ").replace(/ /gm, "* ").replace(/$/gm, "*").replace(/A\*/gm, "").replace(/A$/gm, "");
  return text;
}    

function loglan2lojban(text){
  text=text.toLowerCase().replace(/[^a-z'\. ]/g, '');
  const logl = require('./loglan.js');
  const items = logl.loglandic();
  let i, myregexp, j;
      text = text.split(" ");
      for (i = 0; i < items.length; i++) {
        myregexp = new RegExp(`^${items[i][1]}$`, "gm");
        for (j = 0; j < text.length; j++) {
          if (text[j].match(myregexp) !== null) {
            text[j] = items[i][0].replace(/ /gm, "A ").replace(/$/gm, "A");
          }
        }
      }
      text = text.join(" ").replace(/ /gm, "* ").replace(/$/gm, "*").replace(/A\*/gm, "").replace(/A$/gm, "");
  return text;
}

module.exports = {lojban2loglan,loglan2lojban};
