Skip to content

Commit 5e246e5

Browse files
author
Sankarsan Kampa
committed
Added Pokedex#getPokemonByName() method
1 parent be35b7c commit 5e246e5

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/Pokedex.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ class Pokedex {
148148
return await this.makeRequest(path);
149149
};
150150

151+
/**
152+
* Returns an array of Pokémon objects containing all the forms of the Pokémon specified the name.
153+
* @method getPokemonByNumber
154+
* @param {String} name The name of the Pokémon
155+
* @returns {Promise<Object>} Resolves information about the specified Pokémon
156+
* @example
157+
* // It's best practice to use encodeURIComponent() to encode the name
158+
* // string so the API server doesn't respond with 404.
159+
* pokedex.getPokemonByName(encodeURIComponent('Pikachu'))
160+
* .then(pokemon => console.log(pokemon))
161+
* .catch(console.error);
162+
*/
163+
this.getPokemonByName = async function(name) {
164+
let path = `/pokemon/${name}`;
165+
return await this.makeRequest(path);
166+
};
167+
151168
/**
152169
* Returns an array of Pokémon objects containing all the forms of the Pokémon specified the Pokédex number.
153170
* @method getPokemonByNumber

0 commit comments

Comments
 (0)