pokeapi-typescript
About
pokeapi-typescript is a fully-typed SDK for the PokeAPI using Promises, featuring an easy to manage cache which utilises Collections
Installation
Via yarn: yarn add pokeapi-typescript
Via npm: npm install pokeapi-typescript
Getting Started
To start using the PokeAPI, import the module. All available endpoints are mounted as static properties of the module.
// ES6 imports;// Node.js requireconst PokeAPI = ;
Endpoints
Every endpoint documented in the PokeAPI Docs is available. By default, any data that is fetched will be cached in-memory.
.resolve()
PokeAPI.<Endpoint>.resolve()
retrieves a resource, first checking the internal cache to see if it is available. If no cached resource exists, it will be fetched via the API.
By ID
// Using .then()PokeAPIPokemon; // Using async/awaitconst result = await PokeAPIPokemon;
By Name
// Using.then()PokeAPIPokemon; // Using async/awaitconst result = await PokeAPIPokemon;
.fetch()
PokeAPI.<Endpoint>.fetch()
will always retrieve a resource via the API, updating any cached resources in the process.
By ID
// Using .then()PokeAPIPokemon; // Using async/awaitconst result = await PokeAPIPokemon;
By Name
// Using.then()PokeAPIPokemon; // Using async/awaitconst result = await PokeAPIPokemon;
.get()
PokeAPI.<Endpoint>.get()
will always retrieve a cached resource, returning null if one could not be found. .get()
is synchronous and does not return a Promise.
By ID
const result = PokeAPIPokemon;
By Name
const result = PokeAPIPokemon;
.list()
PokeAPI.<Endpoint>.list()
retrieves the IApiResourceList or INamedApiResourceList for an endpoint.
list()
accepts two parameters for pagination
limit
- Number of results to list. Default 20offset
- Index of result to start listing from. Default 0
// Fetch 1000 Pokemon (all) in a NamedApiResourceListconst resourceList = await PokeAPIPokemon;
resourceList.results
will contain an array of IApiResource
or INamedApiResource
objects depending on the type of list.
.listAll()
PokeAPI.<Endpoint>.listAll()
functions like the above, but will return the complete list for an endpoint. This is done by making two API calls.
// Fetch 1000 Pokemon (all) in a NamedApiResourceListconst completeResourceList = await PokeAPIPokemon;
Endpoint List
Berries
- Berry
- BerryFirmness
- BerryFlavors
Contests
- ContestType
- ContestEffect
- SuperContestEffect
Encounters
- EncounterMethod
- EncounterCondition
- EncounterConditionValue
Evolution
- EvolutionChain
- EvolutionTrigger
Games
- Generation
- Pokedex
- Version
- VersionGroup
Items
- Item
- ItemAttribute
- ItemCategory
- ItemFlingEffect
- ItemPocket
Locations
- Location
- LocationArea
- PalParkArea
- Region
Machines
- Machine
Moves
- Move
- MoveAilment
- MoveBattleStyle
- MoveCategory
- MoveDamageClass
- MoveLearnMethod
- MoveTarget
Pokemon
- Ability
- Characteristic
- EggGroup
- Gender
- GrowthRate
- Nature
- PokeathlonStat
- Pokemon
- PokemonColor
- PokemonForm
- PokemonHabitat
- PokemonShape
- PokemonSpecies
- Stat
- Type
Utility
- Language