@social-embed/lib
@social-embed/lib is a zero-dependency JavaScript library for detecting media platforms, extracting IDs from URLs, and generating embeddable URLs. It runs in any JavaScript environment — browsers, Node.js, edge workers.
import { convertUrlToEmbedUrl } from "@social-embed/lib";
convertUrlToEmbedUrl("https://youtu.be/Bd8_vO5zrjo");// "https://www.youtube.com/embed/Bd8_vO5zrjo"Key features
- Universal conversion —
convertUrlToEmbedUrl()handles all providers in one call - Provider detection —
getProviderFromUrl()identifies which platform a URL belongs to - Extensible registry — Add custom providers with
defaultRegistry.register() - Zero dependencies — No npm dependencies, no DOM requirement
- Type-safe — Full TypeScript with exported
EmbedProvidertype andEmbedProviderRegistryclass
What to read next
- Installation — npm, CDN, and bundler setup
- Examples — Universal conversion, per-provider functions, custom providers
- API reference — All exports, types, and function signatures
- Providers — The
EmbedProviderinterface and registry system
How it fits
This library handles steps 1-3 of the social-embed pipeline (detect → extract → build). It is used internally by the <o-embed> web component, but you can use it standalone for:
- Server-side URL validation — Check if a URL is from a recognized provider before storing it
- Custom renderers — Build your own embed UI in React, Vue, Svelte, or any framework
- Content pipelines — Transform URLs in batch processing, API endpoints, or build steps