add helper function to extract strings

This commit is contained in:
Alex Holliday committed 2026-04-23 11:07:01 -07:00
1 parent 8bfffd540d
commit f2e3640e28
2 files changed
+11 -3

No files matched your search

@@ -29,6 +29,14 @@ export const optionalString = (value: unknown, fieldName: string): string | unde
throw new AppError({ message: `${fieldName} must be a string`, status: 400 });
};
export const extractString = (value: unknown): string | undefined => {
const candidate = Array.isArray(value) ? value[0] : value;
if (typeof candidate !== "string" || candidate.length === 0) {
return undefined;
}
return candidate;
};
export const optionalNumber = (value: unknown, fieldName: string): number | undefined => {
if (value === undefined) {
return undefined;