Skip to content

Commit

Permalink
isolated FlightTrackerConfig in a module
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed Dec 22, 2023
1 parent 48a778c commit 5199d43
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions nodejs/FlightRadar24/flightTrackerConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const proxyHandler = {
set: function(target, key, value) {
if (!target.hasOwnProperty(key)) {
throw new Error("Unknown option: '" + key + "'");
}
if ((typeof value !== "number") && (!isNumeric(value))) {
throw new Error("Value must be a decimal. Got '" + key + "'");
}
target[key] = value.toString();
},
};

function isNumeric(string) {
for (let index = 0; index < string.length; index++) {
if (!"0123456789".includes(string[index])) {
return false;
}
}
return true;
}


class FlightTrackerConfig {
/**
* Data class with settings of the Real Time Flight Tracker.
*/

faa = "1";
satellite = "1";
mlat = "1";
flarm = "1";
adsb = "1";
gnd = "1";
air = "1";
vehicles = "1";
estimated = "1";
maxage = "14400";
gliders = "1";
stats = "1";
limit = "5000";

/**
* Constructor of FlighTrackerConfig class.
*
* @param {object} data
*/
constructor(data) {
for (const key in data) {
const value = data[key];

if (this.hasOwnProperty(key) && (typeof value === "number" || isNumeric(value))) {
this[key] = value;
}
}
return new Proxy(this, proxyHandler);
}
}

module.exports = FlightTrackerConfig;

0 comments on commit 5199d43

Please sign in to comment.