Download next.js/packages/next/src/server/normalizers/request/prefix.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 880 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/normalizers/request/prefix.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/server/normalizers/request/prefix.ts
-
curl -L -o prefix.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/normalizers/request/prefix.ts
880 Bytes
| import type { Normalizer } from '../normalizer' | |
| export class PrefixPathnameNormalizer implements Normalizer { | |
| constructor(private readonly prefix: string) { | |
| if (prefix.endsWith('/')) { | |
| throw new Error( | |
| `PrefixPathnameNormalizer: prefix "${prefix}" should not end with a slash` | |
| ) | |
| } | |
| } | |
| public match(pathname: string) { | |
| // If the pathname doesn't start with the prefix, we don't match. | |
| if (pathname !== this.prefix && !pathname.startsWith(this.prefix + '/')) { | |
| return false | |
| } | |
| return true | |
| } | |
| public normalize(pathname: string, matched?: boolean): string { | |
| // If we're not matched and we don't match, we don't need to normalize. | |
| if (!matched && !this.match(pathname)) return pathname | |
| if (pathname.length === this.prefix.length) { | |
| return '/' | |
| } | |
| return pathname.substring(this.prefix.length) | |
| } | |
| } | |