Created
January 22, 2019 09:59
-
-
Save nanodracula/8ae097f70ce3ba3d513fd6a77fa384bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Convert URL from Youtube video for URL for embeding. | |
| * | |
| * @param {string} videoUrl - URL of Youtube VIdeo | |
| */ | |
| function makeYoutubeEmbed(videoUrl) { | |
| if (typeof videoUrl !== 'string') { | |
| return undefined | |
| } | |
| const getId = (url) => { | |
| const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ | |
| const match = url.match(regExp) | |
| if (match && match[2].length == 11) { | |
| return match[2] | |
| } | |
| } | |
| const id = getId(videoUrl) | |
| if (id) { | |
| return '//www.youtube.com/embed/' + id | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment