bigbuffet-rw/packages/pl-api/lib/entities/mention.ts
marcin mikołajczak 036fa32cd3 Add pl-api to workspace
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-08-28 13:43:23 +02:00

19 lines
462 B
TypeScript

import { z } from 'zod';
/** @see {@link https://docs.joinmastodon.org/entities/Status/#Mention} */
const mentionSchema = z.object({
id: z.string(),
username: z.string().catch(''),
url: z.string().url().catch(''),
acct: z.string(),
}).transform((mention) => {
if (!mention.username) {
mention.username = mention.acct.split('@')[0];
}
return mention;
});
type Mention = z.infer<typeof mentionSchema>;
export { mentionSchema, type Mention };