UNPKG

@r4ai/remark-embed

Version:

[![JSR](https://jsr.io/badges/@r4ai/remark-embed)](https://jsr.io/@r4ai/remark-embed) [![codecov](https://codecov.io/gh/r4ai/remark-embed/graph/badge.svg?token=B9EZXC0PR8)](https://codecov.io/gh/r4ai/remark-embed) [![CI](https://github.com/r4ai/remark-emb

52 lines (51 loc) 1.59 kB
import * as v from "valibot"; export const OEmbedBaseSchema = v.object({ version: v.string(), title: v.optional(v.string()), author_name: v.optional(v.string()), author_url: v.optional(v.string()), provider_name: v.optional(v.string()), provider_url: v.optional(v.string()), cache_age: v.optional(v.union([v.number(), v.pipe(v.string(), v.transform(Number.parseInt))])), thumbnails: v.optional(v.tuple([ v.object({ url: v.optional(v.string()), width: v.optional(v.number()), height: v.optional(v.number()), }), ])), }); export const OEmbedPhotoSchema = v.object({ ...OEmbedBaseSchema.entries, type: v.literal("photo"), url: v.string(), width: v.number(), height: v.number(), }); export const OEmbedVideoSchema = v.object({ ...OEmbedBaseSchema.entries, type: v.literal("video"), html: v.string(), width: v.number(), height: v.number(), }); export const OEmbedLinkSchema = v.object({ ...OEmbedBaseSchema.entries, type: v.literal("link"), }); export const OEmbedRichSchema = v.object({ ...OEmbedBaseSchema.entries, type: v.literal("rich"), html: v.string(), // `width` and `height` are required in OEmbed specification. // However, Twitter OEmbed API returns `null`. // https://developer.x.com/en/docs/x-for-websites/oembed-api width: v.nullable(v.number()), height: v.nullable(v.number()), }); export const OEmbedSchema = v.union([ OEmbedPhotoSchema, OEmbedVideoSchema, OEmbedLinkSchema, OEmbedRichSchema, ]);