UNPKG

4.72 kBTypeScriptView Raw
1declare module 'url' {
2 import { ClientRequestArgs } from 'http';
3 import { ParsedUrlQuery, ParsedUrlQueryInput } from 'querystring';
4
5 // Input to `url.format`
6 interface UrlObject {
7 auth?: string | null | undefined;
8 hash?: string | null | undefined;
9 host?: string | null | undefined;
10 hostname?: string | null | undefined;
11 href?: 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 /**
77 * This utility function converts a URL object into an ordinary options object as
78 * expected by the `http.request()` and `https.request()` APIs.
79 */
80 function urlToHttpOptions(url: URL): ClientRequestArgs;
81
82 interface URLFormatOptions {
83 auth?: boolean | undefined;
84 fragment?: boolean | undefined;
85 search?: boolean | undefined;
86 unicode?: boolean | undefined;
87 }
88
89 class URL {
90 constructor(input: string, base?: string | URL);
91 hash: string;
92 host: string;
93 hostname: string;
94 href: string;
95 readonly origin: string;
96 password: string;
97 pathname: string;
98 port: string;
99 protocol: string;
100 search: string;
101 readonly searchParams: URLSearchParams;
102 username: string;
103 toString(): string;
104 toJSON(): string;
105 }
106
107 class URLSearchParams implements Iterable<[string, string]> {
108 constructor(init?: URLSearchParams | string | NodeJS.Dict<string | ReadonlyArray<string>> | Iterable<[string, string]> | ReadonlyArray<[string, string]>);
109 append(name: string, value: string): void;
110 delete(name: string): void;
111 entries(): IterableIterator<[string, string]>;
112 forEach(callback: (value: string, name: string, searchParams: this) => void): void;
113 get(name: string): string | null;
114 getAll(name: string): string[];
115 has(name: string): boolean;
116 keys(): IterableIterator<string>;
117 set(name: string, value: string): void;
118 sort(): void;
119 toString(): string;
120 values(): IterableIterator<string>;
121 [Symbol.iterator](): IterableIterator<[string, string]>;
122 }
123}
124
125declare module 'node:url' {
126 export * from 'url';
127}