0.1.0-next.10 • Published 6 months ago
@social-embed/lib v0.1.0-next.10
@social-embed/lib
·

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
0.1.0-next.8
6 months ago
0.1.0-next.9
6 months ago
0.1.0-next.10
6 months ago
0.1.0-next.4
2 years ago
0.1.0-next.5
2 years ago
0.1.0-next.7
2 years ago
0.1.0-next.3
2 years ago
0.1.0-next.0
2 years ago
0.1.0-next.1
2 years ago
0.1.0-next.2
2 years ago
0.0.2-next.1
3 years ago
0.0.2-next.0
3 years ago
0.0.1-next.12
4 years ago
0.0.1-next.11
4 years ago
0.0.1-next.10
4 years ago
0.0.1-next.9
4 years ago
0.0.1-next.8
4 years ago
0.0.1-next.7
4 years ago
0.0.1-next.6
4 years ago
0.0.1-next.5
4 years ago
0.0.1-next.4
4 years ago