Skip to content

Commit

Permalink
Merge pull request #54 from PokeAPI/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
Naramsim authored Nov 26, 2021
2 parents 78bff49 + c07cc62 commit 4f533c8
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 399 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- name: Build
run: |
npm run generate:types
npm run generate:jsdocs
npm run generate:main
npm run generate:jsdocs
- name: Unit test
run: |
npm t
Expand Down
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

67 changes: 47 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pokedex-promise-v2 <a href="https://pokeapi.co/api/v2/pokemon/bulbasaur"><img src='https://veekun.com/dex/media/pokemon/global-link/1.png' height=50px/></a>

[![npm version](https://badge.fury.io/js/pokedex-promise-v2.svg)](https://badge.fury.io/js/pokedex-promise-v2)
[![Build Status](https://travis-ci.org/PokeAPI/pokedex-promise-v2.svg?branch=master)](https://travis-ci.org/PokeAPI/pokedex-promise-v2)
[![Tests](https://github.com/PokeAPI/pokedex-promise-v2/actions/workflows/test.yml/badge.svg)](https://github.com/PokeAPI/pokedex-promise-v2/actions/workflows/test.yml)
[![Package Quality](http://npm.packagequality.com/shield/pokedex-promise-v2.svg)](http://packagequality.com/#?package=pokedex-promise-v2)
[![npm](https://img.shields.io/npm/l/express.svg?maxAge=2592000)](https://github.com/PokeAPI/pokedex-promise-v2/blob/master/LICENSE)

Expand Down Expand Up @@ -38,6 +38,8 @@ An easy way to use [Pokéapi](https://pokeapi.co/) v2 with promises *(or callbac

## Install [![nodeVersion](https://img.shields.io/badge/node->=12-brightgreen.svg)](https://www.npmjs.com/package/pokedex-promise-v2)

> As of 4.0.0 this package is now pure ESM. Please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
```sh
npm install pokedex-promise-v2 --save
```
Expand All @@ -61,29 +63,39 @@ const P = new Pokedex();

**UPDATE**: You can pass an array to each endpoint, it will retrive data for each array element. If you scroll down, you will find an example.

### [Example](./test/test_async.js) requests
### Example requests

```js
P.getPokemonByName('eevee') // with Promise
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log('There was an ERROR: ', error);
});
(async () => { // with Async/Await
try {
const golduckSpecies = await P.getPokemonSpeciesByName("golduck")
const frenchName = golduckSpecies.names.filter(pokeAPIName => pokeAPIName.language.name === 'fr')[0].name
console.log(frenchName)
} catch (error) {
throw error
}
})()

P.getPokemonByName(34, (response, error) => { // with callback
if(!error) {
console.log(response);
} else {
console.log(error)
}
});
P.getPokemonByName(['eevee', 'ditto']) // with Promise
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log('There was an ERROR: ', error);
});

P.getResource(['/api/v2/pokemon/36', 'api/v2/berry/8', 'https://pokeapi.co/api/v2/ability/9/'])
.then((response) => {
console.log(response); // the getResource function accepts singles or arrays of URLs/paths
});
P.getPokemonByName(34, (response, error) => { // with callback
if(!error) {
console.log(response);
} else {
console.log(error)
}
});

P.getResource(['/api/v2/pokemon/36', 'api/v2/berry/8', 'https://pokeapi.co/api/v2/ability/9/'])
.then((response) => {
console.log(response); // the getResource function accepts singles or arrays of URLs/paths
});
```

## Configuration
Expand Down Expand Up @@ -782,3 +794,18 @@ This is what you will get:
* .getStatsList()
* .getTypesList()
* .getLanguagesList()

## Development

A linux environment is preferred. `bash`, `sed`, `find` and required.

```sh
npm i
npm run apidata:clone # Only if you are building for the first time
npm run apidata:sync # Only if you have already built once
npm run apidata:replace
npm run generate:types
npm run generate:main
npm run generate:jsdocs
npm t
```
Loading

0 comments on commit 4f533c8

Please sign in to comment.