https://github.com/monbrey/pokeapi-typescript
  
  
    Typescript SDK for PokeAPI (https://pokeapi.co) 
    https://github.com/monbrey/pokeapi-typescript
  
        Last synced: 26 days ago 
        JSON representation
    
Typescript SDK for PokeAPI (https://pokeapi.co)
- Host: GitHub
- URL: https://github.com/monbrey/pokeapi-typescript
- Owner: monbrey
- Created: 2019-08-07T21:55:28.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-11T10:08:41.000Z (8 months ago)
- Last Synced: 2025-03-19T00:17:55.845Z (8 months ago)
- Language: TypeScript
- Size: 305 KB
- Stars: 23
- Watchers: 0
- Forks: 6
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
 
Awesome Lists containing this project
README
          # pokeapi-typescript
## About
pokeapi-typescript is a fully-typed SDK for the [PokeAPI](https://pokeapi.co) using Promises, featuring an easy to manage cache which utilises [Collections](https://github.com/discordjs/collection)
## 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.
```js
// ES6 imports
import { PokeAPI } from "pokeapi-typescript";
```
### Endpoints
Every endpoint documented in the [PokeAPI Docs](https://pokeapi.co/docs/v2.html) is available. By default, any data that is fetched will be cached in-memory.
### .resolve()
`PokeAPI..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
```js
// Using .then()
PokeAPI.Pokemon.resolve(25).then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.resolve(25);
```
#### By Name
```js
// Using.then()
PokeAPI.Pokemon.resolve("pikachu").then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.resolve("pikachu");
```
### .fetch()
`PokeAPI..fetch()` will always retrieve a resource via the API, updating any cached resources in the process.
#### By ID
```js
// Using .then()
PokeAPI.Pokemon.fetch(25).then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.fetch(25);
```
#### By Name
```js
// Using.then()
PokeAPI.Pokemon.fetch("pikachu").then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.fetch("pikachu");
```
### .get()
`PokeAPI..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
```js
const result = PokeAPI.Pokemon.get(25);
```
#### By Name
```js
const result = PokeAPI.Pokemon.get("pikachu");
```
### .list()
`PokeAPI..list()` retrieves the [IApiResourceList](https://pokeapi.co/docs/v2.html#un-named) or [INamedApiResourceList](https://pokeapi.co/docs/v2.html#named) for an endpoint.
`list()` accepts two parameters for pagination
 - `limit` - Number of results to list. Default 20
 - `offset` - Index of result to start listing from. Default 0
```js
// Fetch 1000 Pokemon (all) in a NamedApiResourceList
const resourceList = await PokeAPI.Pokemon.list(1000, 0);
```
`resourceList.results` will contain an array of `IApiResource` or `INamedApiResource` objects depending on the type of list.
### .listAll()
`PokeAPI..listAll()` functions like the above, but will return the complete list for an endpoint. This is done by making two API calls.
```js
// Fetch 1000 Pokemon (all) in a NamedApiResourceList
const completeResourceList = await PokeAPI.Pokemon.listAll();
```
## 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