null when the input can’t be resolved.
Installation
Add the package to your project with Bun.Usage
Import the function you need and pass it a URL or an existing video ID. Extract the video ID from any supported YouTube URL:null when the input is neither a recognizable YouTube URL nor a valid-looking video ID, so you can guard before rendering:
Where it comes in handy
The common thread is taking a messy YouTube link and getting something usable out of it. You can resolve a video ID from mixed formats (watch, youtu.be, embed, /v/, Shorts), render an iframe embed from a user-submitted link, or normalize any URL into a canonical watch?v= form. It also builds thumbnail URLs without a call to the YouTube Data API, and since every function returns null on input it can’t resolve, it doubles as a way to check that a string is a usable URL or ID before you store or render it.