New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@social-embed/lib

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@social-embed/lib

URL detection and parsing for embed providers (YouTube, other OEmbed compatible providers),

  • 0.1.0-next.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
123
decreased by-56.69%
Maintainers
0
Weekly downloads
 
Created
Source

@social-embed/lib · GitHub license npm version

A lightweight, browser-friendly utility that parses common media URLs (YouTube, Vimeo, Spotify, etc.) and converts them into embeddable links or extracts relevant IDs.

Installation

NPM:

npm i @social-embed/lib

yarn:

yarn add @social-embed/lib

pnpm:

pnpm add @social-embed/lib

Using a CDN

If your environment supports ESM or direct URL imports, you can pull from a CDN:

unpkg:

import { getYouTubeIdFromUrl } from "https://www.unpkg.com/@social-embed/lib?module";

skypack:

import { getYouTubeIdFromUrl } from "https://cdn.skypack.dev/@social-embed/lib";

Usage

Below is a simple TypeScript example demonstrating some core functions:

import {
  convertUrlToEmbedUrl,
  getYouTubeIdFromUrl,
  getDailyMotionIdFromUrl,
  getDailyMotionEmbedFromId,
} from "@social-embed/lib";

// 1. Convert any recognized media URL into its embeddable form
console.log(
  convertUrlToEmbedUrl("https://www.youtube.com/watch?v=Bd8_vO5zrjo"),
);
// Output: "https://www.youtube.com/embed/Bd8_vO5zrjo"

// 2. Extract YouTube video ID
console.log(getYouTubeIdFromUrl("https://youtu.be/Bd8_vO5zrjo"));
// Output: "Bd8_vO5zrjo"

// 3. DailyMotion usage
console.log(
  getDailyMotionIdFromUrl("https://www.dailymotion.com/video/x7znrd0"),
);
// Output: "x7znrd0"

console.log(getDailyMotionEmbedFromId("x7znrd0"));
// Output: "https://www.dailymotion.com/embed/video/x7znrd0"

More Examples

Spotify

console.log(convertUrlToEmbedUrl("spotify:album:1DFixLWuPkv3KT3TnV35m3"));
// "https://open.spotify.com/embed/album/1DFixLWuPkv3KT3TnV35m3"

Vimeo

console.log(convertUrlToEmbedUrl("vimeo.com/channels/staffpicks/134668506"));
// "https://player.vimeo.com/video/134668506"

Loom

console.log(
  convertUrlToEmbedUrl("loom.com/share/e883f70b219a49f6ba7fbeac71a72604"),
);
// "https://www.loom.com/embed/e883f70b219a49f6ba7fbeac71a72604"

EdPuzzle

console.log(
  convertUrlToEmbedUrl("edpuzzle.com/media/606b413369971e424ec6021e"),
);
// "https://edpuzzle.com/embed/media/606b413369971e424ec6021e"

Wistia

console.log(
  convertUrlToEmbedUrl("https://support.wistia.com/medias/26sk4lmiix"),
);
// "https://fast.wistia.net/embed/iframe/26sk4lmiix"

Validate Any URL

import { isValidUrl } from "@social-embed/lib";

console.log(isValidUrl("https://apple.com")); // true
console.log(isValidUrl("notaurl")); // false

Try It Out

Keywords

FAQs

Package last updated on 05 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc