Download wp-calypso/client/lib/build-url/index.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 767 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/build-url/index.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/build-url/index.ts
-
curl -L -o index.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/build-url/index.ts
767 Bytes
| /** | |
| * Given an absolute or relative URL and search terms, returns a relative URL including | |
| * the search query parameter and preserving existing parameters. | |
| * @param uri URL or path to modify | |
| * @param search Search terms | |
| * @returns Path including search terms | |
| */ | |
| export function buildRelativeSearchUrl( uri: string, search: string ): string { | |
| // We only care about the relative part, but the URL API only deals with absolute URLs, | |
| // so we need to provide a dummy domain. | |
| const parsedUrl = new URL( uri, 'http://dummy.example' ); | |
| if ( search ) { | |
| parsedUrl.searchParams.set( 's', search ); | |
| } else { | |
| parsedUrl.searchParams.delete( 's' ); | |
| } | |
| return `${ parsedUrl.pathname }${ parsedUrl.search }${ parsedUrl.hash }`.replace( /%20/g, '+' ); | |
| } | |