### Install TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Instructions for installing the TCGdex SDK using npm for Node.js projects or via CDN for browser usage. ```bash # Node.js installation npm install @tcgdex/sdk ``` ```html ``` -------------------------------- ### Install TCGdex SDK in Node.js Source: https://github.com/tcgdex/javascript-sdk/blob/master/README.md This command demonstrates how to install the TCGdex SDK as a project dependency in a Node.js environment using npm. This allows you to import and use the SDK in your backend or Node.js applications. ```bash npm install @tcgdex/sdk ``` -------------------------------- ### Fetch a Card using TCGdex SDK (Browser) Source: https://github.com/tcgdex/javascript-sdk/blob/master/README.md This example illustrates how to instantiate the TCGdex SDK in a browser environment and then fetch a specific card using its ID. It assumes the SDK has already been loaded via a script tag. ```javascript ``` -------------------------------- ### Fetch a Card using TCGdex SDK (Node.js) Source: https://github.com/tcgdex/javascript-sdk/blob/master/README.md This example shows how to import and use the TCGdex SDK in a Node.js environment (TypeScript/moduleJS or CommonJS). It demonstrates fetching a card by its ID and also by set name and card number. ```typescript // 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); })(); ``` -------------------------------- ### Install TCGdex SDK in Browser Source: https://github.com/tcgdex/javascript-sdk/blob/master/README.md This snippet shows how to include the TCGdex SDK in an HTML page using a script tag, making it available for use in the browser. It points to the CDN for the browser-specific build of the SDK. ```html ``` -------------------------------- ### Fetch Set Information Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Examples for fetching set information, including all sets, a specific set by ID or name, and sets within a particular serie using the TCGdex SDK. It also shows how to access set properties and navigate to its parent serie. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Fetch all sets const allSets = await tcgdex.fetch('sets') // Fetch a specific set by ID or name const set = await tcgdex.fetch('sets', 'swsh3') // Or: await tcgdex.fetch('sets', 'Darkness Ablaze') // Using the set endpoint const setModel = await tcgdex.set.get('swsh3') if (setModel) { console.log(setModel.name) // "Darkness Ablaze" console.log(setModel.releaseDate) // "2020-08-14" console.log(setModel.cardCount) // { total: 201, official: 189, normal: 166, reverse: 155, holo: 45 } console.log(setModel.legal) // { standard: true, expanded: true } console.log(setModel.cards.length) // Number of cards in set // Navigate to parent serie const serie = await setModel.getSerie() console.log(serie?.name) // "Sword & Shield" } // Fetch sets from a specific serie const setsInSerie = await tcgdex.fetchSets('swsh') ``` -------------------------------- ### Fetch All Cards or Cards by Set Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Code examples for retrieving a list of all cards or filtering cards by a specific set using the TCGdex SDK. It demonstrates accessing card resume properties and fetching full card details. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Fetch all cards (returns CardResume objects with id, localId, name, image) const allCards = await tcgdex.fetch('cards') // Fetch cards from a specific set const setCards = await tcgdex.fetchCards('swsh3') // Using the card endpoint with list() const cardList = await tcgdex.card.list() // Access card resume properties and get full card for (const cardResume of cardList.slice(0, 5)) { console.log(cardResume.id, cardResume.name) // Get image URL with quality and extension options const imageUrl = cardResume.getImageURL('high', 'png') console.log(imageUrl) // Fetch the full card details const fullCard = await cardResume.getCard() console.log(fullCard.attacks) } ``` -------------------------------- ### TCGdex SDK Browser Usage via CDN Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Provides an example of how to use the TCGdex SDK directly in a web browser by including it via a CDN. Demonstrates fetching card data and displaying it on the page, as well as fetching a random card. ```html TCGdex Browser Example
``` -------------------------------- ### Fetch Single Card Data Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Examples of fetching detailed card information using the TCGdex SDK, either by global card ID or by specifying set and local ID. It also shows how to access various card properties. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Fetch card by global ID const card = await tcgdex.fetch('cards', 'swsh3-136') // Or use the card endpoint const cardModel = await tcgdex.card.get('swsh3-136') // Fetch card by set and local ID const cardBySet = await tcgdex.fetch('sets', 'swsh3', '136') // Using helper method const cardHelper = await tcgdex.fetchCard('136', 'swsh3') // Access card properties if (card) { console.log(card.name) // "Furret" console.log(card.hp) // 110 console.log(card.rarity) // "Uncommon" console.log(card.category) // "Pokemon" console.log(card.illustrator) // "Misa Tsutsui" console.log(card.types) // ["Colorless"] console.log(card.attacks) // Array of attack objects console.log(card.legal) // { standard: boolean, expanded: boolean } } ``` -------------------------------- ### Fetch Set, Series, and HP Data with TCGdex SDK Source: https://github.com/tcgdex/javascript-sdk/blob/master/README.md This snippet provides examples of using the TCGdex SDK to fetch information about card sets, series, and specific HP values. It demonstrates fetching a list of possible values or filtering by a specific value. ```javascript // 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'); ``` -------------------------------- ### Initialize TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Demonstrates how to initialize the TCGdex SDK in both ES Module/TypeScript and CommonJS environments. It shows setting the language, custom API endpoint, and cache TTL. ```typescript // ES Module / TypeScript import TCGdex from '@tcgdex/sdk' // CommonJS const TCGdex = require('@tcgdex/sdk').default // Initialize with language (en, fr, es, it, pt, de) const tcgdex = new TCGdex('en') // Optional: Configure custom endpoint and cache TTL tcgdex.setEndpoint('https://api.tcgdex.net/v2') tcgdex.setCacheTTL(3600) // Cache for 1 hour // Change language after initialization tcgdex.setLang('fr') console.log(tcgdex.getLang()) // 'fr' ``` -------------------------------- ### Navigate Model Relationships with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Illustrates how to navigate relationships between different data models (cards, sets, series) using helper methods provided by the SDK. Demonstrates fetching full card details from a resume, and sets/series from cards or lists. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Start from a card list, navigate to full card, then to set and serie const cardResumes = await tcgdex.card.list() const cardResume = cardResumes[0] // Get full card from resume const fullCard = await cardResume.getCard() console.log(fullCard.attacks) // Get set from card const set = await fullCard.getSet() console.log(set.name, set.releaseDate) // Get serie from set const serie = await set.getSerie() console.log(serie?.name) // Navigate from set list const setList = await tcgdex.set.list() const setResume = setList[0] const fullSet = await setResume.getSet() // Navigate from serie list const serieList = await tcgdex.serie.list() const serieResume = serieList[0] const fullSerie = await serieResume.getSerie() ``` -------------------------------- ### Advanced Query Builder with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Demonstrates how to use the Query class from the TCGdex SDK to filter, sort, and paginate card listings. Supports various comparison operators, null checks, and exclusion criteria. ```typescript import TCGdex, { Query } from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Create a query with multiple filters const query = Query.create() .equal('name', 'Pikachu') // Exact match .greaterOrEqualThan('hp', 60) // HP >= 60 .lesserThan('hp', 100) // HP < 100 .contains('localId', '5') // localId contains '5' .not.contains('localId', 'tg') // localId does not contain 'tg' .not.equal('id', 'cel25-5') // Exclude specific card .sort('hp', 'DESC') // Sort by HP descending .paginate(1, 10) // Page 1, 10 items per page const filteredCards = await tcgdex.card.list(query) console.log(`Found ${filteredCards.length} Pikachu cards`) // Query with comparison operators const highHpQuery = Query.create() .greaterThan('hp', 200) // HP > 200 .lesserOrEqualThan('retreat', 3) // Retreat cost <= 3 const powerfulCards = await tcgdex.card.list(highHpQuery) // Query with null checks const nullQuery = Query.create() .isNull('suffix') // Cards without suffix .not.isNull('abilities') // Cards with abilities // Pagination example const paginatedQuery = Query.create() .contains('types', 'Fire') .sort('name', 'ASC') .paginate(2, 20) // Page 2, 20 items per page const page2FireCards = await tcgdex.card.list(paginatedQuery) ``` -------------------------------- ### Error Handling with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Explains how to handle potential errors when using the TCGdex SDK. Covers scenarios like non-existent data (404s), server errors (5xx), invalid endpoints, and empty fetch requests. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Methods return undefined/null for 404 errors const card = await tcgdex.card.get('non-existent-id') if (card === null) { console.log('Card not found') } // Server errors (5xx) throw exceptions try { const data = await tcgdex.fetch('cards', 'some-id') } catch (error) { console.error('Server error:', error.message) } // Invalid endpoints throw errors try { await tcgdex.fetch('invalid-endpoint' as any) } catch (error) { console.error('Unknown endpoint:', error.message) // "unknown endpoint to fetch! (invalid-endpoint)" } // Empty endpoint throws error try { await (tcgdex as any).fetch() } catch (error) { console.error(error.message) // "endpoint to fetch is empty!" } ``` -------------------------------- ### Generate Card Image URLs with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Shows how to generate URLs for card images using the `getImageURL` method. Allows specifying image quality ('low' or 'high') and format ('jpg', 'png', 'webp'). ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') const cardResume = (await tcgdex.card.list())[0] // Get image URL with options // Quality: 'low' or 'high' // Extension: 'jpg', 'png', or 'webp' const highPng = cardResume.getImageURL('high', 'png') const lowJpg = cardResume.getImageURL('low', 'jpg') const highWebp = cardResume.getImageURL('high', 'webp') console.log(highPng) // Output: https://assets.tcgdex.net/en/swsh/swsh1/1/high.png // Default is high quality PNG const defaultImage = cardResume.getImageURL() ``` -------------------------------- ### Using Simple Endpoints Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Access filter endpoints using the structured endpoint objects for a more object-oriented approach to fetching data. ```APIDOC ## Using Simple Endpoints Access filter endpoints using the structured endpoint objects. ### Method GET ### Endpoint `/types`, `/rarity`, `/retreat`, `/illustrator`, `/hp`, `/categorie`, `/dexID`, `/energyType`, `/regulationMark`, `/stage`, `/suffixe`, `/trainerType`, `/variant` ### Parameters No direct parameters for list, but `get` methods take a value. ### Request Example ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // List all values for an endpoint const allRarities = await tcgdex.rarity.list() console.log(allRarities) // Get cards matching a specific value const rareCardData = await tcgdex.rarity.get('Rare') console.log(rareCardData?.name) console.log(rareCardData?.cards) // Available simple endpoints const types = await tcgdex.type.list() const retreats = await tcgdex.retreat.list() const illustrators = await tcgdex.illustrator.list() const hpValues = await tcgdex.hp.list() const categories = await tcgdex.categorie.list() const dexIds = await tcgdex.dexID.list() const energyTypes = await tcgdex.energyType.list() const regulationMarks = await tcgdex.regulationMark.list() const stages = await tcgdex.stage.list() const suffixes = await tcgdex.suffixe.list() const trainerTypes = await tcgdex.trainerType.list() const variants = await tcgdex.variant.list() ``` ### Response #### Success Response (200) - **list()**: Returns an array of strings representing all available values for the endpoint. - **get(value)**: Returns an object with details for the specified value, including its name and an array of matching `CardResume` objects. ``` -------------------------------- ### Fetching Series Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Retrieve series information containing multiple sets. You can fetch all series or a specific series by its ID or name. ```APIDOC ## Fetching Series Retrieve series information containing multiple sets. ### Method GET ### Endpoint `/series` or `/series/{id}` ### Parameters #### Path Parameters - **id** (string) - Optional - The ID or name of the series to fetch (e.g., 'swsh' or 'Sword & Shield'). ### Request Example ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Fetch all series const allSeries = await tcgdex.fetch('series') // Fetch a specific serie by ID or name const serie = await tcgdex.fetch('series', 'swsh') // Or: await tcgdex.fetch('series', 'Sword & Shield') // Using the serie endpoint const serieModel = await tcgdex.serie.get('swsh') if (serieModel) { console.log(serieModel.id) console.log(serieModel.name) console.log(serieModel.logo) console.log(serieModel.sets) } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the series. - **name** (string) - The name of the series. - **logo** (string) - The URL of the series logo. - **sets** (Array) - An array of SetResume objects, each containing summary information about a set within the series. #### Response Example ```json { "id": "swsh", "name": "Sword & Shield", "logo": "https://.../swsh_logo.png", "sets": [ { "id": "swsh1", "name": "Sword & Shield Base Set", "cardCount": { "total": 202, "official": 202 }, "releaseDate": "2020-02-07", "getSet": () => Promise } ] } ``` ``` -------------------------------- ### Fetch Series Data with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Retrieve series information, including fetching all series or a specific serie by its ID or name. It also demonstrates accessing serie details and iterating through associated sets. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Fetch all series const allSeries = await tcgdex.fetch('series') // Fetch a specific serie by ID or name const serie = await tcgdex.fetch('series', 'swsh') // Or: await tcgdex.fetch('series', 'Sword & Shield') // Using the serie endpoint const serieModel = await tcgdex.serie.get('swsh') if (serieModel) { console.log(serieModel.id) // "swsh" console.log(serieModel.name) // "Sword & Shield" console.log(serieModel.logo) // Logo URL console.log(serieModel.sets) // Array of SetResume objects // Access sets in the serie for (const setResume of serieModel.sets) { console.log(setResume.name, setResume.cardCount.total) // Get full set details const fullSet = await setResume.getSet() console.log(fullSet?.releaseDate) } } ``` -------------------------------- ### Fetch Random Card, Set, and Serie with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Retrieve random cards, sets, or series using the SDK's dedicated methods or the general fetch method. This is useful for implementing discovery features or showcasing random items. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Get a random card const randomCard = await tcgdex.random.card() console.log(randomCard.name, randomCard.set.name) // Get a random set const randomSet = await tcgdex.random.set() console.log(randomSet.name, randomSet.cardCount.total) // Get a random serie const randomSerie = await tcgdex.random.serie() console.log(randomSerie.name, randomSerie.sets.length) // Using fetch directly const randomCardData = await tcgdex.fetch('random', 'card') const randomSetData = await tcgdex.fetch('random', 'set') const randomSerieData = await tcgdex.fetch('random', 'serie') ``` -------------------------------- ### Use Simple Endpoints with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Access filter endpoints using the structured endpoint objects provided by the SDK. This allows listing all values for an endpoint or retrieving cards matching a specific value. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // List all values for an endpoint const allRarities = await tcgdex.rarity.list() console.log(allRarities) // ["Common", "Uncommon", "Rare", ...] // Get cards matching a specific value const rareCardData = await tcgdex.rarity.get('Rare') console.log(rareCardData?.name) // "Rare" console.log(rareCardData?.cards) // Array of CardResume // Available simple endpoints const types = await tcgdex.type.list() const retreats = await tcgdex.retreat.list() const illustrators = await tcgdex.illustrator.list() const hpValues = await tcgdex.hp.list() const categories = await tcgdex.categorie.list() const dexIds = await tcgdex.dexID.list() const energyTypes = await tcgdex.energyType.list() const regulationMarks = await tcgdex.regulationMark.list() const stages = await tcgdex.stage.list() const suffixes = await tcgdex.suffixe.list() const trainerTypes = await tcgdex.trainerType.list() const variants = await tcgdex.variant.list() ``` -------------------------------- ### Filtering by Card Attributes Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Fetch cards filtered by various attributes such as HP, type, rarity, illustrator, and more. This allows for precise searching of the card database. ```APIDOC ## Filtering by Card Attributes Fetch cards filtered by HP, type, rarity, illustrator, and other attributes. ### Method GET ### Endpoint `/hp/{value}`, `/types/{value}`, `/rarities/{value}`, `/illustrators/{value}`, `/retreats/{value}`, `/stages/{value}`, `/categories/{value}`, `/energy-types/{value}`, `/regulation-marks/{value}`, `/dex-ids/{value}`, `/suffixes/{value}`, `/trainer-types/{value}` ### Parameters #### Path Parameters - **value** (string) - The specific value to filter by (e.g., '110' for HP, 'Fire' for type, 'Rare' for rarity). ### Request Example ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Get all possible HP values const allHpValues = await tcgdex.fetch('hp') console.log(allHpValues) // Get cards with specific HP const cardsWithHp110 = await tcgdex.fetch('hp', '110') console.log(cardsWithHp110?.cards) // Get all types and cards of a specific type const allTypes = await tcgdex.fetch('types') const fireCards = await tcgdex.fetch('types', 'Fire') // Get all rarities and cards with specific rarity const allRarities = await tcgdex.fetch('rarities') const rareCards = await tcgdex.fetch('rarities', 'Rare') // Get all illustrators and their cards const allIllustrators = await tcgdex.fetch('illustrators') const illustratorCards = await tcgdex.fetch('illustrators', 'Ken Sugimori') // Other filter endpoints const retreats = await tcgdex.fetch('retreats', '2') const stages = await tcgdex.fetch('stages', 'Stage2') const categories = await tcgdex.fetch('categories', 'Pokemon') const energyTypes = await tcgdex.fetch('energy-types', 'Special') const regulationMarks = await tcgdex.fetch('regulation-marks', 'F') const dexIds = await tcgdex.fetch('dex-ids', '25') const suffixes = await tcgdex.fetch('suffixes', 'V') const trainerTypes = await tcgdex.fetch('trainer-types', 'Item') ``` ### Response #### Success Response (200) - **cards** (Array) - An array of CardResume objects matching the filter criteria. - (For list endpoints like 'hp', 'types', etc.) An array of strings representing the available values for that attribute. ``` -------------------------------- ### Random Card, Set, and Serie Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Fetch random cards, sets, or series. This is useful for discovery features or when you need a random item from the TCGdex database. ```APIDOC ## Random Card, Set, and Serie Fetch random cards, sets, or series for discovery features. ### Method GET ### Endpoint `/random/card`, `/random/set`, `/random/serie` ### Parameters None ### Request Example ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Get a random card const randomCard = await tcgdex.random.card() console.log(randomCard.name, randomCard.set.name) // Get a random set const randomSet = await tcgdex.random.set() console.log(randomSet.name, randomSet.cardCount.total) // Get a random serie const randomSerie = await tcgdex.random.serie() console.log(randomSerie.name, randomSerie.sets.length) // Using fetch directly const randomCardData = await tcgdex.fetch('random', 'card') const randomSetData = await tcgdex.fetch('random', 'set') const randomSerieData = await tcgdex.fetch('random', 'serie') ``` ### Response #### Success Response (200) - **randomCard**: Returns a `CardResume` object representing a random card. - **randomSet**: Returns a `SetResume` object representing a random set. - **randomSerie**: Returns a `SerieResume` object representing a random series. ``` -------------------------------- ### Filter Cards by Attributes with TCGdex SDK Source: https://context7.com/tcgdex/javascript-sdk/llms.txt Fetch cards filtered by various attributes such as HP, type, rarity, illustrator, retreat cost, stage, category, energy type, regulation marks, Pokedex ID, suffixes, trainer types, and variants. It also shows how to retrieve lists of all possible values for these attributes. ```typescript import TCGdex from '@tcgdex/sdk' const tcgdex = new TCGdex('en') // Get all possible HP values const allHpValues = await tcgdex.fetch('hp') console.log(allHpValues) // ["10", "20", "30", ...] // Get cards with specific HP const cardsWithHp110 = await tcgdex.fetch('hp', '110') console.log(cardsWithHp110?.cards) // Array of CardResume // Get all types and cards of a specific type const allTypes = await tcgdex.fetch('types') const fireCards = await tcgdex.fetch('types', 'Fire') // Get all rarities and cards with specific rarity const allRarities = await tcgdex.fetch('rarities') const rareCards = await tcgdex.fetch('rarities', 'Rare') // Get all illustrators and their cards const allIllustrators = await tcgdex.fetch('illustrators') const illustratorCards = await tcgdex.fetch('illustrators', 'Ken Sugimori') // Other filter endpoints const retreats = await tcgdex.fetch('retreats', '2') // Cards with retreat cost 2 const stages = await tcgdex.fetch('stages', 'Stage2') // Stage 2 Pokemon const categories = await tcgdex.fetch('categories', 'Pokemon') const energyTypes = await tcgdex.fetch('energy-types', 'Special') const regulationMarks = await tcgdex.fetch('regulation-marks', 'F') const dexIds = await tcgdex.fetch('dex-ids', '25') // Pikachu by Pokedex number const suffixes = await tcgdex.fetch('suffixes', 'V') // Pokemon V cards const trainerTypes = await tcgdex.fetch('trainer-types', 'Item') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.