yoastseo
Version:
Yoast client-side content analysis
44 lines (42 loc) • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isFollowedByException = isFollowedByException;
exports.isNotFollowedByException = isNotFollowedByException;
var _languageProcessing = require("../../../../languageProcessing");
var _includesWordsAtPosition = require("./includesWordsAtPosition");
/**
* Checks whether a list of words contains a sequence of words in the given order, excluding cases when
* they are followed by one of the exceptions.
*
* @param {string[]} words The list of words.
* @param {string[]} consecutiveWords The sequence of words in the given order to find in the list.
* @param {string[]} exceptions The list of exception phrases.
*
* @returns {function} A function that checks whether the given list of words is contained in another list of words in the given order.
*/
function isFollowedByException(words, consecutiveWords, exceptions) {
const splitExceptions = exceptions.map(exception => (0, _languageProcessing.getWords)(exception, "\\s", false));
return index => splitExceptions.some(exception => {
const startIndex = index + consecutiveWords.length;
if (startIndex >= 0) {
return (0, _includesWordsAtPosition.includesWordsAtPosition)(exception, startIndex, words);
}
return false;
});
}
/**
* Checks whether the given list of words contains another list of words in the given order,
* but only when they are followed by one of the exceptions.
*
* @param {string[]} words The list of words.
* @param {string[]} consecutiveWords The list of words to find.
* @param {string[]} exceptions The list of exception phrases.
*
* @returns {function} A function that checks whether the given list of words is contained in another list of words in the given order.
*/
function isNotFollowedByException(words, consecutiveWords, exceptions) {
return index => !isFollowedByException(words, consecutiveWords, exceptions)(index);
}
//# sourceMappingURL=isFollowedByException.js.map