-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_types.ts
36 lines (33 loc) · 1.01 KB
/
_types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import z from "https://deno.land/x/zod@v3.21.4/index.ts";
export const fetchPokemonEndpoint = "https://pokeapi.co/api/v2/pokemon/";
const PokemonType = z.object({
slot: z.number(),
type: z.object({
name: z.string(),
}),
});
export type PokemonType = z.infer<typeof PokemonType>;
export const Pokemon = z.object({
id: z.number(),
name: z.string(),
height: z.number(),
weight: z.number(),
types: z.array(PokemonType),
}).transform((p) => {
return {
...p,
imageUrl:
`https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${p.id}.png`,
};
});
export type Pokemon = z.infer<typeof Pokemon>;
export const PokemonList = z.array(Pokemon);
export type PokemonList = z.infer<typeof PokemonList>;
export function getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// we are playing with Kanto pokemon only
export const firstPokemonId = 1;
export const lastPokemonId = 151;