I like to avoid repeating things like that:
if (rootName !== '') {
  if (name.indexOf("&R") != -1) {
    name = name.replace(blah);
  }
  if (name.indexOf("&r") != -1) {
    name = blah;
  }
}
// etc