Skip to content

Commit b88ba77

Browse files
authored
Merge pull request #85 from PokeAPI/beta
New version
2 parents 0bd693b + 9824f0c commit b88ba77

24 files changed

Lines changed: 918 additions & 10139 deletions

.github/dependabot.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
version: 2
22
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
37
- package-ecosystem: "npm"
48
directory: "/"
59
schedule:
610
interval: "monthly"
7-
reviewers:
8-
- "Naramsim"
911
groups:
1012
dependencies:
1113
patterns:
1214
- "*"
13-
versioning-strategy: increase
15+
versioning-strategy: auto

.github/workflows/test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node-version: [ 16, 18, 20 ]
10+
node-version: [ 16, 18, 20, lts/*, latest ]
1111
steps:
1212
- name: Clone repository
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v6
1414
- name: Setup node
15-
uses: actions/setup-node@v2
15+
uses: actions/setup-node@v6
1616
with:
1717
node-version: ${{ matrix.node }}
1818
- name: Install dependencies
1919
run: |
2020
npm ci
2121
npm install -g codecov
22-
- name: Build
23-
run: npm run build
2422
- name: Unit test
25-
run: npm t
23+
run: npm run coverage
2624
- name: Upload coverage
27-
uses: codecov/codecov-action@v2
25+
uses: codecov/codecov-action@v6
26+
with:
27+
files: ./lcov.info
28+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
node_modules
22
*.js.map
3-
.nyc_output
4-
coverage
3+
lcov.info

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
node_modules
22
test
3-
.travis.yml
4-
webpack.config.js
3+
.github

README.md

Lines changed: 32 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
[![npm](https://img.shields.io/npm/v/pokeapi-js-wrapper)](https://www.npmjs.com/package/pokeapi-js-wrapper)
44
[![Tests](https://github.com/PokeAPI/pokeapi-js-wrapper/actions/workflows/test.yml/badge.svg)](https://github.com/PokeAPI/pokeapi-js-wrapper/actions/workflows/test.yml)
55
[![Mocha browser tests](https://img.shields.io/badge/test-browser-brightgreen.svg)](https://pokeapi.github.io/pokeapi-js-wrapper/test/test.html)
6-
[![codecov](https://codecov.io/gh/PokeAPI/pokeapi-js-wrapper/branch/master/graph/badge.svg)](https://codecov.io/gh/PokeAPI/pokeapi-js-wrapper)
6+
[![codecov](https://codecov.io/github/PokeAPI/pokeapi-js-wrapper/graph/badge.svg?token=4oXXOVxG2n)](https://codecov.io/github/PokeAPI/pokeapi-js-wrapper)
77

88
Maintainer: [Naramsim](https://github.com/Naramsim)
99

10-
A PokeAPI wrapper intended for browsers only. Comes fully asynchronous (with [localForage](https://github.com/localForage/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](https://github.com/PokeAPI/pokedex-promise-v2)_
11-
12-
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
13-
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
10+
A PokeAPI wrapper intended for browsers. Comes fully asynchronous, zero dependencies 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](https://github.com/PokeAPI/pokedex-promise-v2)_
1411

1512
- [Install](#install)
1613
- [Usage](#usage)
@@ -21,49 +18,42 @@ A PokeAPI wrapper intended for browsers only. Comes fully asynchronous (with [lo
2118
- [Endpoints](#endpoints)
2219
- [Root Endpoints list](#root-endpoints-list)
2320
- [Custom URLs and paths](#custom-urls-and-paths)
24-
- [Internet Explorer 8](#internet-explorer-8)
25-
26-
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
27-
28-
## Install
29-
30-
```sh
31-
npm install pokeapi-js-wrapper --save
32-
```
33-
34-
```html
35-
<script src="https://unpkg.com/pokeapi-js-wrapper/dist/index.js"></script>
36-
```
3721

3822
## Usage
3923

4024
```js
41-
const Pokedex = require("pokeapi-js-wrapper")
42-
const P = new Pokedex.Pokedex()
25+
// As a Node module
26+
// npm install pokeapi-js-wrapper --save
27+
const pokedex = await Pokedex.init();
28+
console.log(await pokedex.getPokemonsList())
4329
```
4430

4531
```html
46-
<script>
47-
const P = new Pokedex.Pokedex()
32+
<!-- Included in some HTML -->
33+
<script type="module">
34+
import {Pokedex} from "https://cdn.jsdelivr.net/gh/pokeapi/pokeapi-js-wrapper@beta/src/index.js"
35+
const pokedex = await Pokedex.init();
36+
const version = await pokedex.getVersionByName(1)
37+
console.log(version)
4838
</script>
4939
```
5040

51-
### [Example](https://jsbin.com/jedakor/5/edit?html,console) requests
41+
### [Example](https://jsbin.com/jedakor/9/edit?html,console) requests
5242

5343
```js
5444
// with await, be sure to be in an async function (and in a try/catch)
5545
(async () => {
56-
const golduck = await P.getPokemonByName("golduck")
46+
const golduck = await pokedex.getPokemonByName("golduck")
5747
console.log(golduck)
5848
})()
5949

6050
// or with Promises
61-
P.getPokemonByName("eevee")
51+
pokedex.getPokemonByName("eevee")
6252
.then(function(response) {
6353
console.log(response)
6454
})
6555

66-
P.resource([
56+
pokedex.resource([
6757
"/api/v2/pokemon/36",
6858
"api/v2/berry/8",
6959
"https://pokeapi.co/api/v2/ability/9/",
@@ -74,11 +64,10 @@ P.resource([
7464

7565
## Configuration
7666

77-
Pass an Object to `Pokedex()` in order to configure it. Available options: `protocol`, `hostName`, `versionPath`, `cache`, `timeout`(ms), and `cacheImages`.
67+
Pass an Object to `Pokedex.init()` in order to configure it. Available options: `protocol`, `hostName`, `versionPath`, `cache`, `timeout`(ms), and `cacheImages`.
7868
Any option is optional :smile:. All the default values can be found [here](https://github.com/PokeAPI/pokeapi-js-wrapper/blob/master/src/config.js#L3-L10)
7969

8070
```js
81-
const Pokedex = require("pokeapi-js-wrapper")
8271
const customOptions = {
8372
protocol: "https",
8473
hostName: "localhost:443",
@@ -87,7 +76,7 @@ const customOptions = {
8776
timeout: 5 * 1000, // 5s
8877
cacheImages: true
8978
}
90-
const P = new Pokedex.Pokedex(customOptions)
79+
const pokedex = await Pokedex.init(customOptions);
9180
```
9281

9382
### Caching images
@@ -97,17 +86,17 @@ Pokeapi.co serves its Pokemon images through [Github](https://github.com/PokeAPI
9786
`pokeapi-js-wrapper` enables browsers to cache all these images by:
9887

9988
1. enabling the config parameter `cacheImages`
100-
2. serving [our service worker](https://raw.githubusercontent.com/PokeAPI/pokeapi-js-wrapper/master/dist/pokeapi-js-wrapper-sw.js) from the root of your project
89+
2. serving [our service worker](https://raw.githubusercontent.com/PokeAPI/pokeapi-js-wrapper/master/src/pokeapi-js-wrapper-sw.js) from the root of your project
10190

102-
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.
91+
In this way when `pokeapi-js-wrapper`'s `Pokedex` is initialized 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.
10392

104-
It's fundamental that you download the Service Worker [we provide](https://raw.githubusercontent.com/PokeAPI/pokeapi-js-wrapper/master/dist/pokeapi-js-wrapper-sw.js)_(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.
93+
It's fundamental that you download the Service Worker [we provide](https://raw.githubusercontent.com/PokeAPI/pokeapi-js-wrapper/master/src/pokeapi-js-wrapper-sw.js)_(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.
10594

10695
A [basic example](https://github.com/PokeAPI/pokeapi-js-wrapper/blob/master/test/example-sw.html) is hosted [here](https://pokeapi.github.io/pokeapi-js-wrapper/test/example-sw.html).
10796

10897
## Tests
10998

110-
`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.
99+
`pokeapi-js-wrapper` can be tested using two strategies. One is with Node, since this package works with Node, and the other with a browser.
111100

112101
```js
113102
npm test
@@ -120,23 +109,15 @@ Or open `/test/test.html` in your browser. A live version can be found at [`gh-p
120109
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.
121110

122111
```js
123-
P.getPokemonByName("eevee").then(function(response) {
124-
console.log(response)
125-
})
112+
response = await pokedex.getPokemonByName("eevee")
126113

127-
P.getPokemonSpeciesByName(25).then(function(response) {
128-
console.log(response)
129-
})
114+
response = await pokedex.getPokemonSpeciesByName(25)
130115

131-
P.getBerryByName(["cheri", "chesto", 5]).then(function(response) {
132-
// `response` will be an Array containing 3 Objects
133-
// response.forEach((item) => {console.log(item.size)}) // 80,50,20
134-
console.log(response)
135-
})
116+
// `response` will be an Array containing 3 Objects
117+
// response.forEach((item) => {console.log(item.size)}) // 80,50,20
118+
response = await pokedex.getBerryByName(["cheri", "chesto", 5])
136119

137-
P.getMachineById(3).then(function(response) {
138-
console.log(response)
139-
})
120+
response = await pokedex.getMachineById(3)
140121
```
141122

142123
| Function | Mapped PokeAPI endpoint | Documentation |
@@ -207,42 +188,11 @@ const interval = {
207188
offset: 34,
208189
limit: 10,
209190
}
210-
P.getPokemonsList(interval).then(function(response) {
191+
pokedex.getPokemonsList(interval).then(function(response) {
211192
console.log(response)
212193
})
213194
```
214195

215-
<!--
216-
This is what you will get:
217-
218-
```json
219-
{
220-
"count": 1050,
221-
"next": "https://pokeapi.co/api/v2/pokemon/?offset=43&limit=10",
222-
"previous": "https://pokeapi.co/api/v2/pokemon/?offset=23&limit=10",
223-
"results": [
224-
{
225-
"name": "nidoking",
226-
"url": "https://pokeapi.co/api/v2/pokemon/34/"
227-
},
228-
{
229-
"name": "clefairy",
230-
"url": "https://pokeapi.co/api/v2/pokemon/35/"
231-
},
232-
// ...
233-
{
234-
"name": "golbat",
235-
"url": "https://pokeapi.co/api/v2/pokemon/42/"
236-
},
237-
{
238-
"name": "oddish",
239-
"url": "https://pokeapi.co/api/v2/pokemon/43/"
240-
}
241-
]
242-
}
243-
```
244-
-->
245-
246196
| Function | Mapped PokeAPI endpoint |
247197
| --- | --- |
248198
| `getEndpointsList()` | [/](https://pokeapi.co/api/v2/) |
@@ -267,6 +217,7 @@ This is what you will get:
267217
| `getItemFlingEffectsList()` | [/item-fling-effect](https://pokeapi.co/api/v2/item-fling-effect/) |
268218
| `getItemPocketsList()` | [/item-pocket](https://pokeapi.co/api/v2/item-pocket/) |
269219
| `getMachinesList()` | [/machine](https://pokeapi.co/api/v2/machine/) |
220+
| `getMeta()` | [/meta](https://pokeapi.co/api/v2/meta/) |
270221
| `getMovesList()` | [/move](https://pokeapi.co/api/v2/move/) |
271222
| `getMoveAilmentsList()` | [/move-ailment](https://pokeapi.co/api/v2/move-ailment/) |
272223
| `getMoveBattleStylesList()` | [/move-battle-style](https://pokeapi.co/api/v2/move-battle-style/) |
@@ -300,19 +251,15 @@ This is what you will get:
300251
Use `.resource()` to query any URL or path. Also this function accepts both single values and Arrays.
301252

302253
```js
303-
P.resource([
254+
pokedex.resource([
304255
"/api/v2/pokemon/36",
305256
"api/v2/berry/8",
306257
"https://pokeapi.co/api/v2/ability/9/",
307258
]).then(function(response) {
308259
console.log(response)
309260
})
310261

311-
P.resource("api/v2/berry/5").then(function(response) {
262+
pokedex.resource("api/v2/berry/5").then(function(response) {
312263
console.log(response)
313264
})
314265
```
315-
316-
## Internet Explorer 8
317-
318-
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](https://cdnjs.com/libraries/es6-promise) or [stefanpenner/es6-promise](https://github.com/stefanpenner/es6-promise)

codecov.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/index.js.LICENSE.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

dist/pokeapi-js-wrapper-sw.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)