1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

ignore non-words in word counter

This commit is contained in:
Harry Hope 2015-02-01 01:22:20 -05:00
parent 0be477d59a
commit efa157db3d

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;