ignore non-words in word counter
This commit is contained in:
parent
950f9c29b3
commit
6361976c39
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user