( origUrl: string, queryParams: Record<PropertyKey, unknown> )
| 15 | export const TAG_VALUE_ESCAPE_PATTERN = '[:\\s\\(\\)\\\\"]'; |
| 16 | |
| 17 | export function addQueryParamsToExistingUrl( |
| 18 | origUrl: string, |
| 19 | queryParams: Record<PropertyKey, unknown> |
| 20 | ): string { |
| 21 | const url = safeURL(origUrl); |
| 22 | |
| 23 | if (!url) { |
| 24 | return ''; |
| 25 | } |
| 26 | |
| 27 | const searchEntries = url.searchParams.entries(); |
| 28 | // Order the query params alphabetically. |
| 29 | // Otherwise ``queryString`` orders them randomly and it's impossible to test. |
| 30 | const params = JSON.parse(JSON.stringify(queryParams)); |
| 31 | const query = {...Object.fromEntries(searchEntries), ...params}; |
| 32 | |
| 33 | return `${url.protocol}//${url.host}${url.pathname}?${qs.stringify(query)}`; |
| 34 | } |
| 35 | |
| 36 | export type QueryValue = string | string[] | undefined | null; |
| 37 |
no test coverage detected