Merge pull request #4877 from harryhope/master

Ignore non-words in word counter
This commit is contained in:
Jason Williams 2015-02-02 10:52:04 -06:00
commit 8b0505070d

View File

@ -1,11 +1,13 @@
// jscs: disable
function wordCount(s) {
s = s.replace(/(^\s*)|(\s*$)/gi, ''); // exclude start and end white-space
s = s.replace(/[ ]{2,}/gi, ' '); // 2 or more space to 1
s = s.replace(/\n /gi, '\n'); // exclude newline with a start spacing
s = s.replace(/\n+/gi, '\n');
s = s.replace(/<(.|\n)*?>/g, ' '); // strip tags
s = s.replace(/[^\w\s]/g, ''); // ignore non-alphanumeric letters
s = s.replace(/(^\s*)|(\s*$)/gi, ''); // exclude starting and ending white-space
s = s.replace(/\n /gi, ' '); // convert newlines to spaces
s = s.replace(/\n+/gi, ' ');
s = s.replace(/[ ]{2,}/gi, ' '); // convert 2 or more spaces to 1
return s.split(/ |\n/).length;
return s.split(' ').length;
}
export default wordCount;