Skip to content

Commit

Permalink
Fix data types in class properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Feb 19, 2024
1 parent 069c2c1 commit cb55962
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 86 deletions.
10 changes: 5 additions & 5 deletions src/structures/Boosters/Booster.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ class Booster {
constructor(data) {
/**
* Booster's purchaser's UUID
* @type {String}
* @type {string}
*/
this.purchaser = data.purchaserUuid;
/**
* Booster's multiplier
* @type {Number}
* @type {number}
*/
this.amount = data.amount;
/**
* Booster's length in seconds
* @type {Number}
* @type {number}
*/
this.originalLength = data.originalLength;
/**
* Length remaining in seconds
* @type {Number}
* @type {number}
*/
this.remaining = data.length;
/**
* Date activated timestamp
* @type {Number}
* @type {number}
*/
this.activatedTimestamp = data.dateActivated;
/**
Expand Down
141 changes: 93 additions & 48 deletions src/structures/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,62 +68,107 @@ class Color {
toCode() {
return this.color;
}

/**
* Returns color code
* @return {InGameCode}
*/
toInGameCode() {
const InGameCodes = {
BLACK: '§0',
DARK_BLUE: '§1',
DARK_GREEN: '§2',
DARK_AQUA: '§3',
DARK_RED: '§4',
DARK_PURPLE: '§5',
GOLD: '§6',
GRAY: '§7',
DARK_GRAY: '§8',
BLUE: '§9',
GREEN: '§a',
AQUA: '§b',
RED: '§c',
LIGHT_PURPLE: '§d',
YELLOW: '§e',
WHITE: '§f'
};
return InGameCodes[this.color];
}
}
/**
* @typedef {string} ColorCode
* * `BLACK`
* * `DARK_BLUE`
* * `DARK_GREEN`
* * `DARK_AQUA`
* * `DARK_RED`
* * `DARK_PURPLE`
* * `GOLD`
* * `GRAY`
* * `DARK_GRAY`
* * `BLUE`
* * `GREEN`
* * `AQUA`
* * `RED`
* * `LIGHT_PURPLE`
* * `YELLOW`
* * `WHITE`
* * 'BLACK'
* * 'DARK_BLUE'
* * 'DARK_GREEN'
* * 'DARK_AQUA'
* * 'DARK_RED'
* * 'DARK_PURPLE'
* * 'GOLD'
* * 'GRAY'
* * 'DARK_GRAY'
* * 'BLUE'
* * 'GREEN'
* * 'AQUA'
* * 'RED'
* * 'LIGHT_PURPLE'
* * 'YELLOW'
* * 'WHITE'
*/
/**
* @typedef {string} ColorString
* * BLACK: `Black`
* * DARK_BLUE: `Dark Blue`
* * DARK_GREEN: `Dark Green`
* * DARK_AQUA: `Dark Aqua`
* * DARK_RED: `Dark Red`
* * DARK_PURPLE: `Dark Purple`
* * GOLD: `Gold`
* * GRAY: `Gray`
* * DARK_GRAY: `Dark Gray`
* * BLUE: `Blue`,
* * GREEN: `Green`
* * AQUA: `Aqua`
* * RED: `Red`
* * LIGHT_PURPLE: `Light Purple`
* * YELLOW: `Yellow`
* * WHITE: `White`
* * BLACK: 'Black'
* * DARK_BLUE: 'Dark Blue'
* * DARK_GREEN: 'Dark Green'
* * DARK_AQUA: 'Dark Aqua'
* * DARK_RED: 'Dark Red'
* * DARK_PURPLE: 'Dark Purple'
* * GOLD: 'Gold'
* * GRAY: 'Gray'
* * DARK_GRAY: 'Dark Gray'
* * BLUE: 'Blue`'
* * GREEN: 'Green'
* * AQUA: 'Aqua'
* * RED: 'Red'
* * LIGHT_PURPLE: 'Light Purple'
* * YELLOW: 'Yellow'
* * WHITE: 'White'
*/
/**
* @typedef {string} ColorHex
* * BLACK: `#000000`
* * DARK_BLUE: `#0000AA`
* * DARK_GREEN: `#008000`
* * DARK_AQUA: `#00AAAA`
* * DARK_RED: `#AA0000`
* * DARK_PURPLE: `#AA00AA`
* * GOLD: `#FFAA00`
* * GRAY: `#AAAAAA`
* * DARK_GRAY: `#555555`
* * BLUE: `#5555FF`
* * GREEN: `#3CE63C`
* * AQUA: `#3CE6E6`
* * RED: `#FF5555`
* * LIGHT_PURPLE: `#FF55FF`
* * YELLOW: `#FFFF55`
* * WHITE: `#FFFFFF`
* * BLACK: '#000000'
* * DARK_BLUE: '#0000AA'
* * DARK_GREEN: '#008000'
* * DARK_AQUA: '#00AAAA'
* * DARK_RED: '#AA0000'
* * DARK_PURPLE: '#AA00AA'
* * GOLD: '#FFAA00'
* * GRAY: '#AAAAAA'
* * DARK_GRAY: '#555555'
* * BLUE: '#5555FF'
* * GREEN: '#3CE63C'
* * AQUA: '#3CE6E6'
* * RED: '#FF5555'
* * LIGHT_PURPLE: '#FF55FF'
* * YELLOW: '#FFFF55'
* * WHITE: '#FFFFFF'
*/
/**
* @typedef {string} InGameCode
* * BLACK: '§0'
* * DARK_BLUE: '§1'
* * DARK_GREEN: '§2'
* * DARK_AQUA: '§3'
* * DARK_RED: '§4'
* * DARK_PURPLE: '§5'
* * GOLD: '§6'
* * GRAY: '§7'
* * DARK_GRAY: '§8'
* * BLUE: '§9'
* * GREEN: '§a'
* * AQUA: '§b'
* * RED: '§c'
* * LIGHT_PURPLE: '§d'
* * YELLOW: '§e'
* * WHITE: '§f'
*/
module.exports = Color;
12 changes: 6 additions & 6 deletions src/structures/Guild/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { getGuildLevel, parseHistory } = require('../../utils/guildExp');
class Guild {
/**
* @param {data} data Guild data
* @param {string} [me] Player uuid used to search for this guild
* @param {string} [me] Player uuid u#sed to search for this guild
*/
constructor(data, me = '') {
/**
Expand All @@ -19,22 +19,22 @@ class Guild {
this.id = data._id;
/**
* Guild name
* @type {String}
* @type {string}
*/
this.name = data.name;
/**
* Guild description
* @type {String}
* @type {string}
*/
this.description = data.description ? data.description : null;
/**
* Guild experience
* @type {Number}
* @type {number}
*/
this.experience = data.exp || 0;
/**
* Guild level
* @type {Number}
* @type {number}
*/
this.level = getGuildLevel(this.experience);
/**
Expand Down Expand Up @@ -86,7 +86,7 @@ class Guild {
};
/**
* Date of guild creation as timestamp
* @type {String}
* @type {string}
*/
this.createdAtTimestamp = data.created;
/**
Expand Down
10 changes: 5 additions & 5 deletions src/structures/Guild/GuildMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class GuildMember {
constructor(data) {
/**
* Guild member UUID
* @type {String}
* @type {string}
*/
this.uuid = data.uuid;
/**
* Timestamp this member joined at
* @type {Number}
* @type {number}
*/
this.joinedAtTimestamp = data.joined;
/**
Expand All @@ -24,12 +24,12 @@ class GuildMember {
this.joinedAt = new Date(data.joined);
/**
* The number of challenges completed that count towards the current quest
* @type {Number}
* @type {number}
*/
this.questParticipation = data.questParticipation || 0;
/**
* Member's rank
* @type {String}
* @type {string}
*/
this.rank = data.rank;
/**
Expand All @@ -50,7 +50,7 @@ class GuildMember {
this.expHistory = parseHistory(data.expHistory);
/**
* Experience per week, resets every Monday at 5 am UTC
* @type {Number}
* @type {number}
*/
this.weeklyExperience = xpCheck ? Object.values(data.expHistory).reduce((pV, cV) => pV + cV, 0) : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Guild/GuildRank.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GuildRank {
constructor(data) {
/**
* Guild rank name
* @type {String}
* @type {string}
*/
this.name = data.name;
/**
Expand Down
4 changes: 2 additions & 2 deletions src/structures/MiniGames/Arcade.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class Arcade {
this.monthlyCoins = parseInt(data[`monthly_coins_${monthAB()}`] || 0, 10);
/**
* Hints Disabled
* @type {Boolean}
* @type {boolean}
*/
this.hintsDisabled = !data.hints;
/**
* Flash Disabled
* @type {Boolean}
* @type {boolean}
*/
this.flashDisabled = !data.flash;
/**
Expand Down
21 changes: 6 additions & 15 deletions src/structures/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,11 @@ class Player {
* @type {string}
*/
this.uuid = data.uuid;
/**
* Player nickname history known to Hypixel
* @type {Array<string>}
*/
this.history = data.knownAliases;
/**
* Player rank
* @type {PlayerRank}
*/
this.rank = getRank(data);
/**
* Player minecraft version
* @type {string|null}
*/
this.mcVersion = data.mcVersionRp || null;
/**
* Current chat channel, usually ALL, PARTY, or GUILD
* @type {string|null}
Expand All @@ -75,12 +65,12 @@ class Player {
*/
this.firstLogin = data.firstLogin ? new Date(data.firstLogin) : null;
/**
* Player's recently played game
* Timestamp when player last logged in as Date
* @type {Game|null}
*/
this.lastLoginTimestamp = data.lastLogin || null;
/**
* Timestamp when player first logged in
* Timestamp when player first logged in unix
* @type {number|null}
*/
this.lastLogin = data.lastLogin ? new Date(data.lastLogin) : null;
Expand All @@ -90,8 +80,8 @@ class Player {
*/
this.lastLogoutTimestamp = data.lastLogout || null;
/**
* Timestamp when player first logged in as Date
* @type {Date|null}
* Timestamp when player first logged in unix
* @type {number|null}
*/
this.lastLogout = data.lastLogout ? new Date(data.lastLogout) : null;
/**
Expand Down Expand Up @@ -348,8 +338,8 @@ function playerLevelProgress(player) {
const percentRemaining = Math.round((100 - percent) * 100) / 100;
return {
xpToNext,
currentXP,
remainingXP,
currentXP,
percent,
percentRemaining
};
Expand Down Expand Up @@ -413,6 +403,7 @@ function parseClaimedRewards(data) {
* @property {BlitzSurvivalGames|null} blitzsg Blitz Survival Games
* @property {ArenaBrawl|null} arena Arena Brawl
* @property {Arcade|null} arcade Arcade
* @property {WoolWars|null} woolwars Wool Wars
*/
/**
* @typedef {Object} RanksPurchaseTime
Expand Down
2 changes: 1 addition & 1 deletion src/structures/ServerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ServerInfo {
constructor(data, ping) {
/**
* Protocol used for retrieving info, should be 736
* @type {Number}
* @type {number}
*/
this.protocolUsed = data.version.protocol || 736;
/**
Expand Down
6 changes: 3 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2299,10 +2299,10 @@ declare module 'hypixel-api-reborn' {
}
class Color {
constructor(color: string);
toString(): string;
toHex(): string;
toName(): string;
toCode(): string;
toHex(): string;
toString(): string;
toInGameCode(): string;
}
class SkyblockInventoryItem {
constructor(data: Record<string, unknown>);
Expand Down

0 comments on commit cb55962

Please sign in to comment.