* Parses the URL argument of a XHR method to a string. * * See: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open#url * url: A string or any other object with a stringifier — including a URL object — that provides the URL of the resource to send the request to. * * @param url
(url: unknown)
| 163 | * @returns The parsed URL string or undefined if the URL is invalid |
| 164 | */ |
| 165 | function parseXhrUrlArg(url: unknown): string | undefined { |
| 166 | if (isString(url)) { |
| 167 | return url; |
| 168 | } |
| 169 | |
| 170 | try { |
| 171 | // If the passed in argument is not a string, it should have a `toString` method as a stringifier. |
| 172 | // If that fails, we just return undefined (like in IE11 where URL is not available) |
| 173 | return (url as URL).toString(); |
| 174 | } catch {} // eslint-disable-line no-empty |
| 175 | |
| 176 | return undefined; |
| 177 | } |