UNPKG

yoastseo

Version:

Yoast client-side content analysis

71 lines (66 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getParticiples; var _lodash = require("lodash"); var _yoastseo = require("yoastseo"); var _passiveVoiceIrregulars = require("../../config/internal/passiveVoiceIrregulars"); const { getWords, matchRegularParticiples } = _yoastseo.languageProcessing; /** * Returns an array of matches of irregular participles with suffixes. * * @param {string} word The word to match on. * @param {Array} irregulars The list of irregulars to match. * @param {string} suffixes The suffixes to match the word with. * * @returns {Array} A list with matched irregular participles. */ const matchFrenchParticipleWithSuffix = function (word, irregulars, suffixes) { const matches = []; (0, _lodash.forEach)(irregulars, function (irregular) { const irregularParticiplesRegex = new RegExp("^" + irregular + suffixes + "?$", "ig"); const participleMatch = word.match(irregularParticiplesRegex); if (participleMatch) { matches.push(participleMatch[0]); } }); return matches; }; /** * Matches a word for a few lists of irregular participles. * * @param {string} word The word to match. * @returns {Array} The matches. */ const matchIrregularParticiples = function (word) { // Match different classes of participles with suffixes. let matches = [].concat(matchFrenchParticipleWithSuffix(word, _passiveVoiceIrregulars.irregularsRegular, "(e|s|es)")); matches = matches.concat(matchFrenchParticipleWithSuffix(word, _passiveVoiceIrregulars.irregularsEndingInS, "(e|es)")); // Match irregular participles that don't require adding a suffix. if ((0, _lodash.includes)(_passiveVoiceIrregulars.irregularsIrregular, word)) { matches.push(word); } return matches; }; /** * Creates an array of the participles found in a clause. * * @param {string} clauseText The clause to find participles in. * @returns {Array} The list with participles. */ function getParticiples(clauseText) { const words = getWords(clauseText); const foundParticiples = []; (0, _lodash.forEach)(words, function (word) { const regularParticiplesRegex = [/\S+(é|ée|és|ées)($|[ \n\r\t.,'()"+\-;!?:/»«‹›<>])/ig]; if (matchRegularParticiples(word, regularParticiplesRegex).length !== 0 || matchIrregularParticiples(word).length !== 0) { foundParticiples.push(word); } }); return foundParticiples; } //# sourceMappingURL=getParticiples.js.map