@mitrajit/simple-whois 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ export interface WhoisDataGroup {
2
+ [key: string]: string;
3
+ }
4
+ export interface WhoisData {
5
+ [key: string]: string | string[] | WhoisDataGroup | {
6
+ [key: string]: WhoisDataGroup;
7
+ } | undefined;
8
+ contacts?: {
9
+ [key: string]: WhoisDataGroup;
10
+ };
11
+ __comments: string[];
12
+ __raw: string;
13
+ }
14
+ /**
15
+ * TLD Whois response, from iana.org
16
+ */
17
+ export interface TldWhoisResponse {
18
+ tld: string;
19
+ organisation?: WhoisDataGroup;
20
+ contacts: WhoisDataGroup[];
21
+ nserver: string[];
22
+ "ds-rdata"?: string;
23
+ whois?: string;
24
+ status: "ACTIVE" | "FORMER";
25
+ remarks: string;
26
+ created: string;
27
+ changed: string;
28
+ source: string;
29
+ __comments: string[];
30
+ __raw: string;
31
+ }
32
+ /**
33
+ * Options for querying Domain Name whois
34
+ */
35
+ export interface DomainWhoisOptions {
36
+ host?: string;
37
+ timeout?: number;
38
+ follow?: 1 | 2;
39
+ raw?: boolean;
40
+ ignorePrivacy?: boolean;
41
+ whoisQuery?: (host: string, query: string, timeout?: number) => Promise<string>;
42
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export declare function splitStringBy(string: string, by: number): [string, string];
2
+ /**
3
+ * Check if a string is a valid TLD, and return it in canonical form.
4
+ *
5
+ * @param tld
6
+ * @returns The normalized TLD
7
+ * @throws If the TLD is invalid
8
+ */
9
+ export declare function validatedTld(tld: string): string;
10
+ export declare function isTld(tld: string): boolean;
11
+ export declare function isDomain(domain: string): boolean;
package/dist/utils.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDomain = exports.isTld = exports.validatedTld = exports.splitStringBy = void 0;
4
+ const punycode_1 = require("punycode");
5
+ function splitStringBy(string, by) {
6
+ return [string.slice(0, by), string.slice(by + 1)];
7
+ }
8
+ exports.splitStringBy = splitStringBy;
9
+ /**
10
+ * Check if a string is a valid TLD, and return it in canonical form.
11
+ *
12
+ * @param tld
13
+ * @returns The normalized TLD
14
+ * @throws If the TLD is invalid
15
+ */
16
+ function validatedTld(tld) {
17
+ tld = tld.trim().toLowerCase();
18
+ if (tld.startsWith(".")) {
19
+ tld = tld.substring(1);
20
+ }
21
+ if (tld.endsWith(".")) {
22
+ tld = tld.slice(0, -1);
23
+ }
24
+ const labelTest = /^([a-z]{2,64}|xn[a-z0-9-]{5,})$/;
25
+ const labels = tld.split(".").map((label) => (0, punycode_1.toASCII)(label));
26
+ if (!labels.every((label) => labelTest.test(label))) {
27
+ throw new Error(`Invalid TLD "${tld}"`);
28
+ }
29
+ //return labels.join('.')
30
+ return tld;
31
+ }
32
+ exports.validatedTld = validatedTld;
33
+ function isTld(tld) {
34
+ if (tld.startsWith(".")) {
35
+ tld = tld.substring(1);
36
+ }
37
+ //todo use https://nodejs.org/api/url.html#urldomaintoasciidomain
38
+ return /^([a-z]{2,64}|xn[a-z0-9-]{5,})$/i.test((0, punycode_1.toASCII)(tld));
39
+ }
40
+ exports.isTld = isTld;
41
+ function isDomain(domain) {
42
+ if (domain.endsWith(".")) {
43
+ domain = domain.substring(0, domain.length - 1);
44
+ }
45
+ const labels = (0, punycode_1.toASCII)(domain).split(".").reverse();
46
+ const labelTest = /^([a-z0-9-]{1,64}|xn[a-z0-9-]{5,})$/i;
47
+ return (labels.length > 1 &&
48
+ labels.every((label, index) => {
49
+ return index
50
+ ? labelTest.test(label) &&
51
+ !label.startsWith("-") &&
52
+ !label.endsWith("-")
53
+ : isTld(label);
54
+ }));
55
+ }
56
+ exports.isDomain = isDomain;