@lucasmod/pokemon.js 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -0
- package/docs/favicon.ico +0 -0
- package/docs/index.html +134 -0
- package/docs/styles.css +173 -0
- package/package.json +30 -0
- package/src/PokeAPI/get_ability.js +18 -0
- package/src/PokeAPI/get_all.js +10 -0
- package/src/PokeAPI/get_evolution_line.js +19 -0
- package/src/PokeAPI/get_generation.js +12 -0
- package/src/PokeAPI/get_item.js +14 -0
- package/src/PokeAPI/get_move.js +14 -0
- package/src/PokeAPI/get_nature.js +14 -0
- package/src/PokeAPI/get_pokemon.js +14 -0
- package/src/PokeAPI/get_pokemon_species.js +14 -0
- package/src/PokeAPI/get_region.js +13 -0
- package/src/PokeAPI/get_type.js +18 -0
- package/src/index.js +25 -0
- package/src/utils/filter_data.js +13 -0
- package/src/utils/format.js +3 -0
- package/src/utils/get.js +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @lucasmod/pokemon.js
|
|
2
|
+
|
|
3
|
+
### 🚀 Versão Corrigida e Mantida por: **lucasmod**
|
|
4
|
+
|
|
5
|
+
Esta é uma versão modificada do pacote original [pokemon.js](https://www.npmjs.com/package/pokemon.js), corrigindo erros de importação ESM e garantindo compatibilidade com as versões mais recentes do Node.js.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
<div align="left">
|
|
9
|
+
<br />
|
|
10
|
+
<p>
|
|
11
|
+
<a href="https://www.npmjs.com/package/pokemon.js"><img src="https://i.postimg.cc/Sx7sKrmx/pokemon.png" width="546" alt="pokemon.js" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
<br />
|
|
14
|
+
<p>
|
|
15
|
+
<a href="https://www.npmjs.com/package/pokemon.js"><img src="https://img.shields.io/npm/v/pokemon.js.svg" alt="NPM Version" /></a>
|
|
16
|
+
<a href="https://www.npmjs.com/package/pokemon.js"><img src = "https://img.shields.io/npm/dt/pokemon.js.svg" alt="NPM Downloads"/></a>
|
|
17
|
+
</p>
|
|
18
|
+
<p>
|
|
19
|
+
<a href="https://www.npmjs.com/package/pokemon.js"><img src="https://nodei.co/npm/pokemon.js.png" alt="npm installinfo" /></a>
|
|
20
|
+
</p>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
## Table Of Contents
|
|
24
|
+
|
|
25
|
+
- [About](#about)
|
|
26
|
+
- [Installation](#installation)
|
|
27
|
+
- [Example Usage](#example-usage)
|
|
28
|
+
- [Methods](#methods)
|
|
29
|
+
- [Links](#links)
|
|
30
|
+
|
|
31
|
+
## About
|
|
32
|
+
|
|
33
|
+
pokemon.js is a [Node.js](https://nodejs.org) module that makes interacting with [PokéAPI](https://pokeapi.co/) easier.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
**Node.js 12.0.0 or newer is required.**
|
|
38
|
+
No dependencies are required.
|
|
39
|
+
|
|
40
|
+
`npm install pokemon.js`
|
|
41
|
+
|
|
42
|
+
## Example Usage
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import Pokemon from 'pokemon.js';
|
|
46
|
+
|
|
47
|
+
Pokemon.get_pokemon('zorua').then(console.log);
|
|
48
|
+
```
|
|
49
|
+
### Methods
|
|
50
|
+
|
|
51
|
+
**`get_pokemon(pokemon, fields=[])`**:
|
|
52
|
+
Returns data for the pokémon in JSON format.
|
|
53
|
+
|
|
54
|
+
**`get_type(name, is_pokemon=false, fields=[])`**:
|
|
55
|
+
Returns an Array of the pokemon's types or returns data for the type in JSON format.
|
|
56
|
+
|
|
57
|
+
**`get_ability(name, is_pokemon=false, fields=[])`**:
|
|
58
|
+
Returns an Array of the pokemon's abilities or returns data for the ability in JSON format.
|
|
59
|
+
|
|
60
|
+
**`get_evolution_line(pokemon, fields=[])`**:
|
|
61
|
+
Returns an Array that contains the evolution line of the pokémon.
|
|
62
|
+
|
|
63
|
+
**`get_move(move, fields=[])`**:
|
|
64
|
+
Returns data on the move in JSON format.
|
|
65
|
+
|
|
66
|
+
**`get_nature(nature, fields=[])`**:
|
|
67
|
+
Returns an Object that contains the increased and decreased stat caused by the nature.
|
|
68
|
+
|
|
69
|
+
**`get_item(item, fields=[])`**:
|
|
70
|
+
Returns data on the item in JSON format.
|
|
71
|
+
|
|
72
|
+
**`get_generation(generation, fields=[])`**:
|
|
73
|
+
Returns data on the generation in JSON format.
|
|
74
|
+
|
|
75
|
+
**`get_region(region, fields=[])`**:
|
|
76
|
+
Returns data on the region in JSON format.
|
|
77
|
+
|
|
78
|
+
**`get_all(type)`**:
|
|
79
|
+
Returns an Array containing names of all the specified resource type.
|
|
80
|
+
|
|
81
|
+
## Links
|
|
82
|
+
|
|
83
|
+
- [NPM](https://www.npmjs.com/package/pokemon.js)
|
|
84
|
+
- [GitHub](https://github.com/musubi3/pokemon.js.git)
|
|
85
|
+
- [PokéAPI](https://pokeapi.co/)
|
|
86
|
+
|
package/docs/favicon.ico
ADDED
|
Binary file
|
package/docs/index.html
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<script src="https://musubi3.github.io/global.js" type="module"></script>
|
|
6
|
+
<link rel="stylesheet" href="https://musubi3.github.io/global.css">
|
|
7
|
+
<link rel="stylesheet" href="styles.css">
|
|
8
|
+
<meta charset="UTF-8">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
10
|
+
<title>pokemon.js</title>
|
|
11
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css">
|
|
14
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
|
|
15
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js"></script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<div class="content project-detail">
|
|
20
|
+
<header class="project-header">
|
|
21
|
+
<h1>pokemon.js</h1>
|
|
22
|
+
<div class="project-meta">
|
|
23
|
+
<p class="project-author">Justin Lee</p>
|
|
24
|
+
<div class="project-info">
|
|
25
|
+
<span class="tag project-date">Winter 2021</span>
|
|
26
|
+
<span class="tag project-category">Personal Project</span>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</header>
|
|
30
|
+
|
|
31
|
+
<div class="project-badges">
|
|
32
|
+
<a href="https://www.npmjs.com/package/pokemon.js">
|
|
33
|
+
<img src="https://img.shields.io/npm/v/pokemon.js.svg" alt="NPM Version">
|
|
34
|
+
</a>
|
|
35
|
+
<a href="https://www.npmjs.com/package/pokemon.js">
|
|
36
|
+
<img src="https://img.shields.io/npm/dt/pokemon.js.svg" alt="NPM Downloads">
|
|
37
|
+
</a>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<nav class="toc">
|
|
41
|
+
<h3>Table of Contents</h3>
|
|
42
|
+
<ul>
|
|
43
|
+
<li><a href="#about">About</a></li>
|
|
44
|
+
<li><a href="#installation">Installation</a></li>
|
|
45
|
+
<li><a href="#example-usage">Example Usage</a></li>
|
|
46
|
+
<li><a href="#methods">Methods</a></li>
|
|
47
|
+
<li><a href="#links">Links</a></li>
|
|
48
|
+
</ul>
|
|
49
|
+
</nav>
|
|
50
|
+
|
|
51
|
+
<h2 id="about">About</h2>
|
|
52
|
+
|
|
53
|
+
<p>pokemon.js is a <a href="https://nodejs.org">Node.js</a> module that makes interacting with <a
|
|
54
|
+
href="https://pokeapi.co/">PokéAPI</a> easier.</p>
|
|
55
|
+
|
|
56
|
+
<section id="installation" class="project-section">
|
|
57
|
+
<h2>Installation</h2>
|
|
58
|
+
<p><strong>Node.js 12.0.0 or newer is required.</strong><br>
|
|
59
|
+
No dependencies are required.</p>
|
|
60
|
+
<code class="install-command">npm install pokemon.js</code>
|
|
61
|
+
</section>
|
|
62
|
+
|
|
63
|
+
<section id="example-usage" class="project-section">
|
|
64
|
+
<h2>Example Usage</h2>
|
|
65
|
+
<pre class="code-block"><code class="language-javascript">import Pokemon from 'pokemon.js';
|
|
66
|
+
|
|
67
|
+
Pokemon.get_pokemon('zorua').then(console.log);</code></pre>
|
|
68
|
+
</section>
|
|
69
|
+
|
|
70
|
+
<section id="methods" class="project-section">
|
|
71
|
+
<h2>Methods</h2>
|
|
72
|
+
<div class="method-list">
|
|
73
|
+
<div class="card method">
|
|
74
|
+
<h3><code>get_pokemon(pokemon, fields=[])</code></h3>
|
|
75
|
+
<p>Returns data for the pokémon in JSON format.</p>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<div class="card method">
|
|
79
|
+
<h3><code>get_type(name, is_pokemon=false, fields=[])</code></h3>
|
|
80
|
+
<p>Returns an Array of the pokemon's types or returns data for the type in JSON format.</p>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div class="card method">
|
|
84
|
+
<h3><code>get_ability(name, is_pokemon=false, fields=[])</code></h3>
|
|
85
|
+
<p>Returns an Array of the pokemon's abilities or returns data for the ability in JSON format.</p>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<div class="card method">
|
|
89
|
+
<h3><code>get_evolution_line(pokemon, fields=[])</code></h3>
|
|
90
|
+
<p>Returns an Array that contains the evolution line of the pokémon.</p>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<div class="card method">
|
|
94
|
+
<h3><code>get_move(move, fields=[])</code></h3>
|
|
95
|
+
<p>Returns data on the move in JSON format.</p>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div class="card method">
|
|
99
|
+
<h3><code>get_nature(nature, fields=[])</code></h3>
|
|
100
|
+
<p>Returns an Object that contains the increased and decreased stat caused by the nature.</p>
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<div class="card method">
|
|
104
|
+
<h3><code>get_item(item, fields=[])</code></h3>
|
|
105
|
+
<p>Returns data on the item in JSON format.</p>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div class="card method">
|
|
109
|
+
<h3><code>get_generation(generation, fields=[])</code></h3>
|
|
110
|
+
<p>Returns data on the generation in JSON format.</p>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<div class="card method">
|
|
114
|
+
<h3><code>get_region(region, fields=[])</code></h3>
|
|
115
|
+
<p>Returns data on the region in JSON format.</p>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<div class="card method">
|
|
119
|
+
<h3><code>get_all(type)</code></h3>
|
|
120
|
+
<p>Returns an Array containing names of all the specified resource type.</p>
|
|
121
|
+
</div>
|
|
122
|
+
</section>
|
|
123
|
+
|
|
124
|
+
<h2 id="links">Links</h2>
|
|
125
|
+
|
|
126
|
+
<ul class="links">
|
|
127
|
+
<li><a href="https://www.npmjs.com/package/pokemon.js" class="tag">NPM</a></li>
|
|
128
|
+
<li><a href="https://github.com/musubi3/pokemon.js.git" class="tag">GitHub</a></li>
|
|
129
|
+
<li><a href="https://pokeapi.co/" class="tag">PokéAPI</a></li>
|
|
130
|
+
</ul>
|
|
131
|
+
</div>
|
|
132
|
+
</body>
|
|
133
|
+
|
|
134
|
+
</html>
|
package/docs/styles.css
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/* ANIMATIONS */
|
|
2
|
+
.project-detail>* {
|
|
3
|
+
opacity: 0;
|
|
4
|
+
transform: translateY(-20px);
|
|
5
|
+
animation: fadeInUp 0.8s ease forwards;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.project-header {
|
|
9
|
+
animation-delay: 0.1s;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.project-badges {
|
|
13
|
+
animation-delay: 0.2s;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.project-toc {
|
|
17
|
+
animation-delay: 0.3s;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#about {
|
|
21
|
+
animation-delay: 0.4s;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#installation {
|
|
25
|
+
animation-delay: 0.5s;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#example-usage {
|
|
29
|
+
animation-delay: 0.6s;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#methods {
|
|
33
|
+
animation-delay: 0.7s;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#links {
|
|
37
|
+
animation-delay: 0.8s;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Badge animations */
|
|
41
|
+
.project-badges img {
|
|
42
|
+
display: inline-block;
|
|
43
|
+
animation: badgeBounce 0.8s ease 0.3s forwards;
|
|
44
|
+
opacity: 0;
|
|
45
|
+
transform: scale(0.8);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.project-badges a:nth-child(1) img {
|
|
49
|
+
animation-delay: 0.3s;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.project-badges a:nth-child(2) img {
|
|
53
|
+
animation-delay: 0.4s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.project-badges a:nth-child(3) img {
|
|
57
|
+
animation-delay: 0.5s;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Link tags */
|
|
61
|
+
.links li a {
|
|
62
|
+
opacity: 0;
|
|
63
|
+
transform: scale(0.8);
|
|
64
|
+
animation: evolveIn 0.5s ease forwards;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.links li:nth-child(1) a {
|
|
68
|
+
animation-delay: 0.8s;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.links li:nth-child(2) a {
|
|
72
|
+
animation-delay: 0.85s;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.links li:nth-child(3) a {
|
|
76
|
+
animation-delay: 0.9s;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Keyframes */
|
|
80
|
+
@keyframes fadeInUp {
|
|
81
|
+
to {
|
|
82
|
+
opacity: 1;
|
|
83
|
+
transform: translateY(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@keyframes badgeBounce {
|
|
88
|
+
0% {
|
|
89
|
+
opacity: 0;
|
|
90
|
+
transform: scale(0.8) translateY(-20px);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
60% {
|
|
94
|
+
transform: scale(1.1) translateY(5px);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
100% {
|
|
98
|
+
opacity: 1;
|
|
99
|
+
transform: scale(1) translateY(0);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@keyframes evolveIn {
|
|
104
|
+
to {
|
|
105
|
+
opacity: 1;
|
|
106
|
+
transform: scale(1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
body {
|
|
111
|
+
padding-bottom: 1.5em;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.code-block {
|
|
115
|
+
background: var(--code);
|
|
116
|
+
padding: 1.5em;
|
|
117
|
+
border-radius: 8px;
|
|
118
|
+
border-left: 4px solid var(--color-accent);
|
|
119
|
+
overflow-x: auto;
|
|
120
|
+
line-height: 1.4;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.install-command {
|
|
124
|
+
padding: 0.25em 0.5em;
|
|
125
|
+
display: inline-block;
|
|
126
|
+
font-size: 1.1em;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.method-list {
|
|
130
|
+
display: flex;
|
|
131
|
+
flex-direction: column;
|
|
132
|
+
gap: 1.5em;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.method {
|
|
136
|
+
padding: 1.5em 1em 0.5em 1em;
|
|
137
|
+
border-radius: 8px;
|
|
138
|
+
border-left: 3px solid var(--color-accent);
|
|
139
|
+
border-right: 1px solid var(--card-border);
|
|
140
|
+
border-top: 1px solid var(--card-border);
|
|
141
|
+
border-bottom: 1px solid var(--card-border);
|
|
142
|
+
transition: all 0.2s ease;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.method h3 {
|
|
146
|
+
margin: 0 0 0.5em 0;
|
|
147
|
+
font-size: 1.1em;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.method code {
|
|
151
|
+
padding: 0.5em;
|
|
152
|
+
font-size: 0.9em;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.links {
|
|
156
|
+
display: flex;
|
|
157
|
+
flex-wrap: wrap;
|
|
158
|
+
gap: 0.7em;
|
|
159
|
+
list-style: none;
|
|
160
|
+
padding: 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.links li a {
|
|
164
|
+
margin: 0;
|
|
165
|
+
font-weight: 500;
|
|
166
|
+
text-decoration: none;
|
|
167
|
+
transition: all 0.2s ease;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.links li a:hover {
|
|
171
|
+
background: var(--tag-hover);
|
|
172
|
+
color: white;
|
|
173
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"test": "node ./module_test/test.js"
|
|
4
|
+
},
|
|
5
|
+
"name": "@lucasmod/pokemon.js",
|
|
6
|
+
"version": "2.1.1",
|
|
7
|
+
"description": "Versão corrigida do pokemon.js com suporte a ESM e créditos para lucasmod",
|
|
8
|
+
"author": "lucasmod",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./src/index.js",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/musubi3/pokemon.js.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/musubi3/pokemon.js/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "musubi3.github.io/pokemon.js/",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"pokemon",
|
|
22
|
+
"pokeapi",
|
|
23
|
+
"javascript",
|
|
24
|
+
"js",
|
|
25
|
+
"api"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"node-fetch": "^3.3.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import filter_data from '../utils/filter_data.js';
|
|
2
|
+
import format_name from '../utils/format.js';
|
|
3
|
+
import get from '../utils/get.js'
|
|
4
|
+
|
|
5
|
+
/** Returns an Array of the pokémon's abilities or returns data for the ability in JSON format.
|
|
6
|
+
* @param {String | Number} name The ability or pokémon name.
|
|
7
|
+
* @param {boolean} is_pokemon Optional. Default is false.
|
|
8
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
9
|
+
* @returns {Promise<Object>} */
|
|
10
|
+
export default async function get_ability(name, is_pokemon = false, fields = []) {
|
|
11
|
+
name = format_name(name);
|
|
12
|
+
const data = is_pokemon ? await get(`pokemon/${name}`) : await get(`ability/${ability_name}`);
|
|
13
|
+
|
|
14
|
+
if (is_pokemon)
|
|
15
|
+
return data ? data['abilities'] : null;
|
|
16
|
+
|
|
17
|
+
return data ? filter_data(data, fields) : null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import get from "../utils/get.js";
|
|
2
|
+
|
|
3
|
+
/** Returns an Array containing names of all the specified resource type.
|
|
4
|
+
* @param {'item'|'pokemon'|'ability'|'type'|'move'|'nature'|'region'} type
|
|
5
|
+
* @returns {Promise<Array>} */
|
|
6
|
+
export default async function get_all(type = 'pokemon') {
|
|
7
|
+
const data = await get(`${type}?limit=100000&offset=0`);
|
|
8
|
+
|
|
9
|
+
return data ? data['results'].map(i => i.name) : null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import filter_data from '../utils/filter_data.js';
|
|
2
|
+
import get from '../utils/get.js'
|
|
3
|
+
import get_pokemon_species from './get_pokemon_species.js'
|
|
4
|
+
|
|
5
|
+
/** Returns data for the given pokémon.
|
|
6
|
+
* @param {String} pokemon Pokémon name or Pokédex #
|
|
7
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
8
|
+
* @returns {Promise<Object>} */
|
|
9
|
+
export default async function get_evolution_line(pokemon, fields = []) {
|
|
10
|
+
const SPECIES = await get_pokemon_species(pokemon);
|
|
11
|
+
|
|
12
|
+
if (!SPECIES)
|
|
13
|
+
return null;
|
|
14
|
+
|
|
15
|
+
const EVO_CHAIN = SPECIES.evolution_chain.url.split('/')[6];
|
|
16
|
+
const data = await get(`evolution-chain/${EVO_CHAIN}`);
|
|
17
|
+
|
|
18
|
+
return data ? filter_data(data, fields) : null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import filter_data from "../utils/filter_data.js";
|
|
2
|
+
import get from "../utils/get.js";
|
|
3
|
+
|
|
4
|
+
/** Returns data on the generation in JSON format.
|
|
5
|
+
* @param {Number} generation
|
|
6
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
7
|
+
* @returns {Promise<Object>} */
|
|
8
|
+
export default async function get_generation(generation, fields = []) {
|
|
9
|
+
const data = await get(`generation/${generation}`);
|
|
10
|
+
|
|
11
|
+
return data ? filter_data(data, fields) : null;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import filter_data from "../utils/filter_data.js";
|
|
2
|
+
import format_name from "../utils/format.js";
|
|
3
|
+
import get from "../utils/get.js";
|
|
4
|
+
|
|
5
|
+
/** Returns data on the item in JSON format.
|
|
6
|
+
* @param {String} item_name
|
|
7
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
8
|
+
* @returns {Promise<Object>} */
|
|
9
|
+
export default async function get_item(item_name, fields = []) {
|
|
10
|
+
item_name = format_name(item_name);
|
|
11
|
+
const data = await get(`item/${item_name}`);
|
|
12
|
+
|
|
13
|
+
return data ? filter_data(data, fields) : null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import filter_data from "../utils/filter_data.js";
|
|
2
|
+
import format_name from "../utils/format.js";
|
|
3
|
+
import get from "../utils/get.js";
|
|
4
|
+
|
|
5
|
+
/** Returns data on the move in JSON fromat.
|
|
6
|
+
* @param {String} move_name
|
|
7
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
8
|
+
* @returns {Promise<Object>} */
|
|
9
|
+
export default async function get_move(move_name, fields = []) {
|
|
10
|
+
move_name = format_name(move);
|
|
11
|
+
const data = await get(`move/${move_name}`);
|
|
12
|
+
|
|
13
|
+
return data ? filter_data(data, fields) : null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import filter_data from '../utils/filter_data.js';
|
|
2
|
+
import format_name from '../utils/format.js';
|
|
3
|
+
import get from '../utils/get.js'
|
|
4
|
+
|
|
5
|
+
/** Returns an Object that contains the increased and decreased stat caused by the nature.
|
|
6
|
+
* @param {'hardy'|'bold'|'modest'|'calm'|'timid'|'lonely'|'docile'|'mild'|'gentle'|'hasty'|'adamant'|'impish'|'bashful'|'careful'|'rash'|'jolly'|'naughty'|'lax'|'quirky'|'naive'|'brave'|'relaxed'|'quiet'|'sassy'|'serious'} nature_name
|
|
7
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
8
|
+
* @returns {Promise<Object>} */
|
|
9
|
+
export default async function get_nature(nature_name, fields = []) {
|
|
10
|
+
nature_name = format_name(nature_name);
|
|
11
|
+
const data = await get(`nature/${nature_name}`);
|
|
12
|
+
|
|
13
|
+
return data ? filter_data(data, fields) : null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import filter_data from '../utils/filter_data.js';
|
|
2
|
+
import format_name from '../utils/format.js';
|
|
3
|
+
import get from '../utils/get.js'
|
|
4
|
+
|
|
5
|
+
/** Returns data for the given pokémon.
|
|
6
|
+
* @param {String} pokemon Pokémon name or Pokédex #
|
|
7
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
8
|
+
* @returns {Promise<Object>} */
|
|
9
|
+
export default async function get_pokemon(pokemon, fields = []) {
|
|
10
|
+
pokemon = format_name(pokemon);
|
|
11
|
+
const data = await get(`pokemon/${pokemon}`);
|
|
12
|
+
|
|
13
|
+
return data ? filter_data(data, fields) : null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import filter_data from '../utils/filter_data.js';
|
|
2
|
+
import format_name from '../utils/format.js';
|
|
3
|
+
import get from '../utils/get.js'
|
|
4
|
+
|
|
5
|
+
/** Returns data for the given pokémon.
|
|
6
|
+
* @param {String} pokemon Pokémon name or Pokédex #
|
|
7
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
8
|
+
* @returns {Promise<Object>} */
|
|
9
|
+
export default async function get_pokemon_species(pokemon, fields = []) {
|
|
10
|
+
pokemon = format_name(pokemon);
|
|
11
|
+
const data = await get(`pokemon-species/${pokemon}`);
|
|
12
|
+
|
|
13
|
+
return data ? filter_data(data, fields) : null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import format_name from "../utils/format.js";
|
|
2
|
+
import get from "../utils/get.js";
|
|
3
|
+
|
|
4
|
+
/** Returns data on the region in JSON format.
|
|
5
|
+
* @param {'kanto'|'johto'|'hoenn'|'sinnoh'|'unova'|'kalos'|'alola'|'galar'|'hisui'|'paldea'} region
|
|
6
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
7
|
+
* @returns {Promise<JSON>} */
|
|
8
|
+
export default async function get_region(region, fields = []) {
|
|
9
|
+
region = format_name(region);
|
|
10
|
+
const data = await get(`region/${region}`);
|
|
11
|
+
|
|
12
|
+
return data ? filter_data(data, fields) : null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import filter_data from '../utils/filter_data.js';
|
|
2
|
+
import format_name from '../utils/format.js';
|
|
3
|
+
import get from '../utils/get.js'
|
|
4
|
+
|
|
5
|
+
/** Returns an Array of the pokémon's types or returns data for the type in JSON format.
|
|
6
|
+
* @param {String | Number} name The type or pokémon name.
|
|
7
|
+
* @param {boolean} is_pokemon Optional. Default is false.
|
|
8
|
+
* @param {String[]} fields Optional. An array of property names to include in the returned object.
|
|
9
|
+
* @returns {Promise<Object> | Promise<Array>} */
|
|
10
|
+
export default async function get_type(name, is_pokemon = false, fields = []) {
|
|
11
|
+
name = format_name(name);
|
|
12
|
+
const data = is_pokemon ? await get(`pokemon/${name}`) : await get(`type/${name}`);
|
|
13
|
+
|
|
14
|
+
if (is_pokemon)
|
|
15
|
+
return data ? data['types'] : null;
|
|
16
|
+
|
|
17
|
+
return data ? filter_data(data, fields) : null;
|
|
18
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import get_ability from './PokeAPI/get_ability.js';
|
|
2
|
+
import get_evolution_line from './PokeAPI/get_evolution_line.js';
|
|
3
|
+
import get_generation from './PokeAPI/get_generation.js';
|
|
4
|
+
import get_item from './PokeAPI/get_item.js';
|
|
5
|
+
import get_move from './PokeAPI/get_move.js';
|
|
6
|
+
import get_nature from './PokeAPI/get_nature.js';
|
|
7
|
+
import get_pokemon from './PokeAPI/get_pokemon.js';
|
|
8
|
+
import get_pokemon_species from './PokeAPI/get_pokemon_species.js';
|
|
9
|
+
import get_type from './PokeAPI/get_type.js';
|
|
10
|
+
import get_region from './PokeAPI/get_region.js';
|
|
11
|
+
import get_all from './PokeAPI/get_all.js';
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
get_pokemon,
|
|
15
|
+
get_pokemon_species,
|
|
16
|
+
get_evolution_line,
|
|
17
|
+
get_type,
|
|
18
|
+
get_ability,
|
|
19
|
+
get_nature,
|
|
20
|
+
get_move,
|
|
21
|
+
get_item,
|
|
22
|
+
get_generation,
|
|
23
|
+
get_region,
|
|
24
|
+
get_all
|
|
25
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function filter_data(data, fields) {
|
|
2
|
+
if (fields.length == 0)
|
|
3
|
+
return data;
|
|
4
|
+
|
|
5
|
+
const filteredData = {};
|
|
6
|
+
for (const field of fields) {
|
|
7
|
+
if (data.hasOwnProperty(field)) {
|
|
8
|
+
filteredData[field] = data[field];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return filteredData;
|
|
13
|
+
}
|
package/src/utils/get.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fetch from "node-fetch";
|
|
2
|
+
|
|
3
|
+
const POKE_BASE_URL = 'https://pokeapi.co/api/v2'
|
|
4
|
+
const POGO_BASE_URL = 'https://pogoapi.net/api/v1/'
|
|
5
|
+
|
|
6
|
+
/** Gets data from the PokeAPI
|
|
7
|
+
* @param {String} endpoint
|
|
8
|
+
* @param {String} params
|
|
9
|
+
* @param {'POKE' | 'POGO'} api
|
|
10
|
+
* @returns {Promise<Object> | null} */
|
|
11
|
+
export default async function get(endpoint, params='', api='POKE') {
|
|
12
|
+
const BASE_URL = api == 'POKE' ? POKE_BASE_URL : POGO_BASE_URL
|
|
13
|
+
|
|
14
|
+
const URL = params ? `${BASE_URL}/${endpoint}?${params}` : `${BASE_URL}/${endpoint}`;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const res = await fetch(URL, { method: "GET" });
|
|
18
|
+
|
|
19
|
+
if (!res.ok) {
|
|
20
|
+
console.error(`HTTP error! Status: ${res.status}`);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return await res.json();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(error);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|