url.
const SERVICE_REGEXP = {
facebook: /https?:\/\/(?:www\.)?facebook\.com/i,
instagram: /https?:\/\/(?:www\.)?instagram\.com\/(p|tv|reel)\//i,
soundcloud: /https?:\/\/(?:(?:api(?:-v2)?|m|p|player|w|www)\.)?soundcloud\.com\//i,
tiktok: /https?:\/\/(?:www\.)?tiktok\.com\//i,
vimeo: /https?:\/\/(?:(?:www|player)\.)?vimeo(?:pro)?\.com\//i,
youtube: /(https?:\/\/)?((www|m)\.)?(youtu\.?be(.com)?)/i,
};
function getServiceByUrl(url) {
}
getServiceByUrl("https://www.youtube.com/watch?v=r_awY1w0kDk") // должна вернуть "youtube"
getServiceByUrl("https://www.instagram.com/reel/Cdv1W8Pgv0E/?igshid=YmMyMTA2M2Y=") // должна вернуть "instagram"
// и так далее...
Мне кажется проще парсить url через new URL(urlString)
Обсуждают сегодня