(url: string)
| 367 | |
| 368 | /** Extract the query params from an URL. */ |
| 369 | export function extractQueryParamsFromUrl(url: string): string | undefined { |
| 370 | // url is path and query string |
| 371 | if (!url) { |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | try { |
| 376 | // The `URL` constructor can't handle internal URLs of the form `/some/path/here`, so stick a dummy protocol and |
| 377 | // hostname as the base. Since the point here is just to grab the query string, it doesn't matter what we use. |
| 378 | const queryParams = new URL(url, 'http://s.io').search.slice(1); |
| 379 | return queryParams.length ? queryParams : undefined; |
| 380 | } catch { |
| 381 | return undefined; |
| 382 | } |
| 383 | } |
no test coverage detected