word-counting
Version:
A very powerful words counter that supports plain text and html.
25 lines • 873 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var htmlToText = require('html-to-text');
var regex = require('word-regex');
/**
* The function that can count the words occurrence in text
* @param text The string that you want to count words
* @param config The config settings for the wordsCounter function
* @returns an object that has the words occurrence information
*/
var wordsCounter = function (text, config) {
var result = {
wordsCount: 0
};
var plainText = config && config.isHtml
? htmlToText.fromString(text, { ignoreHref: true, ignoreImage: true })
: text;
if (plainText.length > 0) {
var match = plainText.match(regex());
result.wordsCount = match ? match.length : 0;
}
return result;
};
exports.default = wordsCounter;
//# sourceMappingURL=word-counting.js.map