forked from 131/node-tld
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test-d.ts
46 lines (39 loc) · 1.54 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
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_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 })
);
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 };
interface ParseOptions {
allowPrivateTLD?: boolean;
allowUnknownTLD?: 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));