@atosjs/pokemon
v1.0.0
Published
<div align="center"> <img src="../../assets/images/atosPNG.png" width="456" alt="@atosjs/pokemon"></img>
Readme
A simple and easy-to-use JavaScript/TypeScript library to fetch Pokémon data from the PokeAPI.
Installation
To use PokeDex in your project, install it via npm:
npm install @atosjs/pokemonUsage
Importing the Library
If you're using CommonJS:
const { PokeDex } = require("@atosjs/pokemon");If you're using ES Modules:
import { PokeDex } from "@atosjs/pokemon";Fetching Pokémon Data
Create an instance of PokeDex and use the fetch method to retrieve Pokémon details.
Fetch by Name
const pokedex = new PokeDex();
async function getPokemon() {
const pikachu = await pokedex.fetch({ name: "pikachu" });
console.log(pikachu);
}
getPokemon();Fetch by ID
async function getPokemonById() {
const bulbasaur = await pokedex.fetch({ id: 1 });
console.log(bulbasaur);
}
getPokemonById();Fetch Multiple Pokémon
async function getMultiplePokemon() {
const pokemons = await pokedex.fetch({ id: [25, 4, 7] }); // Pikachu, Charmander, Squirtle
console.log(pokemons);
}
getMultiplePokemon();Accessing Pokémon Data
The returned object contains the following properties:
{
name: "pikachu",
id: 25,
type: ["electric"],
abilities: ["static", "lightning-rod"],
sprite: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/25.png",
height: 4,
weight: 60,
base_stats: {
hp: 35,
attack: 55,
defense: 40,
speed: 90,
},
evolution_chain: {
url: "https://pokeapi.co/api/v2/evolution-chain/10/"
},
description: "Whenever Pikachu comes across something new, it blasts it with electricity."
}Fetch and Display Pokémon Sprite
async function getSprite() {
const pikachu = await pokedex.fetch({ name: "pikachu" });
console.log("Sprite URL:", pikachu.sprite);
}
getSprite();Error Handling
If an invalid Pokémon name or ID is provided, an error will be thrown.
async function invalidPokemon() {
try {
const unknown = await pokedex.fetch({ name: "unknownpokemon" });
} catch (error) {
console.error("Error:", error.message);
}
}
invalidPokemon();Links
- Website | Documentation | Discord
- GitHub monorep.
- NPM, Latest version:
v1.0.0.
