Skip to content

Commit

Permalink
Refactor findNearestFontStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
mikachan committed Jul 9, 2024
1 parent b06c4e4 commit b407be1
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ export function findNearestFontStyle( availableFontStyles, newFontStyleValue ) {
return '';
}

const validStyles = [ 'normal', 'italic', 'oblique' ];
if ( ! validStyles.includes( newFontStyleValue ) ) {
return '';
}

if (
! availableFontStyles ||
availableFontStyles.length === 0 ||
Expand All @@ -209,26 +214,14 @@ export function findNearestFontStyle( availableFontStyles, newFontStyleValue ) {
return newFontStyleValue;
}

let nearestFontStyle = '';
const validStyles = [ 'normal', 'italic', 'oblique' ];

if (
! validStyles.includes( newFontStyleValue ) ||
! availableFontStyles.find(
( style ) => style.value === newFontStyleValue
)
) {
nearestFontStyle = '';
}

if (
newFontStyleValue === 'oblique' &&
! availableFontStyles.find( ( style ) => style.value === 'oblique' )
) {
nearestFontStyle = 'italic';
return 'italic';
}

return nearestFontStyle;
return '';
}

/**
Expand Down

0 comments on commit b407be1

Please sign in to comment.