Reorganized private methods

pull/62/head
MillenniumEarl 2020-12-26 15:23:41 +01:00
parent a295694af8
commit a67d8c0901
1 changed files with 22 additions and 11 deletions

View File

@ -16,6 +16,10 @@ const LoginResult = require("./scripts/classes/login-result.js");
const UserData = require("./scripts/classes/user-data.js"); const UserData = require("./scripts/classes/user-data.js");
const PrefixParser = require("./scripts/classes/prefix-parser.js"); const PrefixParser = require("./scripts/classes/prefix-parser.js");
//#region Global variables
const USER_NOT_LOGGED = "User not authenticated, unable to continue";
//#endregion
//#region Export classes //#region Export classes
module.exports.GameInfo = GameInfo; module.exports.GameInfo = GameInfo;
module.exports.LoginResult = LoginResult; module.exports.LoginResult = LoginResult;
@ -36,16 +40,11 @@ exports.loggerLevel = "warn"; // By default log only the warn messages
* Indicates whether a user is logged in to the F95Zone platform or not. * Indicates whether a user is logged in to the F95Zone platform or not.
* @returns {String} * @returns {String}
*/ */
/* istambul ignore next */
module.exports.isLogged = function isLogged() { module.exports.isLogged = function isLogged() {
return shared.isLogged; return shared.isLogged;
}; };
//#endregion Export properties //#endregion Export properties
//#region Global variables
const USER_NOT_LOGGED = "User not authenticated, unable to continue";
//#endregion
//#region Export methods //#region Export methods
/** /**
* @public * @public
@ -207,13 +206,8 @@ module.exports.getLatestUpdates = async function(args, limit) {
// Get the closest date limit // Get the closest date limit
let filterDate = 0; let filterDate = 0;
if(args.datelimit) { if(args.datelimit) {
// Script taken from:
// https://www.gavsblog.com/blog/find-closest-number-in-array-javascript
const validDate = [365, 180, 90, 30, 14, 7, 3, 1, 0]; const validDate = [365, 180, 90, 30, 14, 7, 3, 1, 0];
validDate.sort((a, b) => { filterDate = getNearestValueFromArray(validDate, args.datelimit);
return Math.abs(args.datelimit - a) - Math.abs(args.datelimit - b);
});
filterDate = validDate[0];
} }
// Fetch the games // Fetch the games
@ -230,3 +224,20 @@ module.exports.getLatestUpdates = async function(args, limit) {
return await Promise.all(promiseList); return await Promise.all(promiseList);
}; };
//#endregion //#endregion
//#region Private Methods
/**
* @private
* Given an array of numbers, get the nearest value for a given `value`.
* @param {Number[]} array List of default values
* @param {Number} value Value to search
*/
function getNearestValueFromArray(array, value) {
// Script taken from:
// https://www.gavsblog.com/blog/find-closest-number-in-array-javascript
array.sort((a, b) => {
return Math.abs(value - a) - Math.abs(value - b);
});
return array[0];
}
//#endregion