UNPKG

yoastseo

Version:

Yoast client-side content analysis

34 lines (33 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _lodash = require("lodash"); /** * Checks whether a given word is directly preceded by a word from a list of words. * * @param {Array} precedingWords The array of objects with matches and indices. * @param {number} matchIndex The index of the word for which to check whether it's preceded by one of the other words. * @param {boolean} addSpace True if a space should be added. * * @returns {boolean} Returns true if the match is preceded by a given word, otherwise returns false. */ function _default(precedingWords, matchIndex, addSpace = true) { /* 1 if there is a space between the match and the preceding word (because the end word boundary is not included in the match). 0 if the preceding word is a contraction. */ const space = addSpace ? 1 : 0; if ((0, _lodash.isEmpty)(precedingWords)) { return false; } const precedingWordsEndIndices = []; (0, _lodash.forEach)(precedingWords, function (precedingWord) { const precedingWordsEndIndex = precedingWord.index + precedingWord.match.length + space; precedingWordsEndIndices.push(precedingWordsEndIndex); }); return (0, _lodash.includes)(precedingWordsEndIndices, matchIndex); } //# sourceMappingURL=includesIndex.js.map