All Projects → PokeAPI → Pokeapi Js Wrapper

PokeAPI / Pokeapi Js Wrapper

Licence: other
PokeAPI browser wrapper, fully async with built-in cache

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pokeapi Js Wrapper

Azure Sdk For Js
This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/en-us/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
Stars: ✭ 872 (+575.97%)
Mutual labels:  hacktoberfest, browser
Typerep Map
⚡️Efficient implementation of Map with types as keys
Stars: ✭ 85 (-34.11%)
Mutual labels:  hacktoberfest, cache
Qrcode Renderer
QR Code renderer is a dependency-free library to render QR Codes. The library makes it simple to integrate with any UI framework and comes with a prebuilt SVG renderer for the web.
Stars: ✭ 56 (-56.59%)
Mutual labels:  hacktoberfest, browser
Reservoir
Android library to easily serialize and cache your objects to disk using key/value pairs.
Stars: ✭ 674 (+422.48%)
Mutual labels:  asynchronous, cache
Wikipediap2p
WikipediaP2P.org Chrome Extension
Stars: ✭ 105 (-18.6%)
Mutual labels:  cache, browser
Offix
GraphQL Offline Client and Server
Stars: ✭ 694 (+437.98%)
Mutual labels:  hacktoberfest, cache
Pswritecolor
Write-Color is a wrapper around Write-Host allowing you to create nice looking scripts, with colorized output.
Stars: ✭ 78 (-39.53%)
Mutual labels:  wrapper, hacktoberfest
Bpmn Js
A BPMN 2.0 rendering toolkit and web modeler.
Stars: ✭ 5,592 (+4234.88%)
Mutual labels:  hacktoberfest, browser
Pokebase
Python 3 wrapper for Pokéapi v2
Stars: ✭ 99 (-23.26%)
Mutual labels:  wrapper, hacktoberfest
React Promise
a react.js hook for general promise in typescript
Stars: ✭ 90 (-30.23%)
Mutual labels:  hacktoberfest, asynchronous
Webtorrent
⚡️ Streaming torrent client for the web
Stars: ✭ 25,554 (+19709.3%)
Mutual labels:  hacktoberfest, browser
Lru Cache Node
A lighting fast cache manager for node with least-recently-used policy.
Stars: ✭ 120 (-6.98%)
Mutual labels:  hacktoberfest, cache
React Esi
React ESI: Blazing-fast Server-Side Rendering for React and Next.js
Stars: ✭ 537 (+316.28%)
Mutual labels:  hacktoberfest, cache
Hazelcast Hibernate
A distributed second-level cache for Hibernate
Stars: ✭ 24 (-81.4%)
Mutual labels:  hacktoberfest, cache
Bigcache
Efficient cache for gigabytes of data written in Go.
Stars: ✭ 5,304 (+4011.63%)
Mutual labels:  hacktoberfest, cache
Ws Wrapper
Lightweight WebSocket lib with socket.io-like event handling, requests, and channels
Stars: ✭ 58 (-55.04%)
Mutual labels:  wrapper, browser
Memento
Memento is a development-only tool that caches HTTP calls once they have been executed.
Stars: ✭ 380 (+194.57%)
Mutual labels:  hacktoberfest, cache
Imgui Go
Go wrapper library for "Dear ImGui" (https://github.com/ocornut/imgui)
Stars: ✭ 499 (+286.82%)
Mutual labels:  wrapper, hacktoberfest
Aiovk
vk.com API python wrapper for asyncio
Stars: ✭ 85 (-34.11%)
Mutual labels:  wrapper, hacktoberfest
Netclient Ios
Versatile HTTP Networking in Swift
Stars: ✭ 117 (-9.3%)
Mutual labels:  asynchronous, cache

pokeapi-js-wrapper

npm Build Status Mocha browser tests codecov

Maintainer: Naramsim

A PokeAPI wrapper intended for browsers only. Comes fully asynchronous (with localForage) and built-in cache. Offers also Image Caching through the inclusion of a Service Worker. For a Node (server-side) wrapper see: pokedex-promise-v2

Install

Chrome Firefox Safari Opera Edge IE
8+
npm install pokeapi-js-wrapper --save
<script src="https://unpkg.com/pokeapi-js-wrapper/dist/index.js"></script>

Usage

const Pokedex = require("pokeapi-js-wrapper")
const P = new Pokedex.Pokedex()
<script>
  const P = new Pokedex.Pokedex()
</script>

Example requests

// with await, be sure to be in an async function (and in a try/catch)
(async () => {
  const golduck = await P.getPokemonByName("golduck")
  console.log(golduck)
})()

// or with Promises
P.getPokemonByName("eevee")
  .then(function(response) {
    console.log(response)
  })

P.resource([
  "/api/v2/pokemon/36",
  "api/v2/berry/8",
  "https://pokeapi.co/api/v2/ability/9/",
]).then( response => {
  console.log(response)
})

Configuration

Pass an Object to Pokedex() in order to configure it. Available options: protocol, hostName, versionPath, cache, timeout(ms), and cacheImages. Any option is optional 😄. All the default values can be found here

const Pokedex = require("pokeapi-js-wrapper")
const customOptions = {
  protocol: "https",
  hostName: "localhost:443",
  versionPath: "/api/v2/",
  cache: true,
  timeout: 5 * 1000, // 5s
  cacheImages: true
}
const P = new Pokedex.Pokedex(customOptions)

Caching images

Pokeapi.co serves its Pokemon images through Github. For example, the front default DreamWorld image of Pikachu is found at this URL: https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/dream-world/25.svg.

pokeapi-js-wrapper enables browsers to cache all these images by:

  1. enabling the config parameter cacheImages
  2. serving our service worker from the root of your project

In this way when pokeapi-js-wrapper's Pokedex is created it will install and start the Service Worker you are serving at the root of your server. The Service Worker will intercept all the calls your HTML/CSS/JS are making to get PokeAPI's images and will cache them.

It's fundamental that you download the Service Worker we provide(Right Click + Save As) and you serve it from the root of your project/server. Service Workers in fact cannot be installed from a domain different than yours.

A basic example is hosted here.

Tests

pokeapi-js-wrapper can be tested using two strategies. One is with Node, since this package works with Node (although not recommended), and the other with a browser.

npm test

Or open /test/test.html in your browser. A live version can be found at gh-pages

Endpoints

All the endpoints and the functions to access PokeAPI's endpoints are listed in the long table below. Each function .ByName(name) accepts names and ids. The only 5 functions .ById(id) only accept ids. You can also pass an array to each function, it will retrieve the data for each element asynchronously.

P.getPokemonByName("eevee").then(function(response) {
  console.log(response)
})

P.getPokemonSpeciesByName(25).then(function(response) {
  console.log(response)
})

P.getBerryByName(["cheri", "chesto", 5]).then(function(response) {
  // `response` will be an Array containing 3 Objects
  // response.forEach((item) => {console.log(item.size)}) // 80,50,20
  console.log(response)
})

P.getMachineById(3).then(function(response) {
  console.log(response)
})
Function Mapped PokeAPI endpoint Documentation
getBerryByName(name) /berry/:name Documentation
getBerryFirmnessByName(name) /berry-firmness/:name Documentation
getBerryFlavorByName(name) /berry-flavor/:name Documentation
getContestTypeByName(name) /contest-type/:name Documentation
getContestEffectById(id) /contest-effect/:id Documentation
getSuperContestEffectById(id) /super-contest-effect/:id Documentation
getEncounterMethodByName(name) /encounter-method/:name Documentation
getEncounterConditionByName(name) /encounter-condition/:name Documentation
getEncounterConditionValueByName(name) /encounter-condition-value/:nam/ Documentation
getEvolutionChainById(id) /evolution-chain/:id Documentation
getEvolutionTriggerByName(name) /evolution-trigger/:name Documentation
getGenerationByName(name) /generation/:name Documentation
getPokedexByName(name) /pokedex/:name Documentation
getVersionByName(name) /version/:name Documentation
getVersionGroupByName(name) /version-group/:name Documentation
getItemByName(name) /item/:name Documentation
getItemAttributeByName(name) /item-attribute/:name Documentation
getItemCategoryByName(name) /item-category/:name Documentation
getItemFlingEffectByName(name) /item-fling-effect/:name Documentation
getItemPocketByName(name) /item-pocket/:name Documentation
getMachineById(id) /machine/:id Documentation
getMoveByName(name) /move/:name Documentation
getMoveAilmentByName(name) /move-ailment/:name Documentation
getMoveBattleStyleByName(name) /move-battle-style/:name Documentation
getMoveCategoryByName(name) /move-category/:name Documentation
getMoveDamageClassByName(name) /move-damage-class/:name Documentation
getMoveLearnMethodByName(name) /move-learn-method/:name Documentation
getMoveTargetByName(name) /move-target/:name Documentation
getLocationByName(name) /location/:name Documentation
getLocationAreaByName(name) /location-area/:name Documentation
getPalParkAreaByName(name) /pal-park-area/:name Documentation
getRegionByName(name) /region/:name Documentation
getAbilityByName(name) /ability/:name Documentation
getCharacteristicById(id) /characteristic/:id Documentation
getEggGroupByName(name) /egg-group/:name Documentation
getGenderByName(name) /gender/:name Documentation
getGrowthRateByName(name) /growth-rate/:name Documentation
getNatureByName(name) /nature/:name Documentation
getPokeathlonStatByName(name) /pokeathlon-stat/:name Documentation
getPokemonByName(name) /pokemon/:name Documentation
getPokemonEncounterAreasByName(name) /pokemon/:name/encounters Documentation
getPokemonColorByName(name) /pokemon-color/:name Documentation
getPokemonFormByName(name) /pokemon-form/:name Documentation
getPokemonHabitatByName(name) /pokemon-habitat/:name Documentation
getPokemonShapeByName(name) /pokemon-shape/:name Documentation
getPokemonSpeciesByName(name) /pokemon-species/:name Documentation
getStatByName(name) /stat/:name Documentation
getTypeByName(name) /type/:name Documentation
getLanguageByName(name) /language/:name Documentation

Root Endpoints list

For each PokeAPI's root endpoint we provide a method to get all the items served by that endpoint. By default the method will return every item in the endpoint. If needed an offset and a limit can be configured.

  • offset is where to start. The first item that you will get. Default 0
  • limit is how many items you want to list. Default 100000

TIP: Do not pass any config Object to your call, since you will get every item and everything will be cached

The following snippet will get the list of Pokémon between ID 34 and ID 44

const interval = {
  offset: 34,
  limit: 10,
}
P.getPokemonsList(interval).then(function(response) {
  console.log(response)
})
Function Mapped PokeAPI endpoint
getEndpointsList() /
getBerriesList() /berry
getBerriesFirmnesssList() /berry-firmness
getBerriesFlavorsList() /berry-flavor
getContestTypesList() /contest-type
getContestEffectsList() /contest-effect
getSuperContestEffectsList() /super-contest-effect
getEncounterMethodsList() /encounter-method
getEncounterConditionsList() /encounter-condition
getEncounterConditionValuesList() /encounter-condition-value
getEvolutionChainsList() /evolution-chain
getEvolutionTriggersList() /evolution-trigger
getGenerationsList() /generation
getPokedexsList() /pokedex
getVersionsList() /version
getVersionGroupsList() /version-group
getItemsList() /item
getItemAttributesList() /item-attribute
getItemCategoriesList() /item-category
getItemFlingEffectsList() /item-fling-effect
getItemPocketsList() /item-pocket
getMachinesList() /machine
getMovesList() /move
getMoveAilmentsList() /move-ailment
getMoveBattleStylesList() /move-battle-style
getMoveCategoriesList() /move-category
getMoveDamageClassesList() /move-damage-class
getMoveLearnMethodsList() /move-learn-method
getMoveTargetsList() /move-target
getLocationsList() /location
getLocationAreasList() /location-area
getPalParkAreasList() /pal-park-area
getRegionsList() /region
getAbilitiesList() /ability
getCharacteristicsList() /characteristic
getEggGroupsList() /egg-group
getGendersList() /gender
getGrowthRatesList() /growth-rate
getNaturesList() /nature
getPokeathlonStatsList() /pokeathlon-stat
getPokemonsList() /pokemon
getPokemonColorsList() /pokemon-color
getPokemonFormsList() /pokemon-form
getPokemonHabitatsList() /pokemon-habitat
getPokemonShapesList() /pokemon-shape
getPokemonSpeciesList() /pokemon-species
getStatsList() /stat
getTypesList() /type
getLanguagesList() /language

Custom URLs and paths

Use .resource() to query any URL or path. Also this function accepts both single values and Arrays.

P.resource([
  "/api/v2/pokemon/36",
  "api/v2/berry/8",
  "https://pokeapi.co/api/v2/ability/9/",
]).then(function(response) {
  console.log(response)
})

P.resource("api/v2/berry/5").then(function(response) {
  console.log(response)
})

Internet Explorer 8

In order to target this browser you must load a Promise polyfill before pokeapi-js-wrapper. You can choose one of your choice, we recommend jakearchibald/es6-promise or stefanpenner/es6-promise

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].