JS Encode para

function encodeToAmp(text) {
  var el = document.createElement("div");
  
  el.textContent = text;
  el.innerText = text;
  return el.innerHTML;
}

encodeToAmp('&;\'><"')  //  =>  &amp;;'&gt;&lt;"
Destroyer of seg faults