UNPKG

4.89 kBTypeScriptView Raw
1/// <reference lib="es2020"/>
2/** https://url.spec.whatwg.org/#url-representation */
3export interface URLRecord {
4 scheme: string;
5 username: string;
6 password: string;
7 host: string | number | IPv6Address | null;
8 port: number | null;
9 path: string | string[];
10 query: string | null;
11 fragment: string | null;
12}
13
14/** https://url.spec.whatwg.org/#concept-ipv6 */
15export type IPv6Address = [number, number, number, number, number, number, number, number];
16
17/** https://url.spec.whatwg.org/#url-class */
18export class URL {
19 constructor(url: string, base?: string | URL);
20
21 get href(): string;
22 set href(V: string);
23
24 get origin(): string;
25
26 get protocol(): string;
27 set protocol(V: string);
28
29 get username(): string;
30 set username(V: string);
31
32 get password(): string;
33 set password(V: string);
34
35 get host(): string;
36 set host(V: string);
37
38 get hostname(): string;
39 set hostname(V: string);
40
41 get port(): string;
42 set port(V: string);
43
44 get pathname(): string;
45 set pathname(V: string);
46
47 get search(): string;
48 set search(V: string);
49
50 get searchParams(): URLSearchParams;
51
52 get hash(): string;
53 set hash(V: string);
54
55 toJSON(): string;
56
57 readonly [Symbol.toStringTag]: "URL";
58}
59
60/** https://url.spec.whatwg.org/#interface-urlsearchparams */
61export class URLSearchParams {
62 constructor(
63 init?:
64 | ReadonlyArray<readonly [name: string, value: string]>
65 | Iterable<readonly [name: string, value: string]>
66 | { readonly [name: string]: string }
67 | string,
68 );
69
70 append(name: string, value: string): void;
71 delete(name: string): void;
72 get(name: string): string | null;
73 getAll(name: string): string[];
74 has(name: string): boolean;
75 set(name: string, value: string): void;
76 sort(): void;
77
78 keys(): IterableIterator<string>;
79 values(): IterableIterator<string>;
80 entries(): IterableIterator<[name: string, value: string]>;
81 forEach<THIS_ARG = void>(
82 callback: (this: THIS_ARG, value: string, name: string, searchParams: this) => void,
83 thisArg?: THIS_ARG,
84 ): void;
85
86 readonly [Symbol.toStringTag]: "URLSearchParams";
87 [Symbol.iterator](): IterableIterator<[name: string, value: string]>;
88}
89
90/** https://url.spec.whatwg.org/#concept-url-parser */
91export function parseURL(input: string, options?: { readonly baseURL?: URLRecord | undefined }): URLRecord | null;
92
93/** https://url.spec.whatwg.org/#concept-basic-url-parser */
94export function basicURLParse(
95 input: string,
96 options?: {
97 baseURL?: URLRecord | undefined;
98 url?: URLRecord | undefined;
99 stateOverride?: StateOverride | undefined;
100 },
101): URLRecord | null;
102
103/** https://url.spec.whatwg.org/#scheme-start-state */
104export type StateOverride =
105 | "scheme start"
106 | "scheme"
107 | "no scheme"
108 | "special relative or authority"
109 | "path or authority"
110 | "relative"
111 | "relative slash"
112 | "special authority slashes"
113 | "special authority ignore slashes"
114 | "authority"
115 | "host"
116 | "hostname"
117 | "port"
118 | "file"
119 | "file slash"
120 | "file host"
121 | "path start"
122 | "path"
123 | "opaque path"
124 | "query"
125 | "fragment";
126
127/** https://url.spec.whatwg.org/#concept-url-serializer */
128export function serializeURL(urlRecord: URLRecord, excludeFragment?: boolean): string;
129
130/** https://url.spec.whatwg.org/#concept-host-serializer */
131export function serializeHost(host: string | number | IPv6Address): string;
132
133/** https://url.spec.whatwg.org/#url-path-serializer */
134export function serializePath(urlRecord: URLRecord): string;
135
136/** https://url.spec.whatwg.org/#serialize-an-integer */
137export function serializeInteger(number: number): string;
138
139/** https://html.spec.whatwg.org#ascii-serialisation-of-an-origin */
140export function serializeURLOrigin(urlRecord: URLRecord): string;
141
142/** https://url.spec.whatwg.org/#set-the-username */
143export function setTheUsername(urlRecord: URLRecord, username: string): void;
144
145/** https://url.spec.whatwg.org/#set-the-password */
146export function setThePassword(urlRecord: URLRecord, password: string): void;
147
148/** https://url.spec.whatwg.org/#url-opaque-path */
149export function hasAnOpaquePath(urlRecord: URLRecord): boolean;
150
151/** https://url.spec.whatwg.org/#cannot-have-a-username-password-port */
152export function cannotHaveAUsernamePasswordPort(urlRecord: URLRecord): boolean;
153
154/** https://url.spec.whatwg.org/#percent-decode */
155export function percentDecodeBytes(buffer: TypedArray): Uint8Array;
156
157/** https://url.spec.whatwg.org/#string-percent-decode */
158export function percentDecodeString(string: string): Uint8Array;
159
160export type TypedArray =
161 | Uint8Array
162 | Uint8ClampedArray
163 | Uint16Array
164 | Uint32Array
165 | Int8Array
166 | Int16Array
167 | Int32Array
168 | Float32Array
169 | Float64Array;