Value를 Enum으로 변환
Enum을 Value로 변환
const statusMapper = createEnumMapper({
PENDING: ProcessingStatus.PENDING,
IN_PROGRESS: ProcessingStatus.IN_PROGRESS,
COMPLETED: ProcessingStatus.COMPLETED,
});
// 사용
const status = statusMapper.fromValue('PENDING'); // ProcessingStatus.PENDING
const value = statusMapper.toValue(ProcessingStatus.PENDING); // 'PENDING'
// unknown 값 처리
const status = statusMapper.fromValue('UNKNOWN'); // undefined
const safeStatus = statusMapper.fromValue(response.status) ?? ProcessingStatus.PENDING;
백엔드 Value 타입(SCREAMING_SNAKE_CASE)과 프론트엔드 Enum(kebab-case)을 양방향 변환
unknown 값이 오면 undefined 반환 (앱 크래시 방지) 호출하는 쪽에서 nullish coalescing으로 처리