react-native-youtube-bridge
Version:
🎥 Easy-to-use YouTube player for React Native with cross-platform support
27 lines (26 loc) • 908 B
JavaScript
;
const MATCH_URL_YOUTUBE = /(?:youtu\.be\/|youtube(?:-nocookie|education)?\.com\/(?:embed\/|v\/|watch\/|watch\?v=|watch\?.+&v=|shorts\/|live\/))((\w|-){11})/;
export const extractVideoIdFromUrl = url => {
if (!url) {
return undefined;
}
const match = url.match(MATCH_URL_YOUTUBE);
return match ? match[1] : undefined;
};
export const validateVideoId = videoId => {
const videoIdRegex = /^[\w-]{11}$/;
return videoIdRegex.test(videoId ?? '');
};
export const escapeHtml = unsafe => {
if (!unsafe) {
return '';
}
return unsafe.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
};
export const safeNumber = (value, defaultValue = 0) => {
if (typeof value !== 'number' || Number.isNaN(value)) {
return defaultValue;
}
return Math.max(0, Math.floor(value));
};
//# sourceMappingURL=validate.js.map