Download src/lib/helpers/validateVideoId.ts from cursorpro/upd: direct link, hf CLI and curl.
- Browser
- Download file 798 Bytes
-
https://huggingface.co/spaces/cursorpro/upd/resolve/main/src/lib/helpers/validateVideoId.ts
- Command line
-
hf download hf://spaces/cursorpro/upd/src/lib/helpers/validateVideoId.ts
-
curl -L -o validateVideoId.ts https://huggingface.co/spaces/cursorpro/upd/resolve/main/src/lib/helpers/validateVideoId.ts
798 Bytes
| /** | |
| * Validates a YouTube video ID format | |
| * YouTube video IDs are 11 characters long and contain alphanumeric characters, hyphens, and underscores | |
| * Reference: https://webapps.stackexchange.com/questions/54443/format-for-id-of-youtube-video | |
| * | |
| * @param videoId - The video ID to validate | |
| * @returns true if the video ID is valid, false otherwise | |
| */ | |
| export const validateVideoId = (videoId: string): boolean => { | |
| // Handle null, undefined, or non-string values | |
| if (!videoId || typeof videoId !== "string") { | |
| return false; | |
| } | |
| // YouTube video IDs are exactly 11 characters | |
| if (videoId.length !== 11) { | |
| return false; | |
| } | |
| // Valid characters: A-Z, a-z, 0-9, -, _ | |
| const validPattern = /^[A-Za-z0-9_-]{11}$/; | |
| return validPattern.test(videoId); | |
| }; | |