UNPKG

2.04 kBTypeScriptView Raw
1// Type definitions for url-parse 1.4
2// Project: https://github.com/unshiftio/url-parse
3// Definitions by: Pavlo Chernenko <https://github.com/ChernenkoPaul>
4// Hari Sivaramakrishnan <https://github.com/harisiva>
5// Dmitry Dushkin <https://github.com/DimitryDushkin>
6// David Golightly <https://github.com/davidgoli>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8// TypeScript Version: 2.2
9
10declare namespace URLParse {
11 type URLPart = 'auth'
12 | 'hash'
13 | 'host'
14 | 'hostname'
15 | 'href'
16 | 'origin'
17 | 'password'
18 | 'pathname'
19 | 'port'
20 | 'protocol'
21 | 'query'
22 | 'slashes'
23 | 'username';
24
25 type QueryParser = (query: string) => object;
26}
27
28interface URLParse {
29 readonly auth: string;
30 readonly hash: string;
31 readonly host: string;
32 readonly hostname: string;
33 readonly href: string;
34 readonly origin: string;
35 readonly password: string;
36 readonly pathname: string;
37 readonly port: string;
38 readonly protocol: string;
39 readonly query: { [key: string]: string | undefined };
40 readonly slashes: boolean;
41 readonly username: string;
42 set(part: URLParse.URLPart, value: string | object | number | undefined, fn?: boolean | URLParse.QueryParser): URLParse;
43 toString(): string;
44}
45
46declare const URLParse: {
47 new(address: string, parser?: boolean | URLParse.QueryParser): URLParse;
48 new(address: string, location?: string | object, parser?: boolean | URLParse.QueryParser): URLParse;
49 (address: string, parser?: boolean | URLParse.QueryParser): URLParse;
50 (address: string, location?: string | object, parser?: boolean | URLParse.QueryParser): URLParse;
51
52 extractProtocol(url: string): {
53 slashes: boolean;
54 protocol: string;
55 rest: string;
56 };
57 location(url: string): object;
58 qs: {
59 parse: URLParse.QueryParser;
60 stringify(query: object): string;
61 };
62};
63
64export = URLParse;