Magidoc

Utilities

The API also publishes an npm library called @favware/graphql-pokemon which contains a set of utilities to make usage of the API responses easier to parse. The following utilities are available:

isCapPokemon

#

isCapPokemon(pokemon ): boolean

Checks if a Pokemon is a Cap Pokemon by checking if the number is below (not equal to) 0.

MissingNo and M00 are not considered Cap Pokemon, to check if the Pokémon is either of those, use isMissingNoOrM00 .

Parameters

#

Name
Type
Description
pokemon
Pokemon
The details of the Pokemon.

Returns

#

boolean

true if the Pokemon is a Cap Pokemon, false otherwise.


isM00

#

isM00(pokemon ): boolean

Checks if the given Pokemon is M00.

This uses the Pokemon's key, rather than the number. To check if it's either MissingNo or M00, use isMissingNoOrM00 .

Parameters

#

Name
Type
Description
pokemon
Pokemon
The Pokemon to check.

Returns

#

boolean

true if the Pokemon is M00, false otherwise.


isMissingNo

#

isMissingNo(pokemon ): boolean

Checks if the given Pokemon is MissingNo.

This uses the Pokemon's key, rather than the number. To check if it's either MissingNo or M00, use isMissingNoOrM00 .

Parameters

#

Name
Type
Description
pokemon
Pokemon
The Pokemon object to check.

Returns

#

boolean

true if the Pokemon is MissingNo, false otherwise.


isMissingNoOrM00

#

isMissingNoOrM00(pokemon ): boolean

Checks if the given Pokemon is either MissingNo or M00.

This uses the Pokemon's key, rather than the number. This performs both isMissingNo and isM00 .

Parameters

#

Name
Type
Description
pokemon
Pokemon
The Pokemon to check.

Returns

#

boolean

true if the Pokemon is MissingNo or M00, false otherwise.


isRegularPokemon

#

isRegularPokemon(pokemon ): boolean

Checks if a given Pokemon is a not a CAP Pokémon nor MissingNo nor M00. This checks if the number is above (not equal to) 0.

Parameters

#

Name
Type
Description
pokemon
Pokemon
The details of the Pokemon.

Returns

#

boolean

true if the Pokemon is regular, false otherwise.


parseBulbapediaURL

#

parseBulbapediaURL(url ): string

Parses a Bulbapedia-like URL to be properly embeddable on Discord

What this essentially does is replace spaces with underscores and parentheses with their URL-encoded counterparts

Parameters

#

Name
Type
Description
url
string
The URL to be parsed.

Returns

#

string

The parsed URL with spaces replaced by underscores and parentheses encoded.

Example

#

    
  

pokemonEnumToSpecies

#

pokemonEnumToSpecies(pokemon ): string

Converts a PokemonEnum value to its corresponding species name in a human-readable format.

This can be useful when you want to display the name to the user, for example on a web dashboard or in your application.

If undefined , null or an empty string is passed in, the function will return the same value.

Parameters

#

Name
Type
Description
pokemon
PokemonEnum
The PokemonEnum value to convert.

Returns

#

string

The species name of the Pokemon in human-readable format


resolveBulbapediaURL

#

resolveBulbapediaURL(pokemon ): string

Transforms the Bulbapedia URL for a given Pokemon.

This function takes in the details of a Pokemon and returns the corresponding Bulbapedia URL.

  • If the Pokemon is MissingNo, it returns the URL for MissingNo on Bulbapedia.
  • If the Pokemon is M00, it returns the URL for M00 on Bulbapedia.

Parameters

#

Name
Type
Description
pokemon
Pokemon
The details of the Pokemon.

Returns

#

string

The resolved Bulbapedia embedded URL.

Throws

#

This function will not work for CAP or PokéStar Pokémon as they do not have Bulbapedia pages. This function will throw a RangeError when a Pokémon with Pokemon.num < 0 is passed in.

Example

#

    
  

resolveColor

#

resolveColor(color ): number

Parses PokéDex colors to Discord MessageEmbed colors

Parameters

#

Name
Type
Description
color
string
The color to parse

resolveColor(pokemon ): number

Parses PokéDex colors to Discord MessageEmbed colors

Parameters

#

Name
Type
Description
pokemon
Pokemon
The Pokemon data, with a color field, to parse

Returns

#

number

The color as a hexadecimal color code that can be used for a DiscordJS Embed

Remarks

#

The various colours that can be generated are:

  • Black: Black
  • Blue: Blue
  • Brown: Brown
  • Gray: Gray
  • Green: Green
  • Pink: Pink
  • Purple: Purple
  • Red: Red
  • White: White
  • Yellow: Yellow
  • Unknown: Unknown

resolveSerebiiUrl

#

resolveSerebiiUrl(pokemon ): string

Resolves the Serebii URL for a given Pokemon. If the Pokemon is MissingNo or M00, it returns the URL for MissingNo's Serebii page. Otherwise, it returns the URL specified in the serebiiPage property of the Pokemon object.

Parameters

#

Name
Type
Description
pokemon
Pokemon
The details of the Pokemon.

Returns

#

string

The Serebii URL for the Pokemon.

Throws

#

This function will not work for CAP or PokéStar Pokémon as they do not have Serebii pages. This function will throw a RangeError when a Pokémon with Pokemon.num < 0 is passed in.

Example

#