title: How to escape html and urls in Google Apps Script?
body: <p>Say I have the following Javascript:</p>
  
  <pre><code>var userString = "..."; // e.g. "cats &lt; dogs"
  </code></pre>
  
  <p>How do I get <code>userString</code> with all html characters escaped?</p>
  
  <p>E.g. I want <code>cats &amp;lt; dogs</code>.</p>
  
  <p>Also, how do I do the same thing with escaping all URL characters?</p>
  
  <p>E.g. I want <code>cats%20%3C%20dogs</code></p>
  
  <p>I realize I could use a function <a href="https://stackoverflow.com/a/5499821/35690">such as this</a>, but it seems to be non-exhaustive. E.g. it's missing <code>&amp;quot;</code>.</p>
  
  <p>Since Javascript does not seem to have a built-in method, I'm hoping that Google Apps Script has a built-in solution.</p>