2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
/** @see {@link https://docs.joinmastodon.org/entities/Status/#Mention} */
|
2024-10-13 15:25:30 -07:00
|
|
|
const mentionSchema = v.object({
|
|
|
|
id: v.string(),
|
|
|
|
username: v.fallback(v.string(), ''),
|
2024-08-28 04:43:23 -07:00
|
|
|
url: z.string().url().catch(''),
|
2024-10-13 15:25:30 -07:00
|
|
|
acct: v.string(),
|
2024-08-28 04:43:23 -07:00
|
|
|
}).transform((mention) => {
|
|
|
|
if (!mention.username) {
|
|
|
|
mention.username = mention.acct.split('@')[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return mention;
|
|
|
|
});
|
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type Mention = v.InferOutput<typeof mentionSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export { mentionSchema, type Mention };
|