Pokemon TCG Pocket Database
This npm package, currently at version 2.5.1, provides a comprehensive JSON database for the Pokémon Trading Card Game Pocket. It offers various data files including `cards.json` (basic card info), `cards.extra.json` (detailed card info), `sets.json` (grouped by series), `rarities.json`, and `pullRates.json`. The package frequently updates to incorporate new sets, cards, and game data as they are released in Pokémon TCG Pocket. Key differentiators include its specific focus on the TCG Pocket game (distinct from the main Pokémon TCG) and providing multiple data formats like minified (`.min.json`) and image-stripped (`.no-image.min.json`) versions to optimize bandwidth. Additionally, card images are organized into a predictable `cards-by-set` directory structure for easier programmatic access.
Common errors
-
Cannot find module 'pokemon-tcg-pocket-database/dist/cards.json'
cause Incorrect import path or missing JSON module resolution configuration for CommonJS environments or TypeScript projects.fixEnsure you are using an ESM environment with Node.js 16+ or a bundler configured to handle direct JSON imports. For TypeScript, add `"resolveJsonModule": true` and `"esModuleInterop": true` to your `tsconfig.json`. -
Image not found when attempting to load a card asset (e.g., '.../assets/A1/card-1.webp')
cause The image asset path structure changed significantly in v2.1.0, moving to a `cards-by-set` directory with predictable `set/number.webp` naming.fixUpdate image path generation logic to `cards-by-set/${card.set}/${card.number}.webp`. Verify the base path where the `cards-by-set` directory is located relative to your assets.
Warnings
- breaking Version 2.0.0 introduced significant breaking changes, requiring a migration guide. This includes changes to data structures and file organization from v1.
- breaking The `image` field in `cards.min.json` was removed in v2.1.0. The package also introduced `cards.no-image.min.json` and standardized image paths into a new directory structure.
- breaking The `packs` field was removed from card objects in `cards.json` and its variants starting from v2.2.0, as it was often empty or redundant.
Install
-
npm install pokemon-tcg-pocket-database -
yarn add pokemon-tcg-pocket-database -
pnpm add pokemon-tcg-pocket-database
Imports
- cards
import { cards } from 'pokemon-tcg-pocket-database';import cards from 'pokemon-tcg-pocket-database/dist/cards.json';
- sets
const sets = require('pokemon-tcg-pocket-database/dist/sets.json');import sets from 'pokemon-tcg-pocket-database/dist/sets.json';
- rarities
import rarities from 'pokemon-tcg-pocket-database/rarities.json';
import rarities from 'pokemon-tcg-pocket-database/dist/rarities.json';
Quickstart
import sets from 'pokemon-tcg-pocket-database/dist/sets.json';
import cards from 'pokemon-tcg-pocket-database/dist/cards.min.json';
import rarities from 'pokemon-tcg-pocket-database/dist/rarities.json';
// Log basic database information
console.log(`Total sets available: ${Object.keys(sets).length}`);
console.log(`Total cards available: ${cards.length}`);
console.log(`Total rarities defined: ${Object.keys(rarities).length}`);
// Example: Find the first set and some of its cards
const firstSeriesKey = Object.keys(sets)[0]; // e.g., 'A'
const firstSetInSeries = sets[firstSeriesKey] ? sets[firstSeriesKey][0] : null;
if (firstSetInSeries) {
console.log(`\nFirst set in database: ${firstSetInSeries.name} (${firstSetInSeries.id})`);
const cardsInFirstSet = cards.filter(card => card.set === firstSetInSeries.id);
console.log(`Cards in ${firstSetInSeries.name}: ${cardsInFirstSet.slice(0, 3).map(c => c.name).join(', ')}...`);
// Example of calculating an image path (v2.1.0+ structure)
if (cardsInFirstSet.length > 0) {
const exampleCard = cardsInFirstSet[0];
const imagePath = `cards-by-set/${exampleCard.set}/${exampleCard.number}.webp`;
console.log(`Example image path for '${exampleCard.name}': ${imagePath}`);
}
}
// Example: Accessing a specific rarity
const commonRarity = rarities['C'];
if (commonRarity) {
console.log(`\nRarity 'C' details: Name = ${commonRarity.name}, Cost = ${commonRarity.cost}`);
}