Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
prepare support for XML and YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
therealbenpai committed Jul 20, 2024
1 parent ff5d8c7 commit 304de0b
Show file tree
Hide file tree
Showing 19 changed files with 464 additions and 1,211 deletions.
921 changes: 0 additions & 921 deletions documentation/api-documentation.yml

Large diffs are not rendered by default.

Empty file removed modules/api/crypto.js
Empty file.
Empty file removed modules/api/facts.js
Empty file.
52 changes: 52 additions & 0 deletions modules/api/location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const xml = require('xml');

Check failure on line 1 in modules/api/location.js

View check run for this annotation

Codeac.io / Codeac Code Quality

Parsing error: No Babel config file detected for /tmp/commit-1205438-eslint/modules/api/location.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.
const yaml = require('yaml');

class Location {
constructor(data) {
this.address = {
full: data.address.full || '',
houseNumber: data.address.houseNumber || '',
street: data.address.street || '',
city: data.address.city || '',
region: data.address.region || '',
country: data.address.country || '',
postalCode: data.address.postalCode || '',
};
this.pluscode = data.pluscode || '';
this.coords = {
lat: data.coords.lat || 0,
lng: data.coords.lng || 0,
};
}
get JSON() {
return JSON.stringify({
address: this.address,
pluscode: this.pluscode,
coords: this.coords,
});
}
get XML() {
return xml({
address: [
{ full: this.address.full },
{ houseNumber: this.address.houseNumber },
{ street: this.address.street },
{ city: this.address.city },
{ region: this.address.region },
{ country: this.address.country },
{ postalCode: this.address.postalCode },
],
pluscode: this.pluscode,
coords: this.coords,
});
}
get YAML() {
return yaml.stringify({
address: this.address,
pluscode: this.pluscode,
coords: this.coords,
});
}
}

module.exports = Location;
69 changes: 69 additions & 0 deletions modules/api/phone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const xml = require('xml');

Check failure on line 1 in modules/api/phone.js

View check run for this annotation

Codeac.io / Codeac Code Quality

Parsing error: No Babel config file detected for /tmp/commit-1205438-eslint/modules/api/phone.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.
const yaml = require('yaml');

class Phone {
constructor(data) {
this.status = data.status || 'error';
this.phone = data.phone || '';
this.phoneValid = data.phone_valid || false;
this.phoneType = data.phone_type || '';
this.phoneRegion = data.phone_region || '';
this.country = data.country || '';
this.countryCode = data.country_code || '';
this.countryPrefix = data.country_prefix || '';
this.internationalNumber = data.international_number || '';
this.localNumber = data.local_number || '';
this.e164 = data.e164 || '';
this.carrier = data.carrier || '';
}
get JSON() {
return JSON.stringify({
status: this.status,
phone: this.phone,
phoneValid: this.phoneValid,
phoneType: this.phoneType,
phoneRegion: this.phoneRegion,
country: this.country,
countryCode: this.countryCode,
countryPrefix: this.countryPrefix,
internationalNumber: this.internationalNumber,
localNumber: this.localNumber,
e164: this.e164,
carrier: this.carrier,
});
}
get XML() {
return xml({

Check warning on line 36 in modules/api/phone.js

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 16 lines is too similar to modules/api/phone.js:36

Check warning on line 36 in modules/api/phone.js

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 16 lines is too similar to modules/api/phone.js:52
status: this.status,
phone: this.phone,
phoneValid: this.phoneValid,
phoneType: this.phoneType,
phoneRegion: this.phoneRegion,
country: this.country,
countryCode: this.countryCode,
countryPrefix: this.countryPrefix,
internationalNumber: this.internationalNumber,
localNumber: this.localNumber,
e164: this.e164,
carrier: this.carrier,
});
}
get YAML() {
return yaml.stringify({

Check warning on line 52 in modules/api/phone.js

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 16 lines is too similar to modules/api/phone.js:20
status: this.status,
phone: this.phone,
phoneValid: this.phoneValid,
phoneType: this.phoneType,
phoneRegion: this.phoneRegion,
country: this.country,
countryCode: this.countryCode,
countryPrefix: this.countryPrefix,
internationalNumber: this.internationalNumber,
localNumber: this.localNumber,
e164: this.e164,
carrier: this.carrier,
});
}
}

Check warning on line 68 in modules/api/phone.js

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 16 lines is too similar to modules/api/phone.js:20
module.exports = Phone;
33 changes: 33 additions & 0 deletions modules/api/quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const xml = require('xml');

Check failure on line 1 in modules/api/quote.js

View check run for this annotation

Codeac.io / Codeac Code Quality

Parsing error: No Babel config file detected for /tmp/commit-1205438-eslint/modules/api/quote.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.
const yaml = require('yaml');

class Quote {
constructor(data) {
this.quotes = data.quote;
this.author = data.author;
this.tags = data.tags;
}
get JSON() {
return JSON.stringify({
quotes: this.quotes,
author: this.author,
tags: this.tags,
});
}
get XML() {
return xml({
quotes: this.quotes,
author: this.author,
tags: this.tags,
});
}
get YAML() {
return yaml.stringify({
quotes: this.quotes,
author: this.author,
tags: this.tags,
});
}
}

module.exports = Quote;
Empty file removed modules/api/token.js
Empty file.
Empty file removed modules/api/user.js
Empty file.
Empty file removed modules/api/weather.js
Empty file.
192 changes: 192 additions & 0 deletions modules/api/whois.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/* eslint-disable id-length */

Check failure on line 1 in modules/api/whois.js

View check run for this annotation

Codeac.io / Codeac Code Quality

Parsing error: No Babel config file detected for /tmp/commit-1205438-eslint/modules/api/whois.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.
const xml = require('xml');
const yaml = require('yaml');

class Contact {
constructor(data) {
this.name = data.name || 'Unknown';
this.organization = data.organization || 'Unknown';
this.street = data.street || 'Unknown';
this.city = data.city || 'Unknown';
this.state = data.state || 'Unknown';
this.postalCode = data.postalCode || 'Unknown';
this.country = data.country || 'Unknown';
this.phone = data.phone || 'Unknown';
this.fax = data.fax || 'Unknown';
this.email = data.email || 'Unknown';
}
get JSON() {
return {
name: this.name,
organization: this.organization,
street: this.street,
city: this.city,
state: this.state,
postalCode: this.postalCode,
country: this.country,
phone: this.phone,
fax: this.fax,
email: this.email,
};
}
get XML() {
return [
{ name: this.name },
{ organization: this.organization },
{ street: this.street },
{ city: this.city },
{ state: this.state },
{ postalCode: this.postalCode },
{ country: this.country },
{ phone: this.phone },
{ fax: this.fax },
{ email: this.email },
];
}
}



class DNS {
constructor(data) {
this.SOA = data.SOA || {};
this.A = data.A || '';
this.CAA = data.CAA || [];
this.CNAME = data.CNAME || '';
this.SRV = data.SRV || [];
this.AAAA = data.AAAA || '';
this.PTR = data.PTR || [];
this.TXT = data.TXT || [];
this.NS = data.NS || [];
this.MX = data.MX || [];
}
get JSON() {
return {
SOA: this.SOA,
A: this.A,
CAA: this.CAA,
CNAME: this.CNAME,
SRV: this.SRV,
AAAA: this.AAAA,
PTR: this.PTR,
TXT: this.TXT,
NS: this.NS,
MX: this.MX,
};
}
get XML() {
return xml(this.XMLData);
}
get XMLData() {
return [
{
SOA: [
{ nsname: this.SOA.nsname },
{ serial: this.SOA.serial },
{ expire: this.SOA.expire },
{ minttl: this.SOA.minttl },
{ retry: this.SOA.retry },
{ refresh: this.SOA.refresh },
{ hostmaster: this.SOA.hostmaster },
],
},
{ A: this.A },
{
CAA: this.CAA.map(rec => (
rec.iodef
? { iodef: rec.iodef }
: { main: rec.main, wild: rec.wild, issuer: rec.issuer }
)),
},
{ CNAME: this.CNAME },
{ SRV: this.SRV.map(rec => ({ record: rec })) },
{ AAAA: this.AAAA },
{ PTR: this.PTR.map(rec => ({ record: rec })) },
{ TXT: this.TXT.map(rec => ({ record: rec })) },
{ NS: this.NS.map(rec => ({ record: rec })) },
{ MX: this.MX.map(rec => ({ priority: rec.priority, exchange: rec.exchange })) },
];
}
get YAML() {
return yaml.stringify(this.JSON);
}
}

class WHOIS {
constructor(data) {
this.expirationDate = data.expirationDate || 'Unknown';
this.billing = new Contact(data.billing);
this.registrar = data.registrar || 'Unknown';
this.admin = new Contact(data.admin);
this.domainName = data.domainName || 'Unknown';
this.creationDate = data.creationDate || 'Unknown';
this.tech = new Contact(data.tech);
this.updatedDate = data.updatedDate || 'Unknown';
this.registrant = new Contact(data.registrant);
this.status = data.status || [];
}
get JSON() {
return {
expirationDate: this.expirationDate,
billing: this.billing.JSON,
registrar: this.registrar,
admin: this.admin.JSON,
domainName: this.domainName,
creationDate: this.creationDate,
tech: this.tech.JSON,
updatedDate: this.updatedDate,
registrant: this.registrant.JSON,
status: this.status,
};
}
get XML() {
return xml(this.XMLData);
}
get XMLData() {
return [
{ expirationDate: this.expirationDate },
{ billing: this.billing.XML },
{ registrar: this.registrar },
{ admin: this.admin.XML },
{ domainName: this.domainName },
{ creationDate: this.creationDate },
{ tech: this.tech.XML },
{ updatedDate: this.updatedDate },
{ registrant: this.registrant.XML },
{ status: this.status },
];
}
get YAML() {
return yaml.stringify(this.JSON);
}
}

class Full {
constructor(data) {
this.WHOIS = new WHOIS(data.whois);
this.DNS = new DNS(data.dns);
}
get JSON() {
return {
whois: this.WHOIS.JSON,
dns: this.DNS.JSON,
};
}
get XML() {
return xml({
full: [
{ whois: this.WHOIS.XMLData },
{ dns: this.DNS.XMLData },
],
});
}
get YAML() { }
}

class Crypto {
static DNS = DNS;
static WHOIS = WHOIS;
static Full = Full;
}

module.exports = Crypto;
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"vhost": "^3.0.2",
"whoiser": "^1.17.3",
"ws": "^8.17.1",
"xml": "^1.0.1"
"xml": "^1.0.1",
"yaml": "^2.4.5"
},
"devDependencies": {
"@eslint/js": "^9.3.0",
Expand Down
Loading

0 comments on commit 304de0b

Please sign in to comment.