{"version":3,"sources":["../../../../src/lib/classes/Util.ts"],"sourcesContent":["import { Base } from './Base';\nimport { HypixelTSError } from '../errors/HypixelTSError';\nimport type { GetUsernameResponse, GetUUIDResponse } from '../typings';\n\n/**\n * Utility functions\n * @category Classes\n * @group Classes\n */\nexport class Util extends Base {\n\t/**\n\t * Get the UUID of a player by providing their name\n\t * @param name The name of the player\n\t */\n\tpublic static async getUUID(name: string): Promise<string> {\n\t\ttry {\n\t\t\tconst data = await fetch(`https://api.mojang.com/users/profiles/minecraft/${name}`);\n\t\t\tconst json = (await data.json()) as GetUUIDResponse;\n\n\t\t\tif (json.errorMessage) throw new HypixelTSError('GET_UUID_ERROR', json.errorMessage, data.status);\n\t\t\treturn json.id;\n\t\t} catch {\n\t\t\tthrow new HypixelTSError('GET_UUID_404');\n\t\t}\n\t}\n\n\t/**\n\t * Get player's name from their UUID\n\t * @param uuid The uuid of the player\n\t */\n\tpublic static async getUsername(uuid: string): Promise<string> {\n\t\tif (!this.isUUID(uuid)) {\n\t\t\tthrow new HypixelTSError('NOT_UUID');\n\t\t}\n\n\t\ttry {\n\t\t\tconst data = await fetch(`https://api.mojang.com/user/profile/${uuid}`);\n\t\t\tconst json = (await data.json()) as GetUsernameResponse;\n\n\t\t\tif (json.errorMessage) throw new HypixelTSError('GET_USERNAME_ERROR', json.errorMessage, data.status);\n\n\t\t\treturn json.name;\n\t\t} catch {\n\t\t\tthrow new HypixelTSError('GET_USERNAME_404');\n\t\t}\n\t}\n\n\t/**\n\t * Check whether the provided UUID is a valid UUID or not\n\t * @param uuid The UUID to check\n\t */\n\tpublic static isUUID(uuid: string) {\n\t\tconst regexStripped = /^[0-9a-f]{32}$/i;\n\t\tconst regexFull = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\\b[0-9a-f]{12}$/i;\n\t\treturn regexStripped.test(uuid) || regexFull.test(uuid);\n\t}\n}\n"],"mappings":";;;;AAAA,SAAS,YAAY;AACrB,SAAS,sBAAsB;AAQxB,IAAM,OAAN,cAAmB,KAAK;AAAA,EAT/B,OAS+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9B,aAAoB,QAAQ,MAA+B;AAC1D,QAAI;AACH,YAAM,OAAO,MAAM,MAAM,mDAAmD,IAAI,EAAE;AAClF,YAAM,OAAQ,MAAM,KAAK,KAAK;AAE9B,UAAI,KAAK,aAAc,OAAM,IAAI,eAAe,kBAAkB,KAAK,cAAc,KAAK,MAAM;AAChG,aAAO,KAAK;AAAA,IACb,QAAQ;AACP,YAAM,IAAI,eAAe,cAAc;AAAA,IACxC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAoB,YAAY,MAA+B;AAC9D,QAAI,CAAC,KAAK,OAAO,IAAI,GAAG;AACvB,YAAM,IAAI,eAAe,UAAU;AAAA,IACpC;AAEA,QAAI;AACH,YAAM,OAAO,MAAM,MAAM,uCAAuC,IAAI,EAAE;AACtE,YAAM,OAAQ,MAAM,KAAK,KAAK;AAE9B,UAAI,KAAK,aAAc,OAAM,IAAI,eAAe,sBAAsB,KAAK,cAAc,KAAK,MAAM;AAEpG,aAAO,KAAK;AAAA,IACb,QAAQ;AACP,YAAM,IAAI,eAAe,kBAAkB;AAAA,IAC5C;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAc,OAAO,MAAc;AAClC,UAAM,gBAAgB;AACtB,UAAM,YAAY;AAClB,WAAO,cAAc,KAAK,IAAI,KAAK,UAAU,KAAK,IAAI;AAAA,EACvD;AACD;","names":[]}