mirror of
https://github.com/murashit/codex-panel.git
synced 2026-07-22 17:30:31 +00:00
26 lines
803 B
TypeScript
26 lines
803 B
TypeScript
export function truncate(value: string, maxLength: number): string {
|
|
return value.length > maxLength ? `${value.slice(0, maxLength - 1)}...` : value;
|
|
}
|
|
|
|
export function jsonPreview(value: unknown): string {
|
|
try {
|
|
return JSON.stringify(value, null, 2);
|
|
} catch {
|
|
return String(value);
|
|
}
|
|
}
|
|
|
|
export function definedProp<Key extends string, Value>(
|
|
key: Key,
|
|
value: Value | null | undefined,
|
|
): Record<Key, Value> | Record<string, never> {
|
|
return value === null || value === undefined ? {} : ({ [key]: value } as Record<Key, Value>);
|
|
}
|
|
|
|
export function errorMessage(error: unknown): string {
|
|
return error instanceof Error ? error.message : String(error);
|
|
}
|
|
|
|
export function shortThreadId(threadId: string): string {
|
|
return threadId.length <= 8 ? threadId : threadId.slice(0, 8);
|
|
}
|