mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
11 lines
435 B
TypeScript
11 lines
435 B
TypeScript
const ROUTE_INDEX_PATTERN = /^(0|[1-9]\d*)$/;
|
|
|
|
export function parseRouteIndexParam(value: string | undefined): number | null {
|
|
// Route indexes must be canonical digits only; parseInt would accept values like "1abc"
|
|
// and could route a malformed URL to a real provider entry.
|
|
if (!value || !ROUTE_INDEX_PATTERN.test(value)) return null;
|
|
|
|
const parsed = Number(value);
|
|
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
}
|