duhhhhhhhh
This commit is contained in:
@@ -43,9 +43,25 @@ export const transformStringToEnum = <T>(anEnum: { [s: string]: string | number
|
||||
|
||||
export const transformCheckEnum = <T>(anEnum: { [s: string]: string | number }) => {
|
||||
return (arg: number | string, ctx: z.RefinementCtx<number | string>) => {
|
||||
if (typeof anEnum[arg] == 'undefined') {
|
||||
ctx.addIssue("Not an enum member");
|
||||
function invalid() {
|
||||
ctx.addIssue("Invalid enum member");
|
||||
}
|
||||
|
||||
if (typeof arg == 'string') {
|
||||
if (typeof anEnum[arg] == 'number') return anEnum[arg] as T;
|
||||
else {
|
||||
invalid();
|
||||
return null;
|
||||
}
|
||||
} else if (typeof arg == 'number') {
|
||||
if (typeof anEnum[arg] == 'string') return arg as T;
|
||||
else {
|
||||
invalid();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
invalid();
|
||||
return null;
|
||||
} else return anEnum[arg] as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user