smartwhois/ts/index.ts
2023-04-03 17:50:55 +02:00

34 lines
1.1 KiB
TypeScript

import * as plugins from './smartwhois.plugins.js';
export class SmartWhois {
public async getWhoisForDomain(domainArg: string) {
const whoisInfo = await plugins.whoiser.domain(domainArg);
const whoisServers = Object.keys(whoisInfo);
const selectedWhoisInfo: any = whoisInfo[whoisServers[0]];
const registrar = selectedWhoisInfo.Registrar;
const registrarUrl = selectedWhoisInfo['Registrar URL'];
const createdDate = selectedWhoisInfo['Created Date'];
const updatedDate = selectedWhoisInfo['Updated Date'];
const expiryDate = selectedWhoisInfo['Expiry Date'];
return {
originalWhoisInfo: whoisInfo,
whoisServers,
registrar,
registrarUrl,
createdDate,
updatedDate,
expiryDate,
};
}
public async isValidTld(tldArg: string): Promise<boolean> {
const allTlds = await plugins.whoiser.allTlds();
const sanatizedTld = tldArg.startsWith('.')
? tldArg.replace('.', '').toUpperCase()
: tldArg.toUpperCase();
return allTlds.includes(sanatizedTld);
}
public async getWhoisForIp(ipArg: string) {}
}