bigbuffet-rw/packages/pl-api/lib/entities/mention.ts
2024-10-14 20:54:44 +02:00

19 lines
496 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: v.fallback(v.pipe(v.string(), v.url()), ''),
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 };