(path: string, ...queryParams: [string, string | null][])
| 52 | * @returns The path with the query parameters added. |
| 53 | */ |
| 54 | export const createPathWithQueryParams = (path: string, ...queryParams: [string, string | null][]) => { |
| 55 | // Filter out undefined values |
| 56 | |
| 57 | queryParams = queryParams.filter(([_key, value]) => value !== null); |
| 58 | |
| 59 | if (queryParams.length === 0) { |
| 60 | return path; |
| 61 | } |
| 62 | |
| 63 | const queryString = queryParams.map(([key, value]) => `${encodeURIComponent(key)}=${encodeRFC3986URIComponent(value ?? '')}`).join('&'); |
| 64 | return `${path}?${queryString}`; |
| 65 | } |
| 66 | |
| 67 | // @see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#encoding_for_rfc3986 |
| 68 | const encodeRFC3986URIComponent = (str: string) => { |
no test coverage detected