Skip to content

Commit a3c8cde

Browse files
committed
add TypeScript support for allowDotlessTLD
1 parent ec218e3 commit a3c8cde

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ interface ParseOptions {
1010
* @note This option can also be used when parsing URLs that contain IP addresses.
1111
*/
1212
allowUnknownTLD?: boolean;
13+
/**
14+
* Allow parsing URLs that contain a top-level domain (TLD) used as a direct domain name,
15+
* also known as a dotless domain.
16+
*
17+
* @note Using dotless domains is highly not recommended by ICANN and IAB. Use with caution.
18+
*/
19+
allowDotlessTLD?: boolean;
1320
}
1421

1522
interface ParseResult {

index.test-d.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ expectType<ParseResult>(parse_url("", { allowUnknownTLD: true }));
1414
expectType<ParseResult>(
1515
parse_url("", { allowPrivateTLD: true, allowUnknownTLD: true })
1616
);
17+
expectType<ParseResult>(
18+
parse_url("", {
19+
allowPrivateTLD: true,
20+
allowUnknownTLD: true,
21+
allowDotlessTLD: true,
22+
})
23+
);
1724

1825
expectType<ParseResult>(parse_host(""));
1926
expectType<ParseResult>(parse_host("", {}));
@@ -22,6 +29,13 @@ expectType<ParseResult>(parse_host("", { allowUnknownTLD: true }));
2229
expectType<ParseResult>(
2330
parse_host("", { allowPrivateTLD: true, allowUnknownTLD: true })
2431
);
32+
expectType<ParseResult>(
33+
parse_host("", {
34+
allowPrivateTLD: true,
35+
allowUnknownTLD: true,
36+
allowDotlessTLD: true,
37+
})
38+
);
2539

2640
expectError<ParseResult>(parse_url());
2741
expectError<ParseResult>(parse_url({}));
@@ -30,11 +44,16 @@ expectError<ParseResult>(parse_host({}));
3044

3145
const testUrl = "https://github.com/131/node-tld/blob/master/index.js";
3246
const testHostname = "github.com";
33-
const testOptions = { allowPrivateTLD: true, allowUnknownTLD: true };
47+
const testOptions = {
48+
allowPrivateTLD: true,
49+
allowUnknownTLD: true,
50+
allowDotlessTLD: true,
51+
};
3452

3553
interface ParseOptions {
3654
allowPrivateTLD?: boolean;
3755
allowUnknownTLD?: boolean;
56+
allowDotlessTLD?: boolean;
3857
}
3958

4059
expectAssignable<string>(testUrl);

0 commit comments

Comments
 (0)