yoastseo
Version:
Yoast client-side content analysis
46 lines (42 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _lodash = require("lodash");
var _getWords = _interopRequireDefault(require("../../word/getWords"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Checks whether a word from the precedence exception list occurs anywhere in the clause before the participle.
* If this is the case, the sentence part is not passive.
*
* @param {string} clause The clause that contains the participle.
* @param {string} participle The participle.
* @param {Array} cannotBeBetweenPassiveAuxiliaryAndParticipleList List of words which cannot be between auxiliary and participle.
*
* @returns {boolean} Returns true if a word from the precedence exception list occurs anywhere in the
* sentence part before the participle, otherwise returns false.
*/
function _default(clause, participle, cannotBeBetweenPassiveAuxiliaryAndParticipleList = []) {
// Break the sentence part up into words and convert to lower case.
const wordsInClause = (0, _getWords.default)(clause).map(word => word.toLowerCase());
// Search the participle in the word list.
const participleIndex = wordsInClause.indexOf(participle.toLowerCase());
/*
* There can be no exception in the following situations:
*
* -1 The participle is not found.
* 0 There is no word before the participle.
*/
if (participleIndex < 1) {
return false;
}
// Check if the words preceding the participle are in the exceptions list.
for (let i = 0; i < participleIndex; i++) {
if ((0, _lodash.includes)(cannotBeBetweenPassiveAuxiliaryAndParticipleList, wordsInClause[i])) {
return true;
}
}
return false;
}
//# sourceMappingURL=precedenceException.js.map