-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhoisObject.js
69 lines (55 loc) · 1.29 KB
/
WhoisObject.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module.exports = class WhoisObject {
constructor(name, data, type, dynamic = false) {
this._name = name.toLowerCase();
this._data = [];
this._type = type;
this._dynamic = dynamic;
let dataLines = data.split(/(?:\r)?\n/g);
for (var i = 0; i < dataLines.length; i++) {
let thisLine = dataLines[i];
/** @type {Array} */
let thisLineParts = thisLine.split(/:(?: )?/);
if (thisLineParts[0] === '_REFER') {
this._referral = thisLineParts.slice(1).join(':');
continue;
}
if (thisLineParts[0] === '_PULL') {
if (this._referral) {
console.warn(`Whois object ${this._name} has both refer and pull actions. Ignoring the pull action.`);
continue;
}
let pullData = thisLineParts.slice(1).join(':');
this._pull = pullData.split(' ')[0];
if (pullData.split(' ').length > 1) {
this._pullPort = pullData.split(' ')[1];
}
continue;
}
if (thisLineParts[0].startsWith('_')) {
continue;
}
this._data.push(thisLine);
}
}
getData() {
return this._data;
}
getDataText() {
return this._data.join('\n');
}
hasReferral() {
return !!this._referral;
}
getReferral() {
return this._referral;
}
hasPull() {
return !!this._pull;
}
getPull() {
return this._pull;
}
getPullPort() {
return this._pullPort || 43;
}
};