17 lines
349 B
TypeScript
17 lines
349 B
TypeScript
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);
|
|
}
|