UNPKG

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