youtube-video-id
v1.0.4
Published
Extracts the YouTube video ID from a URL or string.
Downloads
1,637
Maintainers
Readme
youtube-video-id
:tv: Extract the YouTube video ID from a string or URL:
YouTubeVideoId(string)
Installation
NPM:
npm install youtube-video-id
Yarn:
yarn add youtube-video-id
CDN:
<script src="https://unpkg.com/youtube-video-id@latest/dist/youtube-video-id.min.js"></script>
Usage
Server
Import with ES Modules:
import YouTubeVideoId from 'youtube-video-id';
Or require with CommonJS:
const YouTubeVideoId = require('youtube-video-id').default;
Extract YouTube video ID from URL or string:
YouTubeVideoId('https://www.youtube.com/watch?v=X3pTXG9a1oQ'); // 'X3pTXG9a1oQ'
YouTubeVideoId('https://youtu.be/X3pTXG9a1oQ'); // 'X3pTXG9a1oQ'
YouTubeVideoId('X3pTXG9a1oQ'); // 'X3pTXG9a1oQ'
Client
Load script:
<script src="https://unpkg.com/youtube-video-id@latest/dist/youtube-video-id.min.js"></script>
Extract YouTube video ID from URL or string:
<script>
const videoId = YouTubeVideoId('https://www.youtube.com/watch?v=F2uovvU-dLA');
console.log(videoId);
</script>
Migration
v1
Migrate to TypeScript and build ESM. CommonJS import now requires the .default
key:
const YouTubeVideoId = require('youtube-video-id').default;
Release
Release is automated with Release Please.