TS-PokéAPI Documentation

website·Indexed 30 days ago

https://jaflesch.github.io/playground-ci

A TypeScript wrapper for the PokéAPI that provides customizable ways to fetch data. The library includes the PokeApi class and pokeapi() function, along with utilities for Pokémon battle parameter calculations (stats, moves, and type charts), nature traits, and integration with Pokémon Showdown.

Tokens
25.2K
Snippets
199
Records
239
Agent score
72%

What's inside TS-PokéAPI

  1. Overview of TS-PokéAPI features

    TS-PokéAPI is a zero-dependency library designed for fetching data from PokéAPI resources. It provides strong type definitions, helper methods for data retrieval, and utilities for calculating game formulas based on sources like Bulbapedia, Serebii, and PokémonDB. Additionally, it supports importing, exporting, and validating Pokémon Showdown teamsheets.
  2. Overview of Pokémon Nature mechanics

    Nature is a trait assigned to individual Pokémon that influences stat growth and flavor preferences. Typically, a Nature increases one non-HP stat (Attack, Defense, Special Attack, Special Defense, or Speed) by 10% and decreases another non-HP stat by 10%.
  3. Move resource interface properties

    The Move resource in the PokeAPI provides detailed information about a specific move, including its unique identifier, name, localized names, localized descriptions, and a list of moves directed at the target.
    interface Move {
      id: number; // The identifier for this resource
      name: string; // The name for this resource
      names: Array<Name>; // The name of this resource listed in different languages
      descriptions: Array<Description>; // The description of this resource listed in different languages
      moves: Array<NamedAPIResource>; // A list of moves that are directed at this target
    }
  4. Use the PokemonType interface

    The PokemonType interface defines the properties of a Pokémon type, including its damage relations, generation of introduction, and associated Pokémon and moves.
    interface PokemonType {
      id: number;
      name: string;
      damage_relations: number;
      past_damage_relations: number;
      game_indices: Array<GenerationGameIndex>;
      generation: NamedAPIResource;
      move_damage_class: Array<NamedAPIResource>;
      names: Array<Name>;
      pokemon: Array<NamedAPIResource>;
      moves: Array<NamedAPIResource>;
    }
  5. Reference the Pokemon species data structure

    The Pokémon species resource contains comprehensive data about a specific Pokémon species, including its biological traits, evolution details, and Pokédex metadata. All properties listed below are required.
    interface PokemonSpecies {
      id: number; // The identifier for this resource
      name: string; // The name for this resource
      order: number; // National Dex order (families grouped by stage)
      gender_rate: number; // Chance of being female in eighths; -1 for genderless
      capture_rate: number; // Happiness when caught by normal Pokéball (up to 255)
      base_happiness: number; // Detail of natures affecting stats
      is_baby: boolean; // Whether this is a baby Pokémon
      is_legendary: boolean; // Whether this is a legendary Pokémon
      is_mythical: boolean; // Whether this is a mythical Pokémon
      hatch_counter: number; // Steps to hatch: 255 * (hatch_counter + 1)
      has_gender_differences: boolean; // Whether there are visual gender differences
      forms_switchable: boolean; // Whether it can switch between multiple forms
      growth_rate: NamedAPIResource; // Rate at which species gains levels
      pokedex_numbers: PokemonSpecieDexEntry[]; // List of Pokedexes and reserved indexes
      egg_groups: NamedAPIResource[]; // List of egg groups
      color: NamedAPIResource; // Color for Pokédex search
      shape: NamedAPIResource; // Shape for Pokédex search
      evolves_from_species: NamedAPIResource; // Species that evolves into this one
      evolution_chain: APIResource; // The evolution chain membership
      habitat: NamedAPIResource; // Encounter habitat
      generation: NamedAPIResource; // Generation introduced
      names: Name[]; // Names in different languages
      pal_park_encounters: PalParkEncounterArea; // Pal park encounter list
      flavor_text_entries: FlavorText[]; // Flavor text entries
      forms_descriptions: Description[]; // Descriptions of different forms
      genera: Genus; // Genus in multiple languages
      varieties: PokemonSpecieVariety; // List of Pokémon within this species
    }
  6. Use the pokeapi() function to fetch PokéAPI data

    The pokeapi() function is syntactic sugar for the PokeApi class. It returns an instance of the class, allowing developers to chain methods to fetch data from PokéAPI endpoints in a procedural fashion. It supports a wide range of resource keys such as 'pokemon', 'ability', 'item', 'move', and 'type'.
  7. Understand the EvolutionChain structure

    The EvolutionChain represents the sequence of evolutions for a Pokémon species. It contains the base link of the chain and information about baby-trigger items used during mating to hatch a baby Pokémon instead of a basic one.
    interface EvolutionChain {
      id: number;
      chain: ChainLink;
      baby_trigger_item: NamedAPIResource;
    }
  8. Understand the PokemonSpecie interface

    A PokemonSpecie represents the base form for one or more Pokémon varieties. Attributes defined at the species level are shared across all varieties of that species (e.g., the species 'Wormadam' is shared by Wormadam-Trash, Wormadam-Sandy, and Wormadam-Plant).
  9. Manage Pokémon encounter data with the Encounter interface

    The Encounter interface provides details about the conditions and probability of encountering a Pokémon in the game.
    interface Encounter {
      min_level: number; // Lowest level the Pokémon could be encountered at
      max_level: number; // Highest level the Pokémon could be encountered at
      condition_values: Array<NamedAPIResource>; // Condition values required for encounter
      chance: number; // Percent chance that this encounter will occur
      method: NamedAPIResource; // The method by which this encounter happens
    }
  10. Access Pokémon utility functions

    The library provides utility functions for the Pokémon universe, including main series game formulas (stat calculation, stat validation, catching chance, damage output), Pokémon Showdown parsers and validators for competitive team building, and other miscellaneous tools.
  11. Use the Berry interface

    The Berry resource provides detailed data about berries in the Pokémon universe, including growth time, harvest limits, and physical properties used for Pokéblocks or Poffins.
    interface Berry {
      id: number; // The identifier for this resource
      name: string; // The name for this resource
      growth_time: number; // Time to grow one stage (in hours); 4 stages total
      max_harvest: number; // Max berries per tree in Generation IV
      natural_gift_power: number; // Power of "Natural Gift" move with this Berry
      size: number; // Size in millimeters
      smoothness: number; // Smoothness used for Pokéblocks/Poffins
      soil_dryness: number; // Speed at which the berry dries out the soil
      firmness: NamedAPIResource; // Firmness used for Pokéblocks/Poffins
      flavors: Array<BerryFlavorMap>; // List of flavors and their potencies
      item: NamedAPIResource; // Reference to the item specific data
      natural_gift_type: NamedAPIResource; // Type inherited by "Natural Gift"
    }
    
    interface BerryFlavorMap {
      potency: number; // The potency of the flavor
      flavor: NamedAPIResource; // The flavor of the berry
    }