title: Capitalize Names in javascript
body: <p>I have a function which Capitalize the sentences. But its not able to Capitalize names such as,   </p>
  
  <pre><code>D'agostino, Fred  
  D'agostino, Ralph B.  
  D'allonnes, C. Revault  
  D'amanda, Christopher 
  </code></pre>
  
  <p>I am expecting:</p>
  
  <pre><code>D'Agostino, Fred  
  D'Agostino, Ralph B.  
  D'Allonnes, C. Revault  
  D'Amanda, Christopher 
  </code></pre>
  
  <p><strong>Function</strong>:</p>
  
  <pre><code>getCapitalized(str){
      var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
      return str.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function (match, index, title) {
        if (index &gt; 0 &amp;&amp; index + match.length !== title.length &amp;&amp;
          match.search(smallWords) &gt; -1 &amp;&amp; title.charAt(index - 2) !== ":" &amp;&amp;
          (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &amp;&amp;
          (title.charAt(index + match.length) !== "'" || title.charAt(index - 1) === "'") &amp;&amp;
          title.charAt(index - 1).search(/[^\s-]/) &lt; 0) {
          return match.toLowerCase();
        }
        if (match.substr(1).search(/[A-Z]|\../) &gt; -1) {
          return match;
        }
        return match.charAt(0).toUpperCase() + match.substr(1);
      });
    }
  </code></pre>
  
  <p>Can anybody help me figuring out the issue? I have tried using <code>(title.charAt(index + match.length) !== "'" || title.charAt(index - 1) === "'")</code> but it doesn't help. </p>