UNPKG

@spaced-out/ui-design-system

Version:
36 lines (32 loc) 705 B
// @flow strict export const RATING_ERRORS = Object.freeze({ INVALID_RANGE: { type: 'INVALID_RANGE', description: 'Given rating\'s stop value cannot come before the start value.', }, INVALID_RATING_LABELS: { type: 'INVALID_RATING_LABELS', description: 'Given rating labels are invalid.', }, }); export const RATINGS: Array<string> = [ 'Not-Qualified', 'Proficient', 'Silver', 'Gold', 'Platinum', 'Diamond', ]; export const getRatingLabel = ( rating: number, labels: Array<string>, ): string => { if (rating <= 0) { return labels[0]; } else if (rating >= labels.length) { return labels.slice(-1)[0]; } else { return labels[rating]; } };