yoastseo
Version:
Yoast client-side content analysis
42 lines (40 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isNotPrecededByException = isNotPrecededByException;
exports.isPrecededByException = isPrecededByException;
var _languageProcessing = require("../../../../languageProcessing");
var _includesWordsAtPosition = require("./includesWordsAtPosition");
/**
* Checks whether the given list of words contains another list of words in the given order,
* but not when they are preceded by one of the exceptions.
*
* @param {string[]} words The list of words.
* @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 isPrecededByException(words, exceptions) {
const splitExceptions = exceptions.map(exception => (0, _languageProcessing.getWords)(exception, "\\s", false));
return index => splitExceptions.some(exception => {
const startIndex = index - exception.length;
if (startIndex >= 0) {
return (0, _includesWordsAtPosition.includesWordsAtPosition)(exception, startIndex, words);
}
return false;
});
}
/**
* The reverse of isPrecededByException
* Checks whether the given list of words contains another list of words in the given order,
* but only when they are preceded by one of the exceptions.
*
* @param {string[]} words The list of words.
* @param {string[]} exception The list of exception phrases.
* @returns {function} A function that checks whether the given list of words is not contained in another list of words in the given order.
*/
function isNotPrecededByException(words, exception) {
return index => !isPrecededByException(words, exception)(index);
}
//# sourceMappingURL=isPrecededByException.js.map