This is the TypeScript SDK for the Pokémon Trading Card Game API.
The original SDK project seems abandoned some years already. In order to have a cleaner repository I decided not to fork the old project, but to start a ne repository. But credits to the original project as well as all it's contributors (whose names are still mentioned here in the contributors section!).
npm
npm install @pokelib/pokemon-tcg-sdk-typescript
yarn
yarn add @pokelib/pokemon-tcg-sdk-typescript
The SDK works out of the box! Simply import the SDK, and you're ready to go:
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.Card) => {
console.log(card.name); // Gardevoir
});
It is recommended to use an API key for version 2 of the API. By default, requests are limited to 20,000/day. Requests are rate limited to 1000 requests a day, and a maximum of 30 per minute.
To use the SDK with an API key, create an account at https://dev.pokemontcg.io to grab an API key.
Then set your API key to the environment variable POKEMONTCG_API_KEY
in a .env
file.
Make sure to use this exact environment variable, otherwise the SDK will not be able to read the API key.
All function calls return generic promises like Promise<T>
or Promise<T[]>
Returns a single Pokémon card given an ID.
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.ICard) => {
console.log(card.name); // Gardevoir
});
Returns an array of cards filtered through a search query.
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
const params: PokemonTCG.IParameter = { q: 'id:xy7-54' };
PokemonTCG.findCardsByQueries(params).then((cards: PokemonTCG.ICard[]) => {
console.log(card[0].name); // Gardevoir
});
Returns all Pokémon cards available through recursive pagination.
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.getAllCards();
Returns all Energy Types
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.getTypes();
Returns all Super Types
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.getSupertypes();
Returns all Sub Types
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.getSubtypes();
Returns all card Rarities
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.getRarities();
Returns a single Pokémon card given an ID.
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.findSetByID('base1').then((set: PokemonTCG.ISet) => {
console.log(set.name); // Base
});
Returns an array of cards filtered through a search query.
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
const params: PokemonTCG.IParameter = { q: 'name:Base' };
PokemonTCG.findSetsByQueries(params).then((sets: PokemonTCG.ISet[]) => {
console.log(sets[0].name); // Base
});
Returns all Pokémon sets available through recursive pagination.
import { PokemonTCG } from '@pokelib/pokemon-tcg-sdk-typescript';
PokemonTCG.getAllSets();
Contributions are welcome! If you want to contribute, feel free to fork the repository, open and issue, then submit a pull request. ESLint and Prettier are used to enforce a consistent coding style.
Raring to code your heart out? Awesome! Here's how to get started:
- Open and issue with a bug or feature. Ensure the change is not already being worked on.
- Fork and clone the repository from the
main
branch. - Create a feat00ure branch.
- Run
npm ci
to install exact versions specified in thepackage-lock.json
. - Code your heart out!
- Run
npm run test
to run ESLint and Jest tests. - (OPTIONAL) Test your changes in a project of yours:
- Create a link with
npm
oryarn
(depending on what tool you installed this SDK with) - In your project that uses the SDK, install the linked package with
yarn/npm link @pokelib/pokemon-tcg-sdk-typescript
- Verify the SDK behaves as expected, and your changes took effect
- Create a link with
- Submit a pull request! 🎉