{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "is-valid-url", "description": "A utility function to check if a string is a valid URL.", "files": [ { "path": "src/registry/new-york/lib/is-valid-url.ts", "content": "/**\n * Check if a string is a valid URL.\n * @param url - The URL string to validate.\n * @param options - Configuration options for validation.\n * @param options.allowRelative - Whether to allow relative URLs (default: false).\n * @param options.protocols - Array of allowed protocols (default: ['http', 'https']).\n * @returns True if the URL is valid, false otherwise.\n */\n\nexport function isValidURL(\n url: string,\n options: {\n allowRelative?: boolean;\n protocols?: string[];\n } = {},\n): boolean {\n const { allowRelative = false, protocols = [\"http\", \"https\"] } = options;\n\n if (!url || typeof url !== \"string\") {\n return false;\n }\n\n // Handle relative URLs\n if (allowRelative && url.startsWith(\"/\")) {\n return true;\n }\n\n try {\n const urlObj = new URL(url);\n\n // Check if protocol is allowed\n const protocol = urlObj.protocol.slice(0, -1); // Remove trailing ':'\n return protocols.includes(protocol);\n } catch {\n return false;\n }\n}\n", "type": "registry:lib" } ], "type": "registry:lib" }