From 6d4ee5b54334e6f5257c6e361b8e6d5a4faa5811 Mon Sep 17 00:00:00 2001 From: aidamarfuaty Date: Fri, 27 Oct 2023 12:42:24 +0200 Subject: [PATCH] Improve code readability --- .../languages/fr/helpers/checkIfWordIsComplex.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/yoastseo/src/languageProcessing/languages/fr/helpers/checkIfWordIsComplex.js b/packages/yoastseo/src/languageProcessing/languages/fr/helpers/checkIfWordIsComplex.js index 05c4ab83538..f98d6515e4b 100644 --- a/packages/yoastseo/src/languageProcessing/languages/fr/helpers/checkIfWordIsComplex.js +++ b/packages/yoastseo/src/languageProcessing/languages/fr/helpers/checkIfWordIsComplex.js @@ -44,6 +44,11 @@ export default function checkIfWordIsComplex( config, word, premiumData ) { * word longer than 9 characters is not complex if it starts with capital letter. */ if ( word[ 0 ].toLowerCase() === word[ 0 ] ) { + const standardSPluralSuffixesRegex = new RegExp( premiumData.suffixGroupsComplexity.standardSuffixesWithSplural ); + const standardXPluralSuffixesRegex = new RegExp( premiumData.suffixGroupsComplexity.standardSuffixesWithXplural ); + const irregularPluralSingularSuffixes = premiumData.suffixGroupsComplexity.irregularPluralSingularSuffixes; + const irregularPluralSuffixRegex = new RegExp( irregularPluralSingularSuffixes[ 0 ] ); + /* * If a word is longer than 9 characters and doesn't start with capital letter, * we check further whether it is a plural that ends on the -s or -x plural suffix. If it is, we remove the plural suffix @@ -51,12 +56,10 @@ export default function checkIfWordIsComplex( config, word, premiumData ) { * if it is a plural that does not end on -s or -x but on -aux, we replace the plural -aux suffix with the singular suffix -al. * The word is not complex if the singular form is in the list. */ - if ( new RegExp( premiumData.suffixGroupsComplexity.standardSuffixesWithSplural ).test( word ) || - new RegExp( premiumData.suffixGroupsComplexity.standardSuffixesWithSplural ).test( word ) ) { + if ( standardSPluralSuffixesRegex.test( word ) || standardXPluralSuffixesRegex.test( word ) ) { word = word.substring( 0, word.length - 1 ); - } else if ( new RegExp( premiumData.suffixGroupsComplexity.irregularPluralSingularSuffixes[ 0 ] ).test( word ) ) { - word = word.replace( new RegExp( premiumData.suffixGroupsComplexity.irregularPluralSingularSuffixes[ 0 ] ), - premiumData.suffixGroupsComplexity.irregularPluralSingularSuffixes[ 1 ] ); + } else if ( irregularPluralSuffixRegex.test( word ) ) { + word = word.replace( irregularPluralSuffixRegex, irregularPluralSingularSuffixes[ 1 ] ); } return ! frequencyList.includes( word ); }