UNPKG

4.45 kBTypeScriptView Raw
1declare module 'url' {
2 import { ParsedUrlQuery, ParsedUrlQueryInput } from 'querystring';
3
4 // Input to `url.format`
5 interface UrlObject {
6 auth?: string | null | undefined;
7 hash?: string | null | undefined;
8 host?: string | null | undefined;
9 hostname?: string | null | undefined;
10 href?: string | null | undefined;
11 path?: string | null | undefined;
12 pathname?: string | null | undefined;
13 protocol?: string | null | undefined;
14 search?: string | null | undefined;
15 slashes?: boolean | null | undefined;
16 port?: string | number | null | undefined;
17 query?: string | null | ParsedUrlQueryInput | undefined;
18 }
19
20 // Output of `url.parse`
21 interface Url {
22 auth: string | null;
23 hash: string | null;
24 host: string | null;
25 hostname: string | null;
26 href: string;
27 path: string | null;
28 pathname: string | null;
29 protocol: string | null;
30 search: string | null;
31 slashes: boolean | null;
32 port: string | null;
33 query: string | null | ParsedUrlQuery;
34 }
35
36 interface UrlWithParsedQuery extends Url {
37 query: ParsedUrlQuery;
38 }
39
40 interface UrlWithStringQuery extends Url {
41 query: string | null;
42 }
43
44 /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
45 function parse(urlStr: string): UrlWithStringQuery;
46 /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
47 function parse(urlStr: string, parseQueryString: false | undefined, slashesDenoteHost?: boolean): UrlWithStringQuery;
48 /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
49 function parse(urlStr: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
50 /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
51 function parse(urlStr: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
52
53 function format(URL: URL, options?: URLFormatOptions): string;
54 /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
55 function format(urlObject: UrlObject | string): string;
56 /** @deprecated since v11.0.0 - Use the WHATWG URL API. */
57 function resolve(from: string, to: string): string;
58
59 function domainToASCII(domain: string): string;
60 function domainToUnicode(domain: string): string;
61
62 /**
63 * This function ensures the correct decodings of percent-encoded characters as
64 * well as ensuring a cross-platform valid absolute path string.
65 * @param url The file URL string or URL object to convert to a path.
66 */
67 function fileURLToPath(url: string | URL): string;
68
69 /**
70 * This function ensures that path is resolved absolutely, and that the URL
71 * control characters are correctly encoded when converting into a File URL.
72 * @param url The path to convert to a File URL.
73 */
74 function pathToFileURL(url: string): URL;
75
76 interface URLFormatOptions {
77 auth?: boolean | undefined;
78 fragment?: boolean | undefined;
79 search?: boolean | undefined;
80 unicode?: boolean | undefined;
81 }
82
83 class URL {
84 constructor(input: string, base?: string | URL);
85 hash: string;
86 host: string;
87 hostname: string;
88 href: string;
89 readonly origin: string;
90 password: string;
91 pathname: string;
92 port: string;
93 protocol: string;
94 search: string;
95 readonly searchParams: URLSearchParams;
96 username: string;
97 toString(): string;
98 toJSON(): string;
99 }
100
101 class URLSearchParams implements Iterable<[string, string]> {
102 constructor(init?: URLSearchParams | string | { [key: string]: string | ReadonlyArray<string> | undefined } | Iterable<[string, string]> | ReadonlyArray<[string, string]>);
103 append(name: string, value: string): void;
104 delete(name: string): void;
105 entries(): IterableIterator<[string, string]>;
106 forEach(callback: (value: string, name: string, searchParams: this) => void): void;
107 get(name: string): string | null;
108 getAll(name: string): string[];
109 has(name: string): boolean;
110 keys(): IterableIterator<string>;
111 set(name: string, value: string): void;
112 sort(): void;
113 toString(): string;
114 values(): IterableIterator<string>;
115 [Symbol.iterator](): IterableIterator<[string, string]>;
116 }
117}