UNPKG

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