@@ -126,17 +126,27 @@ const showDate = computed(() => {
126126 return !! slots [" date" ];
127127});
128128
129+ /**
130+ * Computes class for given variant
131+ */
129132const commentClass = computed (() => {
130133 return props .variant === " slider"
131134 ? " m-comment--slider"
132135 : " m-comment--listing" ;
133136});
134137
138+ /**
139+ * Computes rating with min and max limits
140+ */
141+ const computedRating = computed (() =>
142+ Math .min (Math .max (props .rating , 0 ), MAX_STARS )
143+ );
144+
135145/*
136146 * Converts the dot used on decimal numbers and converts it to a comma.
137147 */
138148const ratingWithDecimalComma = computed (() => {
139- return props . rating .toLocaleString (LOCALES .valueOf (), {
149+ return computedRating . value .toLocaleString (LOCALES .valueOf (), {
140150 minimumFractionDigits: 1 ,
141151 });
142152});
@@ -145,14 +155,14 @@ const ratingWithDecimalComma = computed(() => {
145155Calculates the amount of full, empty and half-stars to be displayed.
146156 */
147157const evaluateRating = computed (() => {
148- const decimalPart = + (props . rating % 1 ).toFixed (1 ); // ask Brendan Eich why "3.3 % 1 = 0.2999999999999998" and then come back
158+ const decimalPart = + (computedRating . value % 1 ).toFixed (1 ); // ask Brendan Eich why "3.3 % 1 = 0.2999999999999998" and then come back
149159
150- let fullStars = Math .min (Math .floor (props . rating ), MAX_STARS );
151- let emptyStars = Math .floor (MAX_STARS - props . rating );
160+ let fullStars = Math .min (Math .floor (computedRating . value ), MAX_STARS );
161+ let emptyStars = Math .floor (MAX_STARS - computedRating . value );
152162 let isHalfStar = false ;
153163
154164 // evaluating half-stars and if the rating is e.g. 3.9 an extra full star needs to be displayed
155- if (props . rating !== 0.0 && props . rating !== MAX_STARS ) {
165+ if (computedRating . value !== 0.0 && computedRating . value !== MAX_STARS ) {
156166 if (decimalPart <= LOWER_THRESHOLD ) emptyStars ++ ;
157167 else if (decimalPart >= UPPER_THRESHOLD ) fullStars ++ ;
158168 else isHalfStar = true ;
0 commit comments