-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (35 loc) · 1016 Bytes
/
index.js
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
const whoiser = require('whoiser')
const log = require('loglevel-colored-level-prefix')()
/**
* Get domain expiration date
*
* @param {string} domain - Domain name
* @return {Promise<Date>} domain expiration date
*
* @example
*
* whoisExpire('nitra.ai')
*/
async function whoisExpire (domain) {
const domainInfo = await whoiser.domain(domain)
const firstData = domainInfo[Object.keys(domainInfo)[0]]
const whooisDate = firstData['Registry Expiry Date'] || firstData.Expires || firstData.expires || firstData['paid-till']
if (whooisDate) {
log.debug(whooisDate)
return new Date(Date.parse(whooisDate))
}
// adv24.lt
if (firstData.text) {
for (const line of firstData.text) {
const lineLowered = line.toLowerCase()
if (lineLowered.startsWith('expires')) {
const lineDate = line.substr(-10, 10)
if (lineDate) {
return new Date(Date.parse(lineDate))
}
}
}
}
log.debug(domain, domainInfo)
}
module.exports = whoisExpire