Ghost/ghost/admin/utils/word-count.js

12 lines
355 B
JavaScript
Raw Normal View History

// 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
2014-06-22 21:46:29 +04:00
s = s.replace(/\n /gi, '\n'); // exclude newline with a start spacing
s = s.replace(/\n+/gi, '\n');
2014-06-22 21:46:29 +04:00
return s.split(/ |\n/).length;
}
export default wordCount;