Skip to content

Commit b21c89f

Browse files
committed
feat: add locationEncounterAreas/duplicate exposed endpoint functions
1 parent c51d74e commit b21c89f

4 files changed

Lines changed: 84 additions & 57 deletions

File tree

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/endpoints.json

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
[
2-
["getBerryByName", "berry"],
3-
["getBerryFirmnessByName", "berry-firmness"],
4-
["getBerryFlavorByName", "berry-flavor"],
5-
["getContestTypeByName", "contest-type"],
6-
["getContestEffectById", "contest-effect"],
7-
["getSuperContestEffectById", "super-contest-effect"],
8-
["getEncounterMethodByName", "encounter-method"],
9-
["getEncounterConditionByName", "encounter-condition"],
10-
["getEncounterConditionValueByName", "encounter-condition-value"],
11-
["getEvolutionChainById", "evolution-chain"],
12-
["getEvolutionTriggerByName", "evolution-trigger"],
13-
["getGenerationByName", "generation"],
14-
["getPokedexByName", "pokedex"],
15-
["getVersionByName", "version"],
16-
["getVersionGroupByName", "version-group"],
17-
["getItemByName", "item"],
18-
["getItemAttributeByName", "item-attribute"],
19-
["getItemCategoryByName", "item-category"],
20-
["getItemFlingEffectByName", "item-fling-effect"],
21-
["getItemPocketByName", "item-pocket"],
22-
["getMachineById", "machine"],
23-
["getMoveByName", "move"],
24-
["getMoveAilmentByName", "move-ailment"],
25-
["getMoveBattleStyleByName", "move-battle-style"],
26-
["getMoveCategoryByName", "move-category"],
27-
["getMoveDamageClassByName", "move-damage-class"],
28-
["getMoveLearnMethodByName", "move-learn-method"],
29-
["getMoveTargetByName", "move-target"],
30-
["getLocationByName", "location"],
31-
["getLocationAreaByName", "location-area"],
32-
["getPalParkAreaByName", "pal-park-area"],
33-
["getRegionByName", "region"],
34-
["getAbilityByName", "ability"],
35-
["getCharacteristicById", "characteristic"],
36-
["getEggGroupByName", "egg-group"],
37-
["getGenderByName", "gender"],
38-
["getGrowthRateByName", "growth-rate"],
39-
["getNatureByName", "nature"],
40-
["getPokeathlonStatByName", "pokeathlon-stat"],
41-
["getPokemonByName", "pokemon"],
42-
["getPokemonColorByName", "pokemon-color"],
43-
["getPokemonFormByName", "pokemon-form"],
44-
["getPokemonHabitatByName", "pokemon-habitat"],
45-
["getPokemonShapeByName", "pokemon-shape"],
46-
["getPokemonSpeciesByName", "pokemon-species"],
47-
["getStatByName", "stat"],
48-
["getTypeByName", "type"],
49-
["getLanguageByName", "language"]
2+
["getBerry", "name", "/berry/:id/"],
3+
["getBerryFirmness", "name", "/berry-firmness/:id/"],
4+
["getBerryFlavor", "name", "/berry-flavor/:id/"],
5+
["getContestType", "name", "/contest-type/:id/"],
6+
["getContestEffect", "id", "/contest-effect/:id/"],
7+
["getSuperContestEffect", "id", "/super-contest-effect/:id/"],
8+
["getEncounterMethod", "name", "/encounter-method/:id/"],
9+
["getEncounterCondition", "name", "/encounter-condition/:id/"],
10+
["getEncounterConditionValue", "name", "/encounter-condition-value/:id/"],
11+
["getEvolutionChain", "id", "/evolution-chain/:id/"],
12+
["getEvolutionTrigger", "name", "/evolution-trigger/:id/"],
13+
["getGeneration", "name", "/generation/:id/"],
14+
["getPokedex", "name", "/pokedex/:id/"],
15+
["getVersion", "name", "/version/:id/"],
16+
["getVersionGroup", "name", "/version-group/:id/"],
17+
["getItem", "name", "/item/:id/"],
18+
["getItemAttribute", "name", "/item-attribute/:id/"],
19+
["getItemCategory", "name", "/item-category/:id/"],
20+
["getItemFlingEffect", "name", "/item-fling-effect/:id/"],
21+
["getItemPocket", "name", "/item-pocket/:id/"],
22+
["getMachine", "id", "/machine/:id/"],
23+
["getMove", "name", "/move/:id/"],
24+
["getMoveAilment", "name", "/move-ailment/:id/"],
25+
["getMoveBattleStyle", "name", "/move-battle-style/:id/"],
26+
["getMoveCategory", "name", "/move-category/:id/"],
27+
["getMoveDamageClass", "name", "/move-damage-class/:id/"],
28+
["getMoveLearnMethod", "name", "/move-learn-method/:id/"],
29+
["getMoveTarget", "name", "/move-target/:id/"],
30+
["getLocation", "name", "/location/:id/"],
31+
["getLocationArea", "name", "/location-area/:id/"],
32+
["getPalParkArea", "name", "/pal-park-area/:id/"],
33+
["getRegion", "name", "/region/:id/"],
34+
["getAbility", "name", "/ability/:id/"],
35+
["getCharacteristic", "id", "/characteristic/:id/"],
36+
["getEggGroup", "name", "/egg-group/:id/"],
37+
["getGender", "name", "/gender/:id/"],
38+
["getGrowthRate", "name", "/growth-rate/:id/"],
39+
["getNature", "name", "/nature/:id/"],
40+
["getPokeathlonStat", "name", "/pokeathlon-stat/:id/"],
41+
["getPokemon", "name", "/pokemon/:id/"],
42+
["getPokemonEncounterAreas", "name", "/pokemon/:id/encounters/"],
43+
["getPokemonColor", "name", "/pokemon-color/:id/"],
44+
["getPokemonForm", "name", "/pokemon-form/:id/"],
45+
["getPokemonHabitat", "name", "/pokemon-habitat/:id/"],
46+
["getPokemonShape", "name", "/pokemon-shape/:id/"],
47+
["getPokemonSpecies", "name", "/pokemon-species/:id/"],
48+
["getStat", "name", "/stat/:id/"],
49+
["getType", "name", "/type/:id/"],
50+
["getLanguage", "name", "/language/:id/"]
5051
]

src/index.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ export class Pokedex {
1717

1818
// add to Pokedex.prototype all our endpoint functions
1919
endpoints.forEach(endpoint => {
20-
this[endpoint[0]] = input => {
20+
const endpointFullName = buildEndpointFullName(endpoint)
21+
this[endpointFullName] = input => {
2122
if (input) {
2223

2324
// if the user has submitted a Name or an ID, return the JSON promise
2425
if (typeof input === 'number' || typeof input === 'string') {
25-
return loadResource(this.config, `${this.config.versionPath}${endpoint[1]}/${input}/`)
26+
return loadResource(this.config, `${this.config.versionPath}${endpoint[2].replace(':id', input)}`)
2627
}
27-
28+
2829
// if the user has submitted an Array
2930
// return a new promise which will resolve when all loadResource calls are ended
3031
else if (typeof input === 'object') {
3132
return Promise.all(mapResources(this.config, endpoint, input))
3233
}
3334
}
3435
}
36+
this[buildEndpointName(endpoint)] = this[endpointFullName]
3537
})
3638

3739
rootEndpoints.forEach(rootEndpoint => {
@@ -78,8 +80,20 @@ export class Pokedex {
7880
}
7981
}
8082

81-
function mapResources(config, endpoint, input) {
82-
return input.map(res => {
83-
return loadResource(config, `${config.versionPath}${endpoint[1]}/${res}/`)
83+
function mapResources(config, endpoint, inputs) {
84+
return inputs.map(input => {
85+
return loadResource(config, `${config.versionPath}${endpoint[2].replace(':id', input)}`)
8486
})
85-
}
87+
}
88+
89+
function buildEndpointFullName(endpoint) {
90+
return `${endpoint[0]}By${capitalize(endpoint[1])}`
91+
}
92+
93+
function buildEndpointName(endpoint) {
94+
return `${endpoint[0]}}`
95+
}
96+
97+
function capitalize([first,...rest]) {
98+
return first.toUpperCase() + rest.join('').toLowerCase()
99+
}

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ describe("pokedex", function () {
113113
});
114114
});
115115

116+
describe(".getPokemonEncounterAreasByName(Id: int)", function () {
117+
before(function () {
118+
promise = secureP.getPokemonEncounterAreasByName(id);
119+
});
120+
it("should succeed", function () {
121+
return promise;
122+
});
123+
it("should be an array", function () {
124+
return expect(promise).to.eventually.be.an("array");
125+
});
126+
});
127+
116128
describe(".getVersionByName(Id: int)", function () {
117129
before(function () {
118130
promise = secureP.getVersionByName(id);

0 commit comments

Comments
 (0)