UNPKG

2.17 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 =
12 | 'auth'
13 | 'hash'
14 | 'host'
15 | 'hostname'
16 | 'href'
17 | 'origin'
18 | 'password'
19 | 'pathname'
20 | 'port'
21 | 'protocol'
22 | 'query'
23 | 'slashes'
24 | 'username';
25
26 type QueryParser = (query: string) => object;
27
28 type StringifyQuery = (query: object) => string;
29}
30
31interface URLParse {
32 readonly auth: string;
33 readonly hash: string;
34 readonly host: string;
35 readonly hostname: string;
36 readonly href: string;
37 readonly origin: string;
38 readonly password: string;
39 readonly pathname: string;
40 readonly port: string;
41 readonly protocol: string;
42 readonly query: { [key: string]: string | undefined };
43 readonly slashes: boolean;
44 readonly username: string;
45 set(
46 part: URLParse.URLPart,
47 value: URLParse[URLParse.URLPart] | undefined,
48 fn?: boolean | URLParse.QueryParser,
49 ): URLParse;
50 toString(stringify?: URLParse.StringifyQuery): string;
51}
52
53declare const URLParse: {
54 new (address: string, parser?: boolean | URLParse.QueryParser): URLParse;
55 new (address: string, location?: string | object, parser?: boolean | URLParse.QueryParser): URLParse;
56 (address: string, parser?: boolean | URLParse.QueryParser): URLParse;
57 (address: string, location?: string | object, parser?: boolean | URLParse.QueryParser): URLParse;
58
59 extractProtocol(url: string): {
60 slashes: boolean;
61 protocol: string;
62 rest: string;
63 };
64 location(url: string): object;
65 qs: {
66 parse: URLParse.QueryParser;
67 stringify: URLParse.StringifyQuery;
68 };
69};
70
71export = URLParse;