UNPKG

yoastseo

Version:

Yoast client-side content analysis

47 lines (43 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isPassiveSentence; var _yoastseo = require("yoastseo"); var _nonPassiveVerbsStartingDi = _interopRequireDefault(require("../config/internal/nonPassiveVerbsStartingDi")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const { getWords } = _yoastseo.languageProcessing; const passivePrefix = "di"; /** * Checks the passed sentence to see if it contains Indonesian passive verb-forms. * * @param {string} sentence The sentence to match against. * * @returns {Boolean} Whether the sentence contains Indonesian passive voice. */ function isPassiveSentence(sentence) { const words = getWords(sentence.toLowerCase()); let matchedPassives = words.filter(word => word.length > 4); matchedPassives = matchedPassives.filter(word => word.startsWith(passivePrefix)); if (matchedPassives.length === 0) { return false; } // Check exception list. for (const nonPassive of _nonPassiveVerbsStartingDi.default) { matchedPassives = matchedPassives.filter(word => !word.startsWith(nonPassive)); } // Check direct precedence exceptions. matchedPassives = matchedPassives.filter(function (matchedPassive) { let matchedPassivesShouldStay = true; const passiveIndex = words.indexOf(matchedPassive); const wordPrecedingPassive = words[passiveIndex - 1]; if (wordPrecedingPassive === "untuk") { matchedPassivesShouldStay = false; } return matchedPassivesShouldStay; }); return matchedPassives.length !== 0; } //# sourceMappingURL=isPassiveSentence.js.map