| export function coerceIdentityValue( | |
| value: string | undefined, | |
| maxLength: number, | |
| ): string | undefined { | |
| if (typeof value !== "string") { | |
| return undefined; | |
| } | |
| const trimmed = value.trim(); | |
| if (!trimmed) { | |
| return undefined; | |
| } | |
| if (trimmed.length <= maxLength) { | |
| return trimmed; | |
| } | |
| return trimmed.slice(0, maxLength); | |
| } | |