/** * Route parameter and query parsing helpers * Centralizes route param type handling to avoid runtime checks in components */ import type { LocationQueryValue } from 'vue-router' /** * Parse a route param (string | string[] | undefined) to a number ID * Returns null if param is missing or invalid */ export function parseRouteId(param: string | string[] | undefined): number | null { if (!param) return null const str = Array.isArray(param) ? param[0] : param if (!str) return null const id = parseInt(str, 10) return isNaN(id) || id < 0 ? null : id } /** * Parse a route query param to a string * Returns empty string if param is missing, null, or is an array */ export function parseQueryString(param: LocationQueryValue | LocationQueryValue[] | undefined): string { if (!param) return '' return Array.isArray(param) ? '' : param }