화면관리 중간 커밋
This commit is contained in:
56
backend-node/src/utils/generateId.ts
Normal file
56
backend-node/src/utils/generateId.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* 고유 ID 생성 유틸리티
|
||||
*/
|
||||
|
||||
/**
|
||||
* UUID v4 생성
|
||||
*/
|
||||
export function generateUUID(): string {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 짧은 고유 ID 생성 (8자리)
|
||||
*/
|
||||
export function generateShortId(): string {
|
||||
return Math.random().toString(36).substring(2, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 긴 고유 ID 생성 (16자리)
|
||||
*/
|
||||
export function generateLongId(): string {
|
||||
return Math.random().toString(36).substring(2, 18);
|
||||
}
|
||||
|
||||
/**
|
||||
* 기본 ID 생성 (UUID v4)
|
||||
*/
|
||||
export function generateId(): string {
|
||||
return generateUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* 타임스탬프 기반 ID 생성
|
||||
*/
|
||||
export function generateTimestampId(): string {
|
||||
return Date.now().toString(36) + Math.random().toString(36).substring(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 컴포넌트 ID 생성 (화면관리 시스템용)
|
||||
*/
|
||||
export function generateComponentId(prefix: string = "comp"): string {
|
||||
return `${prefix}_${generateShortId()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 화면 ID 생성 (화면관리 시스템용)
|
||||
*/
|
||||
export function generateScreenId(prefix: string = "screen"): string {
|
||||
return `${prefix}_${generateShortId()}`;
|
||||
}
|
||||
Reference in New Issue
Block a user