Skip to content
0

katanakit-js / useGetYoutubeVideoId

Function: useGetYoutubeVideoId() ​

ts
function useGetYoutubeVideoId(input): string | null;

Defined in: src/core/services/media.service.ts:54

Extracts a YouTube video id from a watch / shorts / live / embed / youtu.be URL or a bare 11-char id. Returns null when not matched.

Parameters ​

ParameterTypeDescription
inputstringURL or bare video id.

Returns ​

string | null

The 11-char video id or null.

Example ​

ts
useGetYoutubeVideoId("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); // "dQw4w9WgXcQ"
useGetYoutubeVideoId("https://youtu.be/dQw4w9WgXcQ"); // "dQw4w9WgXcQ"
useGetYoutubeVideoId("dQw4w9WgXcQ"); // "dQw4w9WgXcQ"

Released under the MIT License.