79720706

Date: 2025-07-31 02:35:52
Score: 0.5
Natty:
Report link

Using the 1.5kB library Superenum this is easy:

import { Enum, EnumType } from '@ncoderz/superenum'

enum Color {
    Red, Green
}

const stringToValidate = 'Green';

const validatedDefaultRed = Enum(Color).fromKey(stringToValidate) ?? Color.Red;
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: six5536