bigbuffet-rw/packages/pl-api/lib/entities/mention.ts
marcin mikołajczak bc65755862 pl-api: Update docs
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-11-29 16:01:54 +01:00

28 lines
593 B
TypeScript

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