(url: string)
| 212 | * @returns parsed URL object |
| 213 | */ |
| 214 | export function parseUrl(url: string): PartialURL { |
| 215 | if (!url) { |
| 216 | return {}; |
| 217 | } |
| 218 | |
| 219 | const match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/); |
| 220 | |
| 221 | if (!match) { |
| 222 | return {}; |
| 223 | } |
| 224 | |
| 225 | // coerce to undefined values to empty string so we don't get 'undefined' |
| 226 | const query = match[6] || ''; |
| 227 | const fragment = match[8] || ''; |
| 228 | return { |
| 229 | host: match[4], |
| 230 | path: match[5], |
| 231 | protocol: match[2], |
| 232 | search: query, |
| 233 | hash: fragment, |
| 234 | relative: match[5] + query + fragment, // everything minus origin |
| 235 | }; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Strip the query string and fragment off of a given URL or path (if present) |
no test coverage detected