bigbuffet-rw/app/soapbox/schemas/mention.ts

18 lines
386 B
TypeScript
Raw Normal View History

2023-05-04 10:13:39 -07:00
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 };