UNPKG

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