Download next.js/packages/next/src/client/assign-location.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 959 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/client/assign-location.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/client/assign-location.ts
-
curl -L -o assign-location.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/client/assign-location.ts
959 Bytes
| import { addBasePath } from './add-base-path' | |
| /** | |
| * Function to correctly assign location to URL | |
| * | |
| * The method will add basePath, and will also correctly add location (including if it is a relative path) | |
| * @param location Location that should be added to the url | |
| * @param url Base URL to which the location should be assigned | |
| */ | |
| export function assignLocation(location: string, url: URL): URL { | |
| if (location.startsWith('.')) { | |
| const urlBase = url.origin + url.pathname | |
| return new URL( | |
| // In order for a relative path to be added to the current url correctly, the current url must end with a slash | |
| // new URL('./relative', 'https://example.com/subdir').href -> 'https://example.com/relative' | |
| // new URL('./relative', 'https://example.com/subdir/').href -> 'https://example.com/subdir/relative' | |
| (urlBase.endsWith('/') ? urlBase : urlBase + '/') + location | |
| ) | |
| } | |
| return new URL(addBasePath(location), url.href) | |
| } | |