UNPKG

react-native-youtube-bridge

Version:

🎥 Easy-to-use YouTube player for React Native with cross-platform support

27 lines (26 loc) • 908 B
"use strict"; 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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;'); }; 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