npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@andrash/oembed-client

v1.0.3

Published

A TypeScript oEmbed client library for fetching oEmbed data from various providers.

Readme

oEmbed Client

This is a client library for fetching oEmbed information for media URLs from providers like YouTube, Twitter, and Instagram. It handles sending requests to oEmbed services and processing their JSON responses.

Note: This library only supports JSON responses and does not support XML.

中文版請見: oEmbed Client Documentation (Traditional Chinese)

Acknowledgements: This project has adopted and refactored parts of the code and concepts from @extractus/oembed-extractor. Without the contributions of that project's authors, this project would have been difficult to complete. Special thanks to them!

Sponsor: This project is sponsored by Havppen: Create your exclusive "online course platform" and monetize your knowledge now!

Installation

npm install @andrash/oembed-client
# or
yarn add @andrash/oembed-client
# or
pnpm add @andrash/oembed-client

Usage

1. Create a Provider Configuration

The OembedClient does not automatically load any default list of oEmbed service providers. You must first create a provider configuration list to pass to the OembedClient upon initialization.

Here is an example of how to define your provider configurations:

// filepath: oembed-providers.ts
import { ProviderConfig } from "@andrash/oembed-client";

export const OEMBED_PROVIDER_CONFIGS: ProviderConfig[] = [
  // Basic example
  {
    name: "YouTube",
    url: "https://www.youtube.com/",
    endpoints: [
      {
        patterns: [
          "https://*.youtube.com/watch*",
          "https://*.youtube.com/v/*",
          "https://youtu.be/*",
          "https://*.youtube.com/playlist?list=*",
          "https://youtube.com/playlist?list=*",
          "https://*.youtube.com/shorts*",
          "https://youtube.com/shorts*",
          "https://*.youtube.com/embed/*",
          "https://*.youtube.com/live*",
          "https://youtube.com/live*",
        ],
        url: "https://www.youtube.com/oembed",
      },
    ],
  },
  // Advanced example: oEmbed service requiring an access token
  {
    name: "Example",
    url: "https://example.com",
    endpoints: [
      {
        patterns: ["http://example.com/*/p/*", "http://www.example.com/*/p/*"],
        url: "https://graph.example.com/oembed",
        queryParams: {
          // Some oEmbed services (like Facebook, Instagram, Threads) require an access token to authenticate requests. You can add the relevant query parameters here.
          access_token: process.env.EXAMPLE_OEMBED_ACCESS_TOKEN,
          // You can also add other custom query parameters...
        },
        headers: {
          // Some oEmbed services may require authorization information in the headers.
          Authorization: `Bearer ${process.env.EXAMPLE_OEMBED_ACCESS_TOKEN}`,
          // You can also add other custom headers...
        },
      },
    ],
  },

  // Other oEmbed service endpoints...
];

You can copy the example provider list file from this package at oembed-provider.config.ts. It includes many common oEmbed providers and can be modified to suit your needs.

2. Initialize the OembedClient

Create an OembedClient instance, passing your provider configuration list to the constructor:

import { OembedClient } from "@andrash/oembed-client";
import { OEMBED_PROVIDER_CONFIGS } from "./oembed-providers";

const oembedClient = new OembedClient(OEMBED_PROVIDER_CONFIGS);

3. Fetch oEmbed Data

Use the findEndpoint() method to get the correct provider endpoint for a given URL. Then, call the extract() method on the endpoint to fetch the oEmbed data.

const url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
const endpoint = oembedClient.findEndpoint(url);

if (endpoint) {
  try {
    const oembedData = await endpoint.extract(url, {
      // You can pass extra parameters here, such as maxwidth and maxheight.
      // These will be merged with any `queryParams` in your provider config.
      // If a parameter exists in both, the value passed here takes precedence.
      maxwidth: 600,
      maxheight: 400,
    });
    console.log(oembedData);
  } catch (error) {
    console.error("Error fetching oEmbed data:", error);
  }
} else {
  console.log("No matching oEmbed provider found for the URL.");
}

That's it!

You are now ready to use the oEmbed Client to fetch oEmbed data from various providers!