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
- isM00
- isMissingNo
- isMissingNoOrM00
- isRegularPokemon
- parseBulbapediaURL
- pokemonEnumToSpecies
- resolveBulbapediaURL
- resolveColor
- resolveSerebiiUrl
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
#
pokemon
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
#
pokemon
Pokemon
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
#
pokemon
Pokemon
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
#
pokemon
Pokemon
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
#
pokemon
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
#
url
string
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
#
pokemon
PokemonEnum
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
#
pokemon
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
#
color
string
▸ resolveColor(pokemon
): number
Parses PokéDex colors to Discord MessageEmbed colors
Parameters
#
pokemon
Pokemon
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:
- Blue:
- Brown:
- Gray:
- Green:
- Pink:
- Purple:
- Red:
- White:
- Yellow:
- 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
#
pokemon
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
#
JavaScript Examples
getAbility