1- const axios = require ( "axios" ) ;
1+ // @ts -ignore
2+ const { get } = require ( "axios" ) ;
23
4+ /**
5+ * @typedef {import('./bestiary.types').BestiaryConstant } BestiaryConstants
6+ * @typedef {import('./bestiary.types').Mob } Mob
7+ * @typedef {import('./bestiary.types').RawMob } RawMob
8+ */
9+
10+ /**
11+ * @param {RawMob[] } mobs
12+ * @returns {Mob[] }
13+ * */
314function formatBestiaryMobs ( mobs ) {
415 const output = [ ] ;
516 for ( const mob of mobs ) {
@@ -14,20 +25,24 @@ function formatBestiaryMobs(mobs) {
1425 return output ;
1526}
1627
28+ /** @type {Partial<{ lastUpdated: number, data: BestiaryConstants }> } */
1729const cache = { } ;
30+
31+ /**
32+ * @returns {Promise<BestiaryConstants | null> }
33+ * */
1834async function getBestiaryConstants ( ) {
1935 if ( cache . lastUpdated && cache . lastUpdated + 1000 * 60 * 60 * 12 > Date . now ( ) ) {
20- return cache . data ;
36+ return cache . data ?? null ;
2137 }
2238
23- const response = await axios . get (
24- "https://raw.githubusercontent.com/NotEnoughUpdates/NotEnoughUpdates-REPO/refs/heads/master/constants/bestiary.json"
25- ) ;
39+ const response = await get ( "https://raw.githubusercontent.com/NotEnoughUpdates/NotEnoughUpdates-REPO/refs/heads/master/constants/bestiary.json" ) ;
2640 const bestiary = response ?. data ;
2741 if ( ! bestiary ) {
2842 return null ;
2943 }
3044
45+ /** @type {BestiaryConstants } */
3146 const output = { brackets : bestiary . brackets , islands : { } } ;
3247 for ( const [ islandId , islandData ] of Object . entries ( bestiary ) . filter ( ( [ key ] ) => key !== "brackets" ) ) {
3348 if ( islandData . hasSubcategories === true ) {
@@ -37,9 +52,7 @@ async function getBestiaryConstants() {
3752 }
3853
3954 const id = islandId === categoryId ? islandId : `${ islandId } :${ categoryId } ` ;
40- const name = categoryData . name . includes ( islandData . name )
41- ? categoryData . name
42- : `${ categoryData . name } ${ islandData . name } ` ;
55+ const name = categoryData . name . includes ( islandData . name ) ? categoryData . name : `${ categoryData . name } ${ islandData . name } ` ;
4356 output . islands [ id ] = {
4457 name : name ,
4558 mobs : formatBestiaryMobs ( categoryData . mobs )
0 commit comments