Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
FAMarfuaty committed Oct 27, 2023
1 parent 3335864 commit 6d4ee5b
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ 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
* and check if the singular word can be found in the frequency list.
* 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 );
}
Expand Down

0 comments on commit 6d4ee5b

Please sign in to comment.