Skip to content

@mcsb/api / Exports

@mcsb/api

Table of contents

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

APIOptions

Ƭ APIOptions: Object

Default options that all implementations of BaseAPI accept.

Type declaration

NameTypeDescription
deferPolicy?IDeferPolicy | nullRate limit usage percentage at which to enable queuing requests to help ensure that your over-usage of the API doesn't get 429 rate limited. Should be a number between 0.0 and 1.0, where 0.0 means enable queueing after 0% of the rate limit has been used (i.e. all requests) and 1.0 means enable queueing after 100% (i.e. no requests). Once the queue is in use, this will use the rate limit headers found in the response from the API to determine how much time needs to pass before another request can be made to ensure that not all requests are used up before the rate limit timer resets. Requests will then be processed in the queue with the required delay between each request. This value can also be a boolean, where true means enable queueing at any percentage (same as providing 0.0) and false means disable queueing entirely (same as providing 1.0).
httpClient?HttpClientCustom HTTP client to use for HTTP requests to the Mojang API. If not provided, a default HTTP client will be used, which simply uses the fetch function. Custom HTTP clients are particularly useful for test suites where you want to mock an HTTP request. Custom clients can also be useful for adding custom logging or error handling for HTTP requests.

Defined in

packages/api/src/BaseAPI.ts:72


CacheItem

Ƭ CacheItem<T>: Object

Container for storing values of type T along with a timestamp at which the value was saved in the Cache. This is useful for CachePolicy implementations which invalidate the cached values after a certain period of time.

Type parameters

NameTypeDescription
TanyThe type of the value stored in the cache.

Type declaration

NameTypeDescription
creatednumberUnix timestamp in milliseconds at which the value was first inserted into the Cache.
valueTThe value stored in the cache.

Defined in

packages/api/src/cache/Cache.ts:35


CacheOptions

Ƭ CacheOptions<T>: Object

The options that can be provided to a Cache constructor.

Type parameters

NameDescription
TThe type of the values stored in the cache.

Type declaration

NameTypeDescription
policyCachePolicy<T>The policy that defines how the Cache should determine whether a given entry is valid (or, more technically speaking, a "hit").
startGarbageCollection?() => voidFunction used to start a custom garbage collection mechanism. Without this, the default garbage collection mechanism will be used (check all items against the CachePolicy every 60 seconds). To disable garbage collection, you can pass an empty function here. If you have a custom implementation, you may want to also implement stopGarbageCollection.
stopGarbageCollection?() => voidFunction used to stop a custom garbage collection mechanism. Without this, the default garbage collection mechanism will attempt to stop the internal default garbage collection interval. You should not use this option without also using startGarbageCollection (doing so will cause the default garbage collector to never shut down).

Defined in

packages/api/src/cache/Cache.ts:7


HypixelAPIOptions

Ƭ HypixelAPIOptions: APIOptions & { apiKey: string }

Extension of APIOptions that also requires a Hypixel API key.

Defined in

packages/api/src/HypixelAPI.ts:64


HypixelBooster

Ƭ HypixelBooster: z.infer<BoosterSchema>["boosters"][number]

Defined in

packages/api/src/schemas/hypixel/BoosterSchema.ts:9


HypixelChallenge

Ƭ HypixelChallenge: z.infer<ChallengesResourceSchema>["challenges"][string][number]

Defined in

packages/api/src/schemas/hypixel/resources/ChallengesResourceSchema.ts:6


HypixelGame

Ƭ HypixelGame: z.infer<GamesResourceSchema>["games"][keyof typeof EnumHypixelGames]

Defined in

packages/api/src/schemas/hypixel/resources/GamesResourceSchema.ts:7


HypixelGameAchievements

Ƭ HypixelGameAchievements: z.infer<AchievementsResourceSchema>["achievements"][string]

Defined in

packages/api/src/schemas/hypixel/resources/AchievementsResourceSchema.ts:6


HypixelGamePlayerCount

Ƭ HypixelGamePlayerCount: HypixelPlayerCounts["games"][keyof typeof EnumHypixelPlayerCounts]

Type-safe representation of the player data of a Hypixel game, retrieved from the /counts Hypixel endpoint. This type does not have its fields documented due to the size of the inferred type. Look at the source definition to see the data structure.

See

https://api.hypixel.net/#tag/Other/paths/~1counts/get

Defined in

packages/api/src/schemas/hypixel/PlayerCountsSchema.ts:19


HypixelGuild

Ƭ HypixelGuild: z.infer<GuildSchema>["guild"]

Defined in

packages/api/src/schemas/hypixel/GuildSchema.ts:37


HypixelGuildAchievements

Ƭ HypixelGuildAchievements: z.infer<GuildAchievementsResourceSchema>

Defined in

packages/api/src/schemas/hypixel/resources/GuildAchievementsResourceSchema.ts:6


HypixelLeaderboard

Ƭ HypixelLeaderboard: Exclude<HypixelLeaderboards[z.infer<typeof ZodEnumHypixelGames>], undefined>[number]

Defined in

packages/api/src/schemas/hypixel/LeaderboardsSchema.ts:10


HypixelLeaderboards

Ƭ HypixelLeaderboards: z.infer<LeaderboardsSchema>["leaderboards"]

Defined in

packages/api/src/schemas/hypixel/LeaderboardsSchema.ts:9


HypixelOneTimeAchievement

Ƭ HypixelOneTimeAchievement: HypixelGameAchievements["one_time"][string]

Defined in

packages/api/src/schemas/hypixel/resources/AchievementsResourceSchema.ts:8


HypixelOneTimeGuildAchievement

Ƭ HypixelOneTimeGuildAchievement: HypixelGuildAchievements["one_time"][string]

Defined in

packages/api/src/schemas/hypixel/resources/GuildAchievementsResourceSchema.ts:8


HypixelPet

Ƭ HypixelPet: z.infer<PetsResourceSchema>["types"][number]

Defined in

packages/api/src/schemas/hypixel/resources/PetsResourceSchema.ts:7


HypixelPlayer

Ƭ HypixelPlayer: z.infer<PlayerSchema>["player"]

Type-safe representation of the Player object retrieved from the /player Hypixel endpoint. This type does not have its fields documented due to the size of the inferred type. Look at the source definition to see the data structure.

See

https://api.hypixel.net/#tag/Player-Data/paths/~1player/get

Defined in

packages/api/src/schemas/hypixel/PlayerSchema.ts:22


HypixelPlayerCounts

Ƭ HypixelPlayerCounts: z.infer<PlayerCountsSchema>

Type-safe representation of the data retrieved from the /counts Hypixel endpoint. This type does not have its fields documented due to the size of the inferred type. Look at the source definition to see the data structure.

See

https://api.hypixel.net/#tag/Other/paths/~1counts/get

Defined in

packages/api/src/schemas/hypixel/PlayerCountsSchema.ts:12


HypixelPunishmentStatistics

Ƭ HypixelPunishmentStatistics: z.infer<PunishmentStatisticsSchema>

Defined in

packages/api/src/schemas/hypixel/PunishmentStatisticsSchema.ts:5


HypixelQuest

Ƭ HypixelQuest: z.infer<QuestsResourceSchema>["quests"][string][number]

Defined in

packages/api/src/schemas/hypixel/resources/QuestsResourceSchema.ts:6


HypixelRarity

Ƭ HypixelRarity: z.infer<PetsResourceSchema>["rarities"][number]

Defined in

packages/api/src/schemas/hypixel/resources/PetsResourceSchema.ts:8


HypixelRecentGame

Ƭ HypixelRecentGame: Exclude<z.infer<RecentGamesSchema>["games"], undefined | null>[number]

Defined in

packages/api/src/schemas/hypixel/RecentGamesSchema.ts:8


HypixelResourcesOptions

Ƭ HypixelResourcesOptions: APIOptions & { refreshInterval?: number }

Extension of APIOptions that accepts a refresh interval for resources.

Defined in

packages/api/src/HypixelResources.ts:44


HypixelSession

Ƭ HypixelSession: Exclude<HypixelStatus["session"], null | undefined>

Defined in

packages/api/src/schemas/hypixel/StatusSchema.ts:7


HypixelSkyBlockAuction

Ƭ HypixelSkyBlockAuction: Exclude<z.infer<SkyBlockAuctionSchema>["auctions"], undefined | null>[number]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockAuctionSchema.ts:10


HypixelSkyBlockAuctions

Ƭ HypixelSkyBlockAuctions: Exclude<z.infer<SkyBlockAuctionsSchema>, undefined | null>

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockAuctionSchema.ts:9


HypixelSkyBlockBazaarProduct

Ƭ HypixelSkyBlockBazaarProduct: z.infer<SkyBlockBazaarSchema>["products"][string]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockBazaarSchema.ts:5


HypixelSkyBlockBingo

Ƭ HypixelSkyBlockBingo: z.infer<SkyBlockBingoResourceSchema>

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockBingoResourceSchema.ts:6


HypixelSkyBlockBingoGoal

Ƭ HypixelSkyBlockBingoGoal: HypixelSkyBlockBingo["goals"][number]

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockBingoResourceSchema.ts:7


HypixelSkyBlockBingoProfile

Ƭ HypixelSkyBlockBingoProfile: z.infer<SkyBlockBingoSchema>["events"][number]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockBingoSchema.ts:5


HypixelSkyBlockCollection

Ƭ HypixelSkyBlockCollection: z.infer<SkyBlockCollectionsResourceSchema>["collections"][string]

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockCollectionsResourceSchema.ts:6


HypixelSkyBlockElection

Ƭ HypixelSkyBlockElection: z.infer<SkyBlockElectionResourceSchema>["current"]

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockElectionResourceSchema.ts:8


HypixelSkyBlockEndedAuction

Ƭ HypixelSkyBlockEndedAuction: Exclude<z.infer<SkyBlockEndedAuctionsSchema>["auctions"], undefined | null>[number]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockAuctionSchema.ts:11


HypixelSkyBlockFiresale

Ƭ HypixelSkyBlockFiresale: z.infer<SkyBlockFiresalesSchema>["sales"][number]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockFiresalesSchema.ts:6


HypixelSkyBlockItem

Ƭ HypixelSkyBlockItem: z.infer<SkyBlockItemsResourceSchema>["items"][number]

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockItemsResourceSchema.ts:6


HypixelSkyBlockMayor

Ƭ HypixelSkyBlockMayor: z.infer<SkyBlockElectionResourceSchema>["mayor"]

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockElectionResourceSchema.ts:6


HypixelSkyBlockMayorCandidate

Ƭ HypixelSkyBlockMayorCandidate: Exclude<z.infer<SkyBlockElectionResourceSchema>["current"], null | undefined>["candidates"][number]

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockElectionResourceSchema.ts:7


HypixelSkyBlockMuseum

Ƭ HypixelSkyBlockMuseum: z.infer<SkyBlockMuseumSchema>["members"][string]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockMuseumSchema.ts:8


HypixelSkyBlockNews

Ƭ HypixelSkyBlockNews: z.infer<SkyBlockNewsSchema>["items"][number]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockNewsSchema.ts:6


HypixelSkyBlockProfile

Ƭ HypixelSkyBlockProfile: z.infer<SkyBlockProfileSchema>["profile"]

Defined in

packages/api/src/schemas/hypixel/skyblock/SkyBlockProfileSchema.ts:10


HypixelSkyBlockSkill

Ƭ HypixelSkyBlockSkill: z.infer<SkyBlockSkillsResourceSchema>["skills"][string]

Defined in

packages/api/src/schemas/hypixel/resources/skyblock/SkyBlockSkillsResourceSchema.ts:8


HypixelStatus

Ƭ HypixelStatus: z.infer<StatusSchema>

Defined in

packages/api/src/schemas/hypixel/StatusSchema.ts:6


HypixelTieredAchievement

Ƭ HypixelTieredAchievement: HypixelGameAchievements["tiered"][string]

Defined in

packages/api/src/schemas/hypixel/resources/AchievementsResourceSchema.ts:7


HypixelTieredGuildAchievement

Ƭ HypixelTieredGuildAchievement: HypixelGuildAchievements["tiered"][string]

Defined in

packages/api/src/schemas/hypixel/resources/GuildAchievementsResourceSchema.ts:7


MinecraftFormattingCode

Ƭ MinecraftFormattingCode: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | "a" | "b" | "c" | "d" | "e" | "f" | "k" | "l" | "m" | "n" | "o" | "r"

Type containing all the currently-used Minecraft formatting codes on Hypixel.

See

Defined in

packages/api/src/schemas/enums.ts:222


MojangProfile

Ƭ MojangProfile: z.infer<typeof UuidToProfileSchema>

Defined in

packages/api/src/schemas/mojang/UuidToProfileSchema.ts:5

Variables

EnumHypixelGames

Const EnumHypixelGames: Values<["QUAKECRAFT", "SKYCLASH", "BUILD_BATTLE", "UHC", "LEGACY", "SKYBLOCK", "HOUSING", "MCGO", "WOOL_GAMES", "SURVIVAL_GAMES", "BATTLEGROUND", "MURDER_MYSTERY", "ARCADE", "ARENA", "TNTGAMES"]> = ZodEnumHypixelGames.enum

Enumerable object containing all the currently-known game types available in the Hypixel API. Specifically, this enum mirrors the "Type Name" column on the official Hypixel API documentation. It is also used as the key in the value HypixelResources.games.

Example

ts
const bedwarsModes = hypixel.getResources().games.BEDWARS.modeNames
// same as
const bedwarsModes = hypixel.getResources().games[EnumHypixelGames.BEDWARS].modeNames
const bedwarsModes = hypixel.getResources().games.BEDWARS.modeNames
// same as
const bedwarsModes = hypixel.getResources().games[EnumHypixelGames.BEDWARS].modeNames

See

HypixelGame

Defined in

packages/api/src/schemas/enums.ts:65


EnumHypixelGuildAchievements

Const EnumHypixelGuildAchievements: Values<["EXPERIENCE_KINGS", "WINNERS", "ONLINE_PLAYERS"]> = ZodEnumHypixelGuildAchievements.enum

Enumerable object containing all the currently-known guild achievement keys.

Example

ts
const guild = await hypixel.getGuild("b876ec32-e396-476b-a115-8438d83c67d4")
const onlinePlayersValue = guild?.achievements.ONLINE_PLAYERS ?? 0
// same as
const onlinePlayersValue = guild?.achievements[EnumHypixelGuildAchievements.ONLINE_PLAYERS] ?? 0
const guild = await hypixel.getGuild("b876ec32-e396-476b-a115-8438d83c67d4")
const onlinePlayersValue = guild?.achievements.ONLINE_PLAYERS ?? 0
// same as
const onlinePlayersValue = guild?.achievements[EnumHypixelGuildAchievements.ONLINE_PLAYERS] ?? 0

See

HypixelGuild

Defined in

packages/api/src/schemas/enums.ts:19


EnumHypixelPetConsumables

Const EnumHypixelPetConsumables: Values<["CARROT_ITEM", "BAKED_POTATO", "FEATHER", "ROTTEN_FLESH", "SLIME_BALL", "COOKED_BEEF", "RAW_FISH", "WATER_BUCKET", "WOOD_SWORD", "MILK_BUCKET", "GOLD_RECORD", "PORK", "PUMPKIN_PIE", "LEASH"]> = ZodEnumHypixelPetConsumables.enum

Enumerable object containing all the currently-known types of food that is available for lobby pets to eat. Each value is a CAMEL_CASE representation of the item name.

Example

ts
const player = await hypixel.getPlayer("b876ec32-e396-476b-a115-8438d83c67d4")
const slimeBallsRemaining = player?.petConsumables?.SLIME_BALL
// same as
const slimeBallsRemaining = player?.petConsumables?.[EnumHypixelPetConsumables.SLIME_BALL]
const player = await hypixel.getPlayer("b876ec32-e396-476b-a115-8438d83c67d4")
const slimeBallsRemaining = player?.petConsumables?.SLIME_BALL
// same as
const slimeBallsRemaining = player?.petConsumables?.[EnumHypixelPetConsumables.SLIME_BALL]

See

HypixelPlayer

Defined in

packages/api/src/schemas/enums.ts:154


EnumHypixelPlayerCounts

Const EnumHypixelPlayerCounts: Values<["QUAKECRAFT", "SKYCLASH", "BUILD_BATTLE", "UHC", "LEGACY", "SKYBLOCK", "HOUSING", "MCGO", "WOOL_GAMES", "SURVIVAL_GAMES", "BATTLEGROUND", "MURDER_MYSTERY", "ARCADE", "ARENA", "TNTGAMES"]> = ZodEnumHypixelPlayerCounts.enum

Enumerable object containing all the currently-known "game types" that are listed in the player counts from the Hypixel API endpoint /counts. Each game type is formatted in CAMEL_CASE.

Example

ts
const playerCounts = await hypixel.getPlayerCounts()
const bedwarsPlayerCount = playerCounts.BEDWARS?.players
// same as
const bedwarsPlayerCount = playerCounts[EnumHypixelPlayerCounts.BEDWARS]?.players
const playerCounts = await hypixel.getPlayerCounts()
const bedwarsPlayerCount = playerCounts.BEDWARS?.players
// same as
const bedwarsPlayerCount = playerCounts[EnumHypixelPlayerCounts.BEDWARS]?.players

See

HypixelPlayer

Defined in

packages/api/src/schemas/enums.ts:112


EnumHypixelSkyBlockDungeonClasses

Const EnumHypixelSkyBlockDungeonClasses: Values<["healer", "archer", "mage", "tank", "berserk"]> = ZodEnumHypixelSkyBlockDungeonClasses.enum

Enumerable object containing all the currently-known classes available in SkyBlock dungeons. Each value is all lowercase.

Example

ts
const profile = await hypixel.getSkyBlockProfile("b876ec32-e396-476b-a115-8438d83c67d4")
const dungeons = profile?.members["b876ec32-e396-476b-a115-8438d83c67d4"]?.dungeons;

const healerExp = dungeons?.player_classes?.healer?.experience ?? 0;
// same as
const healerExp = dungeons?.player_classes?.[EnumHypixelSkyBlockDungeonClasses.healer]?.experience ?? 0;

console.log(`Player has ${healerExp} experience in the healer class.`);
const profile = await hypixel.getSkyBlockProfile("b876ec32-e396-476b-a115-8438d83c67d4")
const dungeons = profile?.members["b876ec32-e396-476b-a115-8438d83c67d4"]?.dungeons;

const healerExp = dungeons?.player_classes?.healer?.experience ?? 0;
// same as
const healerExp = dungeons?.player_classes?.[EnumHypixelSkyBlockDungeonClasses.healer]?.experience ?? 0;

console.log(`Player has ${healerExp} experience in the healer class.`);

See

HypixelSkyBlockProfile

Defined in

packages/api/src/schemas/enums.ts:90


EnumMinecraftFireworkShapes

Const EnumMinecraftFireworkShapes: Values<["BURST", "STAR", "BALL_LARGE", "BALL", "CREEPER"]> = ZodEnumMinecraftFireworkShapes.enum

Enumerable object containing all the currently-known firework shapes available in the lobby fireworks customizer. Each value is a CAMEL_CASE representation of the item name.

Example

ts
const player = await hypixel.getPlayer("b876ec32-e396-476b-a115-8438d83c67d4")
const playerFireworks = player?.fireworkStorage ?? [];

for(const firework of playerFireworks) {
   if(firework.shape === EnumMinecraftFireworkShapes.CREEPER) {
       console.log("Sssssssss...")
   }
}
const player = await hypixel.getPlayer("b876ec32-e396-476b-a115-8438d83c67d4")
const playerFireworks = player?.fireworkStorage ?? [];

for(const firework of playerFireworks) {
   if(firework.shape === EnumMinecraftFireworkShapes.CREEPER) {
       console.log("Sssssssss...")
   }
}

See

HypixelPlayer

Defined in

packages/api/src/schemas/enums.ts:178


EnumMinecraftFormatting

Const EnumMinecraftFormatting: Values<["BLACK", "DARK_BLUE", "DARK_GREEN", "DARK_AQUA", "DARK_RED", "DARK_PURPLE", "GOLD", "GRAY", "DARK_GRAY", "BLUE", "GREEN", "AQUA", "RED", "LIGHT_PURPLE", "YELLOW", "WHITE", "OBFUSCATED"]> = ZodEnumMinecraftFormatting.enum

Enumerable object containing all the currently-used Minecraft formatting styles on Hypixel. Each value is a CAMEL_CASE representation of the color code name. For the formatting style's code, use getFormattingCode to convert it.

See

Defined in

packages/api/src/schemas/enums.ts:213


MONGODB_ID_REGEX

Const MONGODB_ID_REGEX: RegExp

Regular expression for MongoDB object IDs. Guilds can be fetched from the Hypixel API based on their ID, which is in this format.

See

https://www.mongodb.com/docs/manual/reference/method/ObjectId/

Defined in

packages/api/src/util.ts:15


UUID_REGEX

Const UUID_REGEX: RegExp

Regular expression for v4 UUIDs, with the dashes being optional. The Hypixel API uses and accepts them interchangeably.

See

https://api.hypixel.net/#section/Introduction/Notes

Defined in

packages/api/src/util.ts:8

Functions

getFormattingCode

getFormattingCode(color): MinecraftFormattingCode

Convert a CAMEL_CASE Minecraft style name into the single-digit formatting code used for inline Minecraft text styles.

Parameters

NameTypeDescription
color"BLACK" | "DARK_BLUE" | "DARK_GREEN" | "DARK_AQUA" | "DARK_RED" | "DARK_PURPLE" | "GOLD" | "GRAY" | "DARK_GRAY" | "BLUE" | "GREEN" | "AQUA" | "RED" | "LIGHT_PURPLE" | "YELLOW" | "WHITE" | "OBFUSCATED" | "BOLD" | "STRIKE" | "UNDERLINE" | "ITALIC" | "RESET"The Minecraft formatting style in CAMEL_CASE. The full list of styles is available on the Minecraft wiki, or in EnumMinecraftFormatting.

Returns

MinecraftFormattingCode

The Minecraft formatting code for the provided style. This is a single character or a number 0-9.

Example

ts
const player = await hypixel.getPlayer("b876ec32-e396-476b-a115-8438d83c67d4")
if(!player) return;

const rankColorCode = getFormattingCode(player.monthlyRankColor)
const message = `The player ${player.displayname} has a §${rankColorCode}${player.monthlyRankColor}§r rank!`
console.log(message) // The player Player123 has a §6GOLD§r rank!
const player = await hypixel.getPlayer("b876ec32-e396-476b-a115-8438d83c67d4")
if(!player) return;

const rankColorCode = getFormattingCode(player.monthlyRankColor)
const message = `The player ${player.displayname} has a §${rankColorCode}${player.monthlyRankColor}§r rank!`
console.log(message) // The player Player123 has a §6GOLD§r rank!

See

Defined in

packages/api/src/util.ts:240


networkExpToLevel

networkExpToLevel(exp): number

Function to calculate a player's current level based on how much experience they have. The amount of experience per level increases by 2,500 for each level, and starts at 10,000 to get from level 1 to 2. Players start at level 1 (i.e., no level 0).

This function does not return partial levels, and instead rounds down. Because experience per level grows quadratically, the calculated value between two levels is not going to be linear. For example, if level 2 requires 10,000 total XP and level 3 requires 22,500 total XP, the midpoint would be 16,250. However, this equates to ~2.525 on the curve. This is likely not the desired behavior by someone using this function, so we don't include it. If you want this value, use networkExpToLevelQuadratic. To get a linear progression to the next level, use networkLevelProgress.

Parameters

NameTypeDescription
expnumberAmount of network experience to get the corresponding level for. Must be an integer greater than or equal to 0. Behavior is undefined when greater than Number.MAX_SAFE_INTEGER.

Returns

number

The network level that the given amount of experience is able to get a player to, but no more.

Throws

Error if the provided value is not an integer greater than or equal to 0.

See

Example

ts
networkExpToLevel(10000) // 2
networkExpToLevel(22500) // 3
networkExpToLevel(37500) // 4
networkExpToLevel(10000) // 2
networkExpToLevel(22500) // 3
networkExpToLevel(37500) // 4

Defined in

packages/api/src/util.ts:100


networkExpToLevelQuadratic

networkExpToLevelQuadratic(exp): number

Function to calculate a player's current level based on how much experience they have. The amount of experience per level increases by 2,500 for each level, and starts at 10,000 to get from level 1 to 2. Players start at level 1 (i.e., no level 0).

Unlike networkExpToLevel, this function does support partial levels. Because experience per level grows quadratically, the calculated value between two levels is not going to be linear. For example, if level 2 requires 10,000 total XP and level 3 requires 22,500 total XP, the midpoint would be 16,250. However, this equates to ~1.525 on the curve. This is often not the desired value, but this function is available for when it is. To get a linear progression to the next level instead, use networkExpToLevel and networkLevelProgress.

Parameters

NameTypeDescription
expnumberAmount of network experience to get the corresponding level for. Must be an integer greater than or equal to 0. Behavior is undefined when greater than Number.MAX_SAFE_INTEGER.

Returns

number

The maximum network level that the given amount of experience is able to get a player to.

Throws

Error if the provided value is not an integer greater than or equal to 0.

See

Example

ts
networkExpToLevelQuadratic(16250) // 2.524937810560445
networkExpToLevelQuadratic(16250) // 2.524937810560445

Defined in

packages/api/src/util.ts:67


networkLevelExpDifference

networkLevelExpDifference(a, b): number

The difference in experience required to reach two given network levels. This is just equivalent to networkLevelToExp(b) - networkLevelToExp(a). As a result, this function cannot handle partial levels.

Parameters

NameTypeDescription
anumberFirst network level, inclusive. Must be an integer greater than or equal to 1. Behavior is undefined when greater than 2,684,352, as above this, the required experience for the level is greater than Number.MAX_SAFE_INTEGER.
bnumberSecond network level, exclusive. Must be an integer greater than or equal to 1. Behavior is undefined when greater than 2,684,352, as above this, the required experience for the level is greater than Number.MAX_SAFE_INTEGER.

Returns

number

The difference in experience required to reach the second level from the first level.

Throws

Error if either of the provided values are less than 0 or not integers.

See

Example

ts
networkLevelExpDifference(1, 2) // 10000
networkLevelExpDifference(2, 3) // 12500
networkLevelExpDifference(2, 4) // 27500
networkLevelExpDifference(1, 2) // 10000
networkLevelExpDifference(2, 3) // 12500
networkLevelExpDifference(2, 4) // 27500

Defined in

packages/api/src/util.ts:160


networkLevelProgress

networkLevelProgress(exp, target, start?): number

Linear progress between two network levels.

Parameters

NameTypeDefault valueDescription
expnumberundefinedAmount of network experience to get the corresponding linear progression point for, e.g. the player's current experience.
targetnumberundefinedNetwork level to calculate the linear progression point for. Must be an integer greater than or equal to 1. Must not be equal to start. Behavior is undefined when greater than 2,684,352, as above this, the required experience for the level is greater than Number.MAX_SAFE_INTEGER.
startnumber1Optional starting network level. Defaults to 1. Must be an integer greater than or equal to 1. Must not be equal to start. Behavior is undefined when greater than 2,684,352, as above this, the required experience for the level is greater than Number.MAX_SAFE_INTEGER

Returns

number

A floating point value between 0 and 1 indicating the point at which exp sits on the linear scale between start and target. Value will be greater than 1 if exp is already greater than the required experience for the target level, or will be less than 0 if exp is less than the required experience for the start level.

Throws

  • Error if either start or target are less than 0 or not integers.
  • Error if target and start are equal to each other.

Example

ts
// Progress to get to the next level.
const exp = 16250; // (level 2 EXP + level 3 EXP) / 2
const level = networkExpToLevel(exp); // 2
const remaining = networkLevelProgress(exp, level + 1, level); // 0.5
// Progress to get to the next level.
const exp = 16250; // (level 2 EXP + level 3 EXP) / 2
const level = networkExpToLevel(exp); // 2
const remaining = networkLevelProgress(exp, level + 1, level); // 0.5

See

Defined in

packages/api/src/util.ts:219


networkLevelRemainingExp

networkLevelRemainingExp(exp, level): number

Calculates the amount of experience needed to reach a given network level starting from the provided experience.

Parameters

NameTypeDescription
expnumberBase amount of network experience, e.g. what a player has already earned. Behavior is undefined when greater than Number.MAX_SAFE_INTEGER.
levelnumberNetwork level to calculate the amount of remaining experience required to reach. Must be an integer greater than or equal to 1. Behavior is undefined when greater than 2,684,352, as above this, the required experience is greater than Number.MAX_SAFE_INTEGER.

Returns

number

The remaining amount of XP required to reach the provided level. If the starting amount of XP is already passed the required amount of XP for the level, a negative number will be returned, indicative of how much XP it is over (or 0, if the XP is exactly the right amount).

Throws

Error if the provided level is less than 0 or not an integer.

Example

ts
// Amount of experience remaining to get to the next level.
const exp = 50000;
const level = networkExpToLevel(exp); // 4
const remaining = networkLevelRemainingExp(exp, level + 1); // 5000
// Amount of experience remaining to get to the next level.
const exp = 50000;
const level = networkExpToLevel(exp); // 4
const remaining = networkLevelRemainingExp(exp, level + 1); // 5000

See

Defined in

packages/api/src/util.ts:186


networkLevelToExp

networkLevelToExp(level): number

Calculate the amount of experience required to reach a given network level starting from zero experience. This function is not able to handle partial levels (i.e., non-integer inputs). To get a linear partial level, use networkLevelExpDifference. Getting the quadratic partial level is currently not supported.

Parameters

NameTypeDescription
levelnumberNetwork level to calculate the amount of experience required to reach. Must be an integer greater than or equal to 1. Behavior is undefined when greater than 2,684,352, as above this, the required experience is greater than Number.MAX_SAFE_INTEGER.

Returns

number

The minimum amount of experience a player would need to get in order to get from 0 EXP to the provided level.

Throws

Error if the provided value is not an integer greater than or equal to 1.

See

Example

ts
networkLevelToExp(1) // 0
networkLevelToExp(2) // 10000
networkLevelToExp(3) // 22500
networkLevelToExp(4) // 37500
networkLevelToExp(1) // 0
networkLevelToExp(2) // 10000
networkLevelToExp(3) // 22500
networkLevelToExp(4) // 37500

Defined in

packages/api/src/util.ts:130

Released under the MIT License.