File: index.d.ts

package info (click to toggle)
node-url-parse 1.5.10%2B~1.4.8-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: javascript: 1,584; makefile: 9
file content (77 lines) | stat: -rwxr-xr-x 3,029 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Type definitions for url-parse 1.4
// Project: https://github.com/unshiftio/url-parse
// Definitions by: Hari Sivaramakrishnan <https://github.com/harisiva>
//                 Dmitry Dushkin <https://github.com/DimitryDushkin>
//                 David Golightly <https://github.com/davidgoli>
//                 Kit Song <https://github.com/kitsong>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2

declare namespace URLParse {
    type URLPart =
        | 'auth'
        | 'hash'
        | 'host'
        | 'hostname'
        | 'href'
        | 'origin'
        | 'password'
        | 'pathname'
        | 'port'
        | 'protocol'
        | 'query'
        | 'slashes'
        | 'username';

    type QueryParser<T = Record<string, string | undefined>> = (query: string) => T;

    type StringifyQuery = (query: object) => string;
}

interface URLParse<Query> {
    readonly auth: string;
    readonly hash: string;
    readonly host: string;
    readonly hostname: string;
    readonly href: string;
    readonly origin: string;
    readonly password: string;
    readonly pathname: string;
    readonly port: string;
    readonly protocol: string;
    readonly query: Query;
    readonly slashes: boolean;
    readonly username: string;
    set<Part extends URLParse.URLPart>(part: Part, value: URLParse<Query>[Part] | undefined, fn?: false): URLParse<Query>;
    set<Part extends URLParse.URLPart, T>(part: Part, value: URLParse<T>[Part] | undefined, fn?: URLParse.QueryParser<T>): URLParse<T>;
    toString(stringify?: URLParse.StringifyQuery): string;
}

declare const URLParse: {
    new(address: string, parser?: false): URLParse<string>;
    new(address: string, parser: true): URLParse<Record<string, string | undefined>>;
    new <T>(address: string, parser?: URLParse.QueryParser<T>): URLParse<T>;
    new(address: string, location?: string | object, parser?: false): URLParse<string>;
    new(address: string, location: string | object | undefined, parser: true): URLParse<Record<string, string | undefined>>;
    new <T>(address: string, location: string | object | undefined, parser: URLParse.QueryParser<T>): URLParse<T>;
    (address: string, parser?: false): URLParse<string>;
    (address: string, parser: true): URLParse<Record<string, string | undefined>>;
    <T>(address: string, parser: URLParse.QueryParser<T>): URLParse<T>;
    (address: string, location?: string | object, parser?: false): URLParse<string>;
    (address: string, location: string | object | undefined, parser: true): URLParse<Record<string, string | undefined>>;
    <T>(address: string, location: string | object | undefined, parser: URLParse.QueryParser<T>): URLParse<T>;

    extractProtocol(url: string): {
        slashes: boolean;
        protocol: string;
        rest: string;
    };
    location(url: string): object;
    qs: {
        parse: URLParse.QueryParser;
        stringify: URLParse.StringifyQuery;
    };
    trimLeft(url: string): string;
};

export = URLParse;