2021-03-17 23:52:35 -04:00
2021-03-17 23:51:13 -04:00
2021-03-15 23:23:06 -04:00
2021-03-15 23:23:06 -04:00
2021-03-15 21:43:43 -04:00
2021-03-15 21:43:43 -04:00
2019-10-12 13:44:01 -04:00
2021-03-15 21:44:36 -04:00
2021-03-15 08:45:16 -04:00
2021-03-15 08:37:56 -04:00
2021-03-15 21:45:12 -04:00
2021-03-16 00:18:09 -04:00

Pokeemon TCG SDK TypeScript

Now supporting Version 2 of the Pokémon TCG API! Please refer to the V1 to V2 Migration section of the official API docs for more information.

pokemontcg-developers on discord pokemon-tcg-sdk-typescript build status

This is the TypeScript SDK for the Pokémon Trading Card Game API.

Installation

npm

npm install pokemon-tcg-sdk-typescript

yarn

yarn add pokemon-tcg-sdk-typescript

Configuration

The SDK works out of the box! Simply import the SDK, and you're ready to go:

import PokemonTCG from '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. An API key unlocks higher race limits, and can be adjusted to meet your needs if necessary. Create an account at https://dev.pokemontcg.io to grab an API key.

To use the SDK with an API key, set your API key to the environment variable POKEMONTCG_API_KEY in a .env file.

Usage

Card methods

  • findCardByID()
  • findCardsByQueries()
  • getAllCards()
  • getTypes()
  • getSupertypes()
  • getSubtypes()
  • getRarities()

Set methods

  • findSetByID()
  • findSetsByQueries()
  • getAllSets()

findCardByID()

Returns a single Pokémon card given an ID.

import PokemonTCG from 'pokemon-tcg-sdk-typescript';

PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.Card) => {
    console.log(card.name) // Gardevoir
})

findCardByQueries()

Returns an array of cards filtered through a search query.

import PokemonTCG from 'pokemon-tcg-sdk-typescript';

const params: PokemonTCG.Query[] = [{
   name: 'id',
   value: 'xy7-54'
}]

PokemonTCG.findCardsByQueries(params).then((cards: PokemonTCG.Card[]) => {
   console.log(card[0].name) // Gardevoir
})

getAllCards()

Returns all Pokémon cards available through recursive pagination

import PokemonTCG from 'pokemon-tcg-sdk-typescript';

PokemonTCG.getAllCards();
ability: IAbility;
ancientTrait?: IAncientTrait;
artist: string;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
imageUrl: string;
imageUrlHiRes: string;
name: string;
nationalPokedexNumber: number;
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
series: string;
set: string;
setCode: string;
subtype: string;
supertype: string;
text: string[];
types: string[];
weaknesses: IWeakness[];

IAbility

name: string;
text: string;
type: string;

IAttack

cost: string[];
name: string;
text: string;
damage: string;
convertedEnergyCost: string;

IResistance, IWeakness

type: string;
value: string;

Set

code: string;
expandedLegal: boolean;
logoUrl: string;
name: string;
ptcgoCode: string;
releaseDate: string;
series: string;
standardLegal: boolean;
symbolUrl: string;
totalCards: number;
updatedAt: string;

IQuery

{ name: string, value: string | number }

Method Definitions

Card.find(id: string): Promise<Card>
Card.where(params: IQuery[]): Promise<Card[]>
Card.all(): Promise<Card[]>

Set.find(id: string): Promise<Set>
Set.where(params: IQuery[]): Promise<Set[]>
Set.all(): Promise<Set[]>

Meta.allTypes(): Promise<string[]>
Meta.allSubtypes(): Promise<string[]>
Meta.allSupertypes(): Promise<string[]>

Usage

All of the calls return generic promises like Promise<T> or Promise<T[]>. The type is determined from the class making the call. The examples here are using the Card class but the usage for the other classes are the same.

import { PokemonTCG } from 'pokemon-tcg-sdk-typescript'

PokemonTCG.Card.find('xy1')
  .then(card => {
    // do stuff with the card
  })
  .catch(error => {
    // do something with the error
  });

let params: PokemonTCG.IQuery[] = [{ name: 'name', value: 'Charizard' }];
PokemonTCG.Card.where(params)
  .then(cards => {
    // do stuff with the cards
  })
  .catch(error => {
    // do something with the error
  });

PokemonTCG.Card.all()
  .then(cards => {
    // do stuff with the cards
  })
  .catch(error => {
    // do something with the error
  });

Contributing

  • Fork it (click the Fork button at the top of the page)
  • Create your feature branch (git checkout -b my-new-feature)
  • Make some changes and fix some bugs!
  • Run the tests npm run-script test
  • Test your changes in a project of yours:
    • Create a link with npm or yarn (depending on what tool you installed this SDK with)
    • In your project that uses the SDK, install the linked package with yarn/npm link pokemon-tcg-sdk-typescript
    • Verify the SDK behaves as expected, and your changes took effect
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request
Description
Pokémon TCG SDK - Typescript
Readme 361 KiB
Languages
TypeScript 100%