bigbuffet-rw/app/soapbox/schemas/mention.ts
2023-05-04 12:13:39 -05:00

18 lines
No EOL
386 B
TypeScript

import { z } from 'zod';
const mentionSchema = z.object({
acct: z.string(),
id: z.string(),
url: z.string().url().catch(''),
username: z.string().catch(''),
}).transform((mention) => {
if (!mention.username) {
mention.username = mention.acct.split('@')[0];
}
return mention;
});
type Mention = z.infer<typeof mentionSchema>;
export { mentionSchema, type Mention };