
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
prefix-enum
Advanced tools
카테고리별로 prefix를 붙여 고유한 enum 키를 생성하고 관리하는 TypeScript 라이브러리. 포맷 불일치와 중복 값 충돌 문제를 해결합니다.
prefix-enum은 카테고리 기반 prefix 규칙을 통해 고유한 enum 키를 생성하고 관리하는 TypeScript 유틸리티 라이브러리입니다. 여러 enum 그룹을 통합하고 포맷을 자동 정규화하여 중복 충돌 · 포맷 불일치 · 복잡한 매핑 로직을 해결합니다.
실제 서비스 환경에서 다양한 enum을 통합하여 사용할 때 다음 문제가 발생합니다:
[Next.js] 중복 ENUM 값 충돌로 인해 발생한 키워드 매핑 오류 해결하기
[Next.js] ENUM 키워드 매핑 실패로 인해 발생한 한글 변환 오류 해결하기
TRYING_TO_QUIT) 사용으로 인한 충돌preferredPeople)과 enum 키(PREFERRED_PEOPLE_RELIABLE) 포맷 불일치prefix-enum은 다음과 같은 기능을 제공합니다:
| 기능 | 설명 |
|---|---|
| Prefix 기반 고유한 키 생성 | SMOKING_TRYING_TO_QUIT, DRINKING_TRYING_TO_QUIT |
| Key 포맷 자동 정규화 | 모든 입력 포맷을 SNAKE_CASE로 통일 |
| 여러 enum 그룹 통합 | buildKeywordMap으로 자동 병합 및 중복 검사 |
| TypeScript enum 지원 | enum 객체 그대로 전달 가능 |
| 타입 안전성 | strict 타입 체크, 자동완성, 컴파일 타임 오류 감지 |
| 매핑 실패 옵션 | fallback, strict, debug 처리 방식 지원 |
npm install prefix-enum
# or
pnpm add prefix-enum
# or
yarn add prefix-enum
import { prefixEnum, buildKeywordMap, getKeywordLabel } from "prefix-enum";
const smoking = prefixEnum("SMOKING", {
TRYING_TO_QUIT: "금연중",
NEVER: "비흡연",
});
const drinking = prefixEnum("DRINKING", {
TRYING_TO_QUIT: "금주중",
NEVER: "비음주",
});
const keywordMap = buildKeywordMap([smoking, drinking]);
getKeywordLabel(keywordMap, "SMOKING_TRYING_TO_QUIT"); // "금연중"
getKeywordLabel(keywordMap, "DRINKING_TRYING_TO_QUIT"); // "금주중"
enum SmokingEnum {
TRYING_TO_QUIT = "TRYING_TO_QUIT",
NEVER = "NEVER",
}
enum DrinkingEnum {
TRYING_TO_QUIT = "TRYING_TO_QUIT",
NEVER = "NEVER",
}
const map = buildKeywordMap({
SMOKING: SmokingEnum,
DRINKING: DrinkingEnum,
});
map["SMOKING_TRYING_TO_QUIT"]; // 사용 가능
prefixEnum(category, definitions, options?)카테고리 prefix가 적용된 고유 키와 라벨 매핑 객체를 생성합니다.
const result = prefixEnum("userRole", {
admin: "Admin User",
member: "Member User",
});
result.keys.admin; // "USER_ROLE_ADMIN"
result.map["USER_ROLE_ADMIN"].label; // "Admin User"
buildKeywordMap(sources | enumGroups, options?)여러 PrefixEnumResult 또는 enum 그룹 객체를 하나의 매핑 테이블로 조립합니다.
const map = buildKeywordMap({
SMOKING: SmokingEnum,
DRINKING: DrinkingEnum,
});
getKeywordLabel(source, key, options?)매핑된 라벨을 반환하거나 옵션에 따라 fallback/strict 처리합니다.
getKeywordLabel(map, "SMOKING_TRYING_TO_QUIT"); // "금연중"
getKeywordLabel(map, "UNKNOWN_KEY", { fallback: "알 수 없음" }); // fallback 반환
getKeywordLabel(map, "UNKNOWN_KEY", { strict: true }); // Error throw
normalizeCategory(category)카테고리 문자열을 대문자 SNAKE_CASE로 정규화합니다.
normalizeCategory("preferredPeople"); // "PREFERRED_PEOPLE"
normalizeCategory("preferred-people"); // "PREFERRED_PEOPLE"
| 옵션 | 설명 |
|---|---|
fallback | 키 조회 실패 시 기본 텍스트 반환 |
strict | 매핑 실패 시 즉시 오류 throw |
debug | 경고 메시지 출력 |
formatLabel | 라벨 생성 커스텀 formatter |
prefix-enum/
├── src/
├── tests/
├── dist/
├── tsconfig.json
├── tsup.config.ts
└── vitest.config.ts
.github/workflows/ci.yml GitHub Actions가 pnpm lint, pnpm test, pnpm build를 Node.js 18.x / 20.x 환경에서 자동으로 실행합니다.pnpm install
pnpm lint
pnpm test
pnpm build
ISC License Copyright (c)
GitHub Repository: https://github.com/dani1552/prefix-enum
Issues: https://github.com/dani1552/prefix-enum/issues
FAQs
카테고리별로 prefix를 붙여 고유한 enum 키를 생성하고 관리하는 TypeScript 라이브러리. 포맷 불일치와 중복 값 충돌 문제를 해결합니다.
We found that prefix-enum demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.