bigbuffet-rw/packages/pl-api/lib/entities/mention.ts
marcin mikołajczak a6bc160caa pl-api: Do some blind search and replace
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-14 00:25:30 +02:00

19 lines
479 B
TypeScript

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