Create a stringToSlug() prototype function in javascript
<p>I have used the answers <a href="http://stackoverflow.com/questions/1053902/how-to-convert-a-title-to-a-url-slug-in-jquery">here</a> as an examples although I would prefer to write it like this: <code>value.stringToSlug()</code></p>

<p>So I have changed it to this:</p>

<pre><code>// String to slug
String.prototype.stringToSlug = function(str) {
      str = str.replace(/^\s+|\s+$/g, ''); // trim
      str = str.toLowerCase();
      str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
               .replace(/\s+/g, '-') // collapse whitespace and replace by -
               .replace(/-+/g, '-'); // collapse dashes
      return str;
};
</code></pre>

<p>It works if I pass the string like this:</p>

<pre><code>var value = $(this).val();
value.stringToSlug(value);
</code></pre>
