Download next.js/packages/next/src/server/request/fallback-params.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/request/fallback-params.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/server/request/fallback-params.ts
-
curl -L -o fallback-params.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/request/fallback-params.ts
1.15 kB
| import { getRouteMatcher } from '../../shared/lib/router/utils/route-matcher' | |
| import { getRouteRegex } from '../../shared/lib/router/utils/route-regex' | |
| export type FallbackRouteParams = ReadonlyMap<string, string> | |
| function getParamKeys(page: string) { | |
| const pattern = getRouteRegex(page) | |
| const matcher = getRouteMatcher(pattern) | |
| // Get the default list of allowed params. | |
| return Object.keys(matcher(page)) | |
| } | |
| export function getFallbackRouteParams( | |
| pageOrKeys: string | readonly string[] | |
| ): FallbackRouteParams | null { | |
| let keys: readonly string[] | |
| if (typeof pageOrKeys === 'string') { | |
| keys = getParamKeys(pageOrKeys) | |
| } else { | |
| keys = pageOrKeys | |
| } | |
| // If there are no keys, we can return early. | |
| if (keys.length === 0) return null | |
| const params = new Map<string, string>() | |
| // As we're creating unique keys for each of the dynamic route params, we only | |
| // need to generate a unique ID once per request because each of the keys will | |
| // be also be unique. | |
| const uniqueID = Math.random().toString(16).slice(2) | |
| for (const key of keys) { | |
| params.set(key, `%%drp:${key}:${uniqueID}%%`) | |
| } | |
| return params | |
| } | |