Skip to content

Instantly share code, notes, and snippets.

@RoyalIcing
Last active March 4, 2022 05:41
Show Gist options
  • Save RoyalIcing/5cabb793e7e4ba961c00a807323e0afe to your computer and use it in GitHub Desktop.
Save RoyalIcing/5cabb793e7e4ba961c00a807323e0afe to your computer and use it in GitHub Desktop.
YouTube URL YieldParser
function* VideoID() {
const [videoID] = yield /^[a-zA-Z0-9_]+$/;
return videoID;
}
function* Long() {
yield "https://www.youtube.com/watch?v=";
const videoID = yield VideoID;
return videoID;
}
function* Embed() {
yield "https://www.youtube.com/embed/";
const videoID = yield VideoID;
return videoID;
}
function* Short() {
yield "https://youtu.be/";
const videoID = yield VideoID;
return videoID;
}
export function* YouTubeURL() {
const videoID = yield [Long, Embed, Short];
yield mustEnd;
return videoID;
}
// export function* YouTubeEmbed() {
// const videoID = yield YouTubeURL;
// yield importModule("https://cdn.jsdelivr.net/npm/lite-youtube-embed");
// return `<lite-youtube videoid="${videoID}"></lite-youtube>`;
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment