Files
ViGent2/frontend/src/shared/lib/title.ts
Kevin Wong 0a5a17402c 更新
2026-02-24 16:55:29 +08:00

19 lines
567 B
TypeScript

export const TITLE_MAX_LENGTH = 15;
export const SECONDARY_TITLE_MAX_LENGTH = 20;
export const clampTitle = (value: string, maxLength: number = TITLE_MAX_LENGTH) =>
value.slice(0, maxLength);
export const clampSecondaryTitle = (value: string, maxLength: number = SECONDARY_TITLE_MAX_LENGTH) =>
value.slice(0, maxLength);
export const applyTitleLimit = (
prev: string,
next: string,
maxLength: number = TITLE_MAX_LENGTH
) => {
if (next.length <= maxLength) return next;
if (prev.length >= maxLength) return prev;
return next.slice(0, maxLength);
};