Skip to content

Commit

Permalink
docs: add JSDoc to pokemon-helpers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
IdoBouskila committed Jun 7, 2023
1 parent 3c2c419 commit eff529a
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/utils/pokemon-helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
export const getTypeIconSrc = (type) => `./images/types-icons/${ type }.svg`;

/**
* Formats the given Pokemon data object.
*
* @param {Object} pokemon
* @param {number} pokemon.id - The ID of the Pokemon.
* @param {string} pokemon.name - The name of the Pokemon.
* @param {Object} pokemon.sprites - The sprites object containing image URLs of the Pokemon.
* @param {number} pokemon.weight - The weight of the Pokemon.
* @param {number} pokemon.height - The height of the Pokemon.
* @param {Array} pokemon.types - The types array containing the types of the Pokemon.
* @returns {Object} - The formatted Pokemon data object.
*/
export const formatPokemonData = (pokemon) => {
const { id, name, sprites, weight, height, stats, types } = pokemon;
const { id, name, sprites, weight, height, types } = pokemon;

const weightInKg = (weight / 10 ) + 'kg';
const heightInMeter = (height / 10 ) + 'm';
Expand All @@ -20,7 +32,12 @@ export const formatPokemonData = (pokemon) => {
};
}

// create well structured object from api stats array for easier usage
/**
* Formats the stats array obtained from the API into a well-structured object for easier usage.
*
* @param {Array} stats - The stats array obtained from the API.
* @returns {Array} - The formatted stats array.
*/
export function formatStats(stats) {
const statsMaxValues = {
hp: 714,
Expand Down Expand Up @@ -74,7 +91,13 @@ export function normalizeEvolutionChain(evolutionChain) {
return evolutions;
}

// The evolution-chain endpoint doesn't provide the ID and image source of each evolved pokémon
/**
* Retrieves the image source of a Pokémon based on provided url with id.
* This is necessary because the evolution endpoint doesn't provide the ID of each evolved Pokémon.
*
* @param {string} url - The species URL or URL with the ID of the Pokémon.
* @returns {string} - The image source of the Pokémon.
*/
const getPokemonImage = (url) => {
const id = url.match(/\/(\d+)\//)[1];
const isPokemonHasSvg = id < 650;
Expand Down

0 comments on commit eff529a

Please sign in to comment.