| 32 | * @returns {JSON|undefined} The router data or undefined if not found |
| 33 | */ |
| 34 | export function useMatchesData(id: string | string[], debug: boolean = false): UIMatch | undefined { |
| 35 | const matchingRoutes = useMatches(); |
| 36 | |
| 37 | if (debug) { |
| 38 | console.log("matchingRoutes", matchingRoutes); |
| 39 | } |
| 40 | |
| 41 | const paths = Array.isArray(id) ? id : [id]; |
| 42 | |
| 43 | // Get the first matching route |
| 44 | const route = paths.reduce((acc, path) => { |
| 45 | if (acc) return acc; |
| 46 | return matchingRoutes.find((route) => route.id === path); |
| 47 | }, undefined as UIMatch | undefined); |
| 48 | |
| 49 | return route; |
| 50 | } |
| 51 | |
| 52 | export function validateEmail(email: unknown): email is string { |
| 53 | return typeof email === "string" && email.length > 3 && email.includes("@"); |