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:
When to use it
- Resolving a YouTube video ID from mixed link formats (
watch,youtu.be,embed,/v/, Shorts). - Rendering responsive
iframeembeds from user-submitted YouTube links. - Normalizing arbitrary YouTube URLs into a canonical
watch?v=form. - Displaying video thumbnails without calling the YouTube Data API.
- Validating that a string is a usable YouTube URL or ID before storing or rendering it.