forked from mfpopa/node-tld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test-d.ts
65 lines (58 loc) · 1.86 KB
/
index.test-d.ts
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
import parse_url, { parse_host } from ".";
import { expectAssignable, expectError, expectType } from "tsd";
interface ParseResult {
tld: string;
domain: string;
sub: string;
}
expectType<ParseResult>(parse_url(""));
expectType<ParseResult>(parse_url("", {}));
expectType<ParseResult>(parse_url("", { allowPrivateTLD: true }));
expectType<ParseResult>(parse_url("", { allowUnknownTLD: true }));
expectType<ParseResult>(
parse_url("", { allowPrivateTLD: true, allowUnknownTLD: true })
);
expectType<ParseResult>(
parse_url("", {
allowPrivateTLD: true,
allowUnknownTLD: true,
allowDotlessTLD: true,
})
);
expectType<ParseResult>(parse_host(""));
expectType<ParseResult>(parse_host("", {}));
expectType<ParseResult>(parse_host("", { allowPrivateTLD: true }));
expectType<ParseResult>(parse_host("", { allowUnknownTLD: true }));
expectType<ParseResult>(
parse_host("", { allowPrivateTLD: true, allowUnknownTLD: true })
);
expectType<ParseResult>(
parse_host("", {
allowPrivateTLD: true,
allowUnknownTLD: true,
allowDotlessTLD: true,
})
);
expectError<ParseResult>(parse_url());
expectError<ParseResult>(parse_url({}));
expectError<ParseResult>(parse_host());
expectError<ParseResult>(parse_host({}));
const testUrl = "https://github.com/131/node-tld/blob/master/index.js";
const testHostname = "github.com";
const testOptions = {
allowPrivateTLD: true,
allowUnknownTLD: true,
allowDotlessTLD: true,
};
interface ParseOptions {
allowPrivateTLD?: boolean;
allowUnknownTLD?: boolean;
allowDotlessTLD?: boolean;
}
expectAssignable<string>(testUrl);
expectAssignable<string>(testHostname);
expectAssignable<ParseOptions>(testOptions);
expectType<ParseResult>(parse_url(testUrl));
expectType<ParseResult>(parse_url(testUrl, testOptions));
expectType<ParseResult>(parse_host(testHostname));
expectType<ParseResult>(parse_host(testHostname, testOptions));