79720712

Date: 2025-07-31 02:42:54
Score: 0.5
Natty:
Report link

Using the 1.5kB library Superenum this is easy:

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

export const MESSAGE_TYPE = {
    INFO: 1,
    SUCCESS: 2,
    WARNING: 3,
    ERROR: 4,
};

const validatedValue = Enum(MESSAGE_TYPE).fromValue(3); // 3

const badValue = Enum(MESSAGE_TYPE).fromValue(7); // undefined
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: six5536