UNPKG

@pinuts/bsr-uikit-relaunch

Version:

BSR UI-KIT Relaunch

25 lines (22 loc) 1.03 kB
import { useMemo } from 'react'; import ICON_MAPPING from './AllStaticIcons'; export const getIconByName = (iconName: keyof typeof ICON_MAPPING) => { return ICON_MAPPING[iconName]; }; export const useGetIconByName = (iconName: keyof typeof ICON_MAPPING) => useMemo(() => getIconByName(iconName), [iconName]); // Function to check if the video exists and get the title export const checkVideoExistsAndGetTitle = async (videoId: string): Promise<{ exists: boolean, title?: string }> => { try { const response = await fetch( `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${videoId}&format=json` ); if (!response.ok) { throw new Error('Video not found'); } const data = await response.json(); return { exists: true, title: data.title }; // Return true and the video title if the video exists } catch (err) { return { exists: false }; // Return false if the video does not exist or an error occurs } };