title: Using node-validator to strip HTML tags from a string
body: <p>I'm looking for a way to strip tags from a string in the backend using NodeJS. A few answers here have suggested trying <a href="https://github.com/chriso/node-validator" rel="nofollow"><code>node-validator</code></a> but neither the docs nor any answers explain specifically how to use it.</p>
  
  <p>For instance, I have a string in a variable like this:</p>
  
  <p><strong>INPUT:</strong></p>
  
  <p><code>var text = '&lt;p&gt;&lt;b&gt;Hello there!&lt;/b&gt; I am a string &lt;span class="small"&gt;but not a very exciting one!&lt;/span&gt;&lt;/p&gt;'</code></p>
  
  <p><strong>DESIRED OUTPUT:</strong></p>
  
  <p><code>var newText = Hello there! I am a string but not a very exciting one!</code></p>
  
  <p>The <code>node-validator</code> docs have several options, I think the most pertinent is the <code>trim()</code> function:</p>
  
  <pre><code>var check = require('validator').check,
      sanitize = require('validator').sanitize
  
  //Validate
  check('test@email.com').len(6, 64).isEmail();        //Methods are chainable
  check('abc').isInt();                                //Throws 'Invalid integer'
  check('abc', 'Please enter a number').isInt();       //Throws 'Please enter a number'
  check('abcdefghijklmnopzrtsuvqxyz').is(/^[a-z]+$/);
  
  //Sanitize / Filter
  var int = sanitize('0123').toInt();                  //123
  var bool = sanitize('true').toBoolean();             //true
  var str = sanitize(' \t\r hello \n').trim();       //'hello'
  var str = sanitize('aaaaaaaaab').ltrim('a');         //'b'
  var str = sanitize(large_input_str).xss();
  var str = sanitize('&amp;lt;a&amp;gt;').entityDecode();      //'&lt;a&gt;'
  </code></pre>
  
  <p>Is it possible to use this to strip tags (as well as classes) from a string? </p>
  
  <p><strong>EDIT</strong>: I also have <code>cheerio</code> (essentially jquery) loaded and was trying to use something similar to:</p>
  
  <pre><code>HTML
  &lt;div class="select"&gt;
  &lt;p&gt;&lt;b&gt;Hello there!&lt;/b&gt; I am a string &lt;span class="small"&gt;but not a very exciting one!&lt;/span&gt;&lt;/p&gt;
  &lt;/div&gt;
  
  JAVASCRIPT
  (function() {
      var text = $(.select *).each(function() {
          var content = $(this).contents();
          $(this).replaceWith(content);
      }
      );
      return text;
  }
  ());
  </code></pre>
  
  <p>But this results in an <code>'Object '&lt;p&gt;&lt;b&gt;Hello....' has no method "contents"'</code> error, I'm open to using a similar function if it's easier with jQuery.</p>