( querystring?: string | null )
| 4 | * @param querystring - The querystring to parse, also known as the "search" string. |
| 5 | */ |
| 6 | export function parseQueryString( |
| 7 | querystring?: string | null |
| 8 | ): Record<string, string[]> { |
| 9 | const query: Record<string, string[]> = Object.create(null); |
| 10 | if (!querystring || !querystring.startsWith('?') || querystring === '?') { |
| 11 | return query; |
| 12 | } |
| 13 | const params = querystring.slice(1).split('&'); |
| 14 | for (const param of params) { |
| 15 | let [key, value] = param.split('='); |
| 16 | if (key !== undefined) { |
| 17 | key = decodeURIComponent(key); |
| 18 | } |
| 19 | if (value !== undefined) { |
| 20 | value = decodeURIComponent(value); |
| 21 | } |
| 22 | |
| 23 | let existing = query[key]; |
| 24 | if (!existing) { |
| 25 | existing = []; |
| 26 | query[key] = existing; |
| 27 | } |
| 28 | |
| 29 | existing.push(value); |
| 30 | } |
| 31 | return query; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * This function is necessary to account for the difference between |
no test coverage detected