PokemonDetail object that’s optimized for use throughout the application.
adaptPokemon
Main adapter function that transforms a raw API response into a structured Pokemon detail object.Parameters
The raw Pokemon response from PokeAPI, containing:
id(number): Pokemon IDname(string): Pokemon nameheight(number): Height in decimetersweight(number): Weight in hectogramstypes(ApiPokemonType[]): Raw type datasprites(ApiPokemonSprites): Sprite URLs objectflavor_text_entries(array): Description entriesgenera(array): Genus entries in multiple languagesabilities(ApiPokemonAbility[]): Raw ability datastats(ApiPokemonStat[]): Raw stat dataevolution_chain(object): Evolution chain referencevarieties(ApiVariety[]): Pokemon form varieties
Returns
Adapted Pokemon detail object with the following structure:
Usage Example
Helper Functions
The adapter uses several internal helper functions to transform specific data:distillGenus
Extracts the genus from multi-language entries."en"Returns: Genus string with “Pokémon” suffix removed (e.g., “Mouse” from “Mouse Pokémon”)
distillDescription
Extracts and cleans the flavor text description."en"Returns: Cleaned description with whitespace normalized and special characters removed
mapTypes
Converts API type format to application format.PokeType objects with name and url properties
mapAbilities
Converts API ability format to simplified format.name (string) and hidden (boolean)
mapStats
Converts API stats to application stat format with friendly names.mapVarieties
Converts Pokemon varieties (forms) to application format.Data Transformations
The adapter performs several key transformations:Unit Conversions
Unit Conversions
- Height: Decimeters → Meters (divided by 10)
- Weight: Hectograms → Kilograms (divided by 10)
Text Cleaning
Text Cleaning
- Description: Removes newlines, form feeds, tabs, and extra whitespace
- Genus: Removes “Pokémon” suffix
- Variety names: Replaces hyphens with spaces
Stat Name Mapping
Stat Name Mapping
Maps API stat names to friendly abbreviations:
hp→ “HP”attack→ “ATK”defense→ “DEF”special-attack→ “SPA”special-defense→ “SPD”speed→ “SPE”
Fallback Handling
Fallback Handling
- Missing sprites default to Ditto sprite (ID 132)
- Missing genus defaults to “Unknown”
- Missing description defaults to “Not enough data has been collected yet to describe this Pokémon.”