|
| 1 | +/** |
| 2 | + * @file url.d.ts |
| 3 | + * Type definitions for URL/URLSearchParams |
| 4 | + * |
| 5 | + * @author Tom Tang <[email protected]> |
| 6 | + * @date August 2023 |
| 7 | + */ |
| 8 | + |
| 9 | +/*! |
| 10 | + * Modified from https://www.npmjs.com/package/@types/web |
| 11 | + * Apache License 2.0 |
| 12 | + */ |
| 13 | + |
| 14 | +/** |
| 15 | + * The URL interface represents an object providing static methods used for creating object URLs. |
| 16 | + * |
| 17 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL) |
| 18 | + */ |
| 19 | +export interface URL { |
| 20 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hash) */ |
| 21 | + hash: string; |
| 22 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/host) */ |
| 23 | + host: string; |
| 24 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hostname) */ |
| 25 | + hostname: string; |
| 26 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/href) */ |
| 27 | + href: string; |
| 28 | + toString(): string; |
| 29 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/origin) */ |
| 30 | + readonly origin: string; |
| 31 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/password) */ |
| 32 | + password: string; |
| 33 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/pathname) */ |
| 34 | + pathname: string; |
| 35 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/port) */ |
| 36 | + port: string; |
| 37 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/protocol) */ |
| 38 | + protocol: string; |
| 39 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/search) */ |
| 40 | + search: string; |
| 41 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/searchParams) */ |
| 42 | + readonly searchParams: URLSearchParams; |
| 43 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/username) */ |
| 44 | + username: string; |
| 45 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/toJSON) */ |
| 46 | + toJSON(): string; |
| 47 | +} |
| 48 | + |
| 49 | +export declare var URL: { |
| 50 | + prototype: URL; |
| 51 | + new(url: string | URL, base?: string | URL): URL; |
| 52 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */ |
| 53 | + canParse(url: string | URL, base?: string): boolean; |
| 54 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/createObjectURL_static) @deprecated not implemented by polyfill */ |
| 55 | + // @ts-expect-error types not defined |
| 56 | + createObjectURL(obj: Blob | MediaSource): string; |
| 57 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/revokeObjectURL_static) @deprecated not implemented by polyfill */ |
| 58 | + revokeObjectURL(url: string): void; |
| 59 | +}; |
| 60 | + |
| 61 | +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams) */ |
| 62 | +export interface URLSearchParams { |
| 63 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/size) */ |
| 64 | + readonly size: number; |
| 65 | + /** |
| 66 | + * Appends a specified key/value pair as a new search parameter. |
| 67 | + * |
| 68 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/append) |
| 69 | + */ |
| 70 | + append(name: string, value: string): void; |
| 71 | + /** |
| 72 | + * Deletes the given search parameter, and its associated value, from the list of all search parameters. |
| 73 | + * |
| 74 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/delete) |
| 75 | + */ |
| 76 | + delete(name: string, value?: string): void; |
| 77 | + /** |
| 78 | + * Returns the first value associated to the given search parameter. |
| 79 | + * |
| 80 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/get) |
| 81 | + */ |
| 82 | + get(name: string): string | null; |
| 83 | + /** |
| 84 | + * Returns all the values association with a given search parameter. |
| 85 | + * |
| 86 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll) |
| 87 | + */ |
| 88 | + getAll(name: string): string[]; |
| 89 | + /** |
| 90 | + * Returns a Boolean indicating if such a search parameter exists. |
| 91 | + * |
| 92 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/has) |
| 93 | + */ |
| 94 | + has(name: string, value?: string): boolean; |
| 95 | + /** |
| 96 | + * Sets the value associated to a given search parameter to the given value. If there were several values, delete the others. |
| 97 | + * |
| 98 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/set) |
| 99 | + */ |
| 100 | + set(name: string, value: string): void; |
| 101 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/sort) */ |
| 102 | + sort(): void; |
| 103 | + /** Returns a string containing a query string suitable for use in a URL. Does not include the question mark. */ |
| 104 | + toString(): string; |
| 105 | + forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void; |
| 106 | +} |
| 107 | + |
| 108 | +export declare var URLSearchParams: { |
| 109 | + prototype: URLSearchParams; |
| 110 | + new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams; |
| 111 | +}; |
0 commit comments