diff options
author | mat <github@matdoes.dev> | 2022-04-10 18:54:48 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-04-10 18:54:48 -0500 |
commit | d0f7262b1b132f990d7cdc9c88eda927515723ad (patch) | |
tree | 4734c152db4097ec356120dd918664024f88bd1f /src/util.ts | |
parent | 26aa581d96ec0db3644bb930feb8cd5bb97cfc70 (diff) | |
download | skyblock-api-d0f7262b1b132f990d7cdc9c88eda927515723ad.tar.gz skyblock-api-d0f7262b1b132f990d7cdc9c88eda927515723ad.tar.bz2 skyblock-api-d0f7262b1b132f990d7cdc9c88eda927515723ad.zip |
Cache usernames and ranks in leaderboards in db
Diffstat (limited to 'src/util.ts')
-rw-r--r-- | src/util.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/util.ts b/src/util.ts index 0d91aba..4d40cc0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -61,20 +61,22 @@ export const minecraftColorCodes: { [key: string]: string } = { * For example: blue -> 9 * @param colorName The name of the color (blue, red, aqua, etc) */ -export function colorCodeFromName(colorName: string): string | undefined { +export function colorCodeFromName(colorName: string): string | null { const hexColor = minecraftColorCodes[colorName.toLowerCase()] for (const key in minecraftColorCodes) { const value = minecraftColorCodes[key] if (key.length === 1 && value === hexColor) return key } + return null } -export function letterFromColorCode(colorCode: string): string | undefined { +export function letterFromColorCode(colorCode: string): string | null { for (const [key, value] of Object.entries(minecraftColorCodes)) { if (value === colorCode) return key } + return null } export async function sleep(ms: number): Promise<void> { @@ -95,3 +97,11 @@ export function levelFromXpTable(xp: number, xpTable: number[]) { const skillLevel = [...xpTable].reverse().findIndex(levelXp => xp >= levelXp) return skillLevel === -1 ? 0 : xpTable.length - skillLevel } + +// https://stackoverflow.com/a/51365037 +export type RecursivePartial<T> = { + [P in keyof T]?: + T[P] extends (infer U)[] ? RecursivePartial<U>[] : + T[P] extends object ? RecursivePartial<T[P]> : + T[P] +}
\ No newline at end of file |