yoastseo
Version:
Yoast client-side content analysis
38 lines (36 loc) • 1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _lodash = require("lodash");
var _yoastseo = require("yoastseo");
var _tinySegmenter = _interopRequireDefault(require("tiny-segmenter"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const {
sanitizeString,
removePunctuation
} = _yoastseo.languageProcessing;
const segmenter = new _tinySegmenter.default();
/**
* Returns an array with words used in the text.
*
* @param {string} text The text to be counted.
*
* @returns {Array} The array with all words.
*/
function _default(text) {
// Strips HTML tags.
text = sanitizeString(text);
if (text === "") {
return [];
}
let words = segmenter.segment(text);
words = (0, _lodash.map)(words, function (word) {
return removePunctuation(word);
});
return (0, _lodash.filter)(words, function (word) {
return word.trim() !== "";
});
}
//# sourceMappingURL=getWords.js.map