Files
JayuCloud/JY-Artist-Frontend/src/utils/comment-review.ts
T

13 lines
413 B
TypeScript
Raw Normal View History

2026-05-31 18:36:52 +08:00
export const normalizeCommentRating = (value: unknown, fallback = 5) => {
const numeric = Number(value ?? fallback)
if (!Number.isFinite(numeric)) {
return fallback
}
return Math.min(5, Math.max(1, Math.round(numeric)))
}
export const buildRatingStars = (rating: unknown) => {
const normalized = normalizeCommentRating(rating)
return Array.from({ length: 5 }, (_, index) => index < normalized)
}