UNPKG

yoastseo

Version:

Yoast client-side content analysis

46 lines (42 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isPassiveSentence; var _yoastseo = require("yoastseo"); var _passiveEndings = _interopRequireDefault(require("../config/internal/passiveEndings")); var _nonPassiveExceptions = require("../config/internal/nonPassiveExceptions"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const { getWords } = _yoastseo.languageProcessing; /** * Filters out words that are passive exceptions from an array. * * @param {string[]} matchedPassives The words from the sentence that could be passives * * @returns {string[]} The array of words with the non-passives filtered out */ const checkNonPassivesStemsList = function (matchedPassives) { return matchedPassives.filter(passive => _nonPassiveExceptions.nonPassiveStems.some(stem => _passiveEndings.default.some(function (ending) { const pattern = new RegExp("^" + stem + ending + "$"); return !pattern.test(passive); }))); }; /** * Checks the passed sentence to see if it contains passive verb forms and is not found in the non-passive full forms exception list. * * @param {string} sentence The sentence to match against. * * @returns {Boolean} Whether the sentence contains a Turkish verb passive voice. */ function isPassiveSentence(sentence) { const words = getWords(sentence); // We only check words that is longer than 5 letters let matchedPassives = words.filter(word => word.length > 5); // Filter out words that are passive exceptions from an array matchedPassives = matchedPassives.filter(word => !_nonPassiveExceptions.nonPassivesFullForms.includes(word)); matchedPassives = checkNonPassivesStemsList(matchedPassives); return matchedPassives.some(word => _passiveEndings.default.some(ending => word.endsWith(ending))); } //# sourceMappingURL=isPassiveSentence.js.map