Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@tcgdex/sdk

tcgdex1.7kMIT2.7.0TypeScript support: included

Communicate with the Open Source TCGdex API in Javascript/Typescript using the SDK

tcgdex, pokemon, trading, card, tcg, sdk, api, typescript, javascript, typing, browser, node

readme

TCGdex Main Image

NOM Version NPM Downloads npm version Github stars the TCGdex JAvascript SDK is released under the MIT license. Discord Link

TCGdex JavaScript/TypeScript SDK

The Javascript/Typescript SDK provides a convenient access with the Open Source TCGdex API.

The SDK is available in ESM and CommonJS and should be automaticly chosen.

Documentation

The full API/SDK documentation in progress at API Documentation - TCGdex

Getting Started

How To install

In the browser

To use the SDK in the browser, simply add the following script tag to your HTML pages:

<script src="https://cdn.jsdelivr.net/npm/@tcgdex/sdk@2/dist/tcgdex.browser.js"></script>

You cna also download the script from JSDelivr by right clicking the link and selecting save link as.

In Node.js

Simply type the following into a terminal window:

npm install @tcgdex/sdk

Usage

Note: a complete documentation is available at TCGdex.dev

Example: Fetch a Card

in Browser

<script src="https://cdn.jsdelivr.net/npm/@tcgdex/sdk@2.4.9/dist/tcgdex.browser.js"></script>
<script>
    // Instantiate the SDK
    const tcgdex = new TCGdex('en');

    // go into an async context
    ;(async () => {
        // Card will be Furret from the Darkness Ablaze Set
        const card = await tcgdex.fetch('cards', 'swsh3-136');
    })();
</script>

in NodeJS (in an async context)

// Import the SDK in Typescript or moduleJS
import TCGdex from '@tcgdex/sdk'

// import the SDK in commonJS
const TCGdex = require('@tcgdex/sdk').default

// Instantiate the SDK
const tcgdex = new TCGdex('en');

// go into an async context
(async () => {
    // Card will be Furret from the Darkness Ablaze Set
    const card = await tcgdex.fetch('cards', 'swsh3-136');

    // You can also get the same result using
    const card = await tcgdex.fetch('sets', 'Darkness Ablaze', 136);
})();

Other Examples

// fetch a Set's informations using the set's name or ID
await tcgdex.fetch('sets', 'Darkness Ablaze')

// Fetch a serie using the serie's name or ID
await tcgdex.fetch('series', 'Sword & Shield')

// Fetch cards possible pokemon cards HP
await tcgdex.fetch('hp');

// Fetch Cards with the specific number of HP
await tcgdex.fetch('hp', 110);

// Fetch cards possible illustrators
await tcgdex.fetch('illustrators');

// Fetch Cards with the specific illustrator
await tcgdex.fetch('illustrators', 'tetsuya koizumi');

Other Endpoints

They work like the two (hp and illustrators) abose

  • categories: the the different cards categories
  • energy-types: Fetch different types of energies
  • hp: fetch the different cards possible HPs
  • illustrators: fetch all the cards illustrators
  • rarities: fetch the cards rarities
  • retreats: fetch the cards using the retreat count
  • stages: fetch differents cards stages
  • suffixes: fetch differents cards suffixes
  • trainer-types: fetch trainer cards types
  • dex-ids: fetch pokemon Global Pokédex IDS
  • types: fetch the cards using the Pokémon type(s)

Contributing

See CONTRIBUTING.md

TL::DR

  • Fork

  • Commit your changes

  • Pull Request on this Repository

License

This project is licensed under the IT License. A copy of the license is available at LICENSE.md

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

2.5.1 - 2023-07-18

Fixed

  • ModuleJS exports not working as intended

2.5.0 - 2023-06-28

Added

  • Support for both ModuleJS and CommonJS

2.4.9 - 2022-09-26

Fixed

  • package not loading on browser

2.4.8 - 2022-09-26

Fixed

  • fix version number not correctly exposting

2.4.7 - 2022-09-26

Fixed

  • Compatibility with Angular

2.4.6 - 2022-01-28

Fixed

  • Updated node-fetch for CVE-2022-0235

2.4.5 - 2021-10-11

Added

  • Added new endpoint

2.4.4 - 2021-08-12

Added

  • New logo field in serie

2.4.3 - 2021-07-19

Added

  • ESM exports are back

2.4.2 2021-07-11

Fixed

  • Downgraded to ES2015 to have better suport browsers

Changed

  • Moved browser export from Webpack to esbuild

2.4.1 - 2021-07-11

Deprecated

  • Deprecated Languages Type

2.4.0 - 2021-06-29

Added

  • Support for new languages

2.3.1 - 2021-06-22

Fixed

  • Cleaned dist folder

2.3.0-2.3.1 - 2021-06-22

Added

  • Browser specialized build
  • #9 Build/Unit/ESLint tests and coverage with Codecov using Github Action

Changed

  • #10 Simplified Request/Cache manager

2.2.0 - 2021-06-19

Added

  • Added new fields

2.1.1 - 2021-05-31

Fixed

  • Package building in the wrong version of ECMAScript

2.1.0 - 2021-05-31

Added

  • new fetch function that manage all the API endpoints

2.0.2-2.0.3 - 2021-05-28

Fixed

  • rotationMark should have been named regulationMark

2.0.1 - 2021-05-28

Changed

  • Hardcoded string values are now strings as they depends on the language

2.0.0 - 2021-05-28

Added

  • simple string endpoint typing
  • Typing is exported through the main.d.ts file
  • cardCount field in the set interface
  • a rotationMark to the card interface

Changed

  • Support new incoming datas
  • Point the SDK to the new V2
  • Renamed getExpansion(s) to getSerie(s)
  • Typing for the new SDK
  • Functions now use fetch instead of get in their names
  • URL Normalization is now done by the SDK

Removed

  • TranslationUtil as now translation are managed by the API
  • the interfaces folder as every interfaces are now in interfaces.d.ts
  • this.gbu
  • Translation files as they are now in the Compiler

1.7.0 - 2021-01-31

Added

  • new Rarities

1.6.1 - 2021-01-31

Changed

  • tags are now optionnal

1.6.0 - 2021-01-08

Changed

  • Errors are now handled to return undefined

Removed

  • console.warn when using getCards

1.5.0 - 2021-01-08

Added

  • getSet can now not transform the API Date to a Javascript Date

1.4.2 - 2021-01-08

Added

  • new Tags

Changed

  • rarities to have less strange rarities -

Fixed

  • CORS blocked

1.4.1 - 2020-04-24

Changed

  • Changed API url to the new one

1.4.0 - 2020-03-25

Added

  • a defaultLang static field to customize the default lang
  • a getLang function to get the current lang for the SDK

Fixed

  • Warnings for translations

1.3.0 - 2020-03-18

Added

  • A cache system
  • some informations about differents tags on a card
  • lvl on the card interface

Removed

  • cardTypes on the card interface

1.2.1 - 2020-03-14

Fixed

  • Fix items datas not in the correct interface

1.2.0 - 2020-03-14

Added

  • Added The getCards endpoint to fetch the big list of card with an optionnal filter on the set
  • Added The getExpansions endpoint to fetch the list of expansions
  • Added Some informations about cardTypes
  • Updated DB to add support for items

Fixed

  • Fix translation not getting the correct file

1.0.8 - 2020-03-11

Changed

  • Changed typing for some interfaces

1.0.1-1.0.7 - 2020-03-11

Changed

  • Renamed the class Name from TCGDex to TCGdex
  • lang argument is now public so it can be changed while the SDK is active

Added

  • some typing for getCard and translationUtil

1.0.0 - 2020-03-11

Added

  • the getCard function to use with the fetch a card with it's id
  • the getSet function to use with the fetch a set with it's id
  • the getExpansion function to use with the fetch an expansion with it's id
  • Constructor arg support for multiple langs
  • TranslationUtil to go from the SDK value to a text value