Skip to content

Commit

Permalink
multi: fix class function/remove semi-colons and trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Naramsim committed Dec 11, 2020
1 parent cba5f50 commit 1aee529
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 130 deletions.
92 changes: 46 additions & 46 deletions src/endpoints.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
exports.endpoints = [
["getBerryByName", "berry"],
["getBerryFirmnessByName", "berry-firmness"],
["getBerryFlavorByName", "berry-flavor"],
["getContestTypeByName", "contest-type"],
["getContestEffectById", "contest-effect"],
["getSuperContestEffectById", "super-contest-effect"],
["getEncounterMethodByName", "encounter-method"],
["getEncounterConditionByName", "encounter-condition"],
["getEncounterConditionValueByName", "encounter-condition-value"],
["getEvolutionChainById", "evolution-chain"],
["getEvolutionTriggerByName", "evolution-trigger"],
["getGenerationByName", "generation"],
["getPokedexByName", "pokedex"],
["getVersionByName", "version"],
["getVersionGroupByName", "version-group"],
["getItemByName", "item"],
["getItemAttributeByName", "item-attribute"],
["getItemCategoryByName", "item-category"],
["getItemFlingEffectByName", "item-fling-effect"],
["getItemPocketByName", "item-pocket"],
["getBerryByName", "berry"],
["getBerryFirmnessByName", "berry-firmness"],
["getBerryFlavorByName", "berry-flavor"],
["getContestTypeByName", "contest-type"],
["getContestEffectById", "contest-effect"],
["getSuperContestEffectById", "super-contest-effect"],
["getEncounterMethodByName", "encounter-method"],
["getEncounterConditionByName", "encounter-condition"],
["getEncounterConditionValueByName", "encounter-condition-value"],
["getEvolutionChainById", "evolution-chain"],
["getEvolutionTriggerByName", "evolution-trigger"],
["getGenerationByName", "generation"],
["getPokedexByName", "pokedex"],
["getVersionByName", "version"],
["getVersionGroupByName", "version-group"],
["getItemByName", "item"],
["getItemAttributeByName", "item-attribute"],
["getItemCategoryByName", "item-category"],
["getItemFlingEffectByName", "item-fling-effect"],
["getItemPocketByName", "item-pocket"],
["getMachineById", "machine"],
["getMoveByName", "move"],
["getMoveAilmentByName", "move-ailment"],
["getMoveBattleStyleByName", "move-battle-style"],
["getMoveCategoryByName", "move-category"],
["getMoveDamageClassByName", "move-damage-class"],
["getMoveLearnMethodByName", "move-learn-method"],
["getMoveTargetByName", "move-target"],
["getLocationByName", "location"],
["getLocationAreaByName", "location-area"],
["getPalParkAreaByName", "pal-park-area"],
["getRegionByName", "region"],
["getAbilityByName", "ability"],
["getCharacteristicById", "characteristic"],
["getEggGroupByName", "egg-group"],
["getGenderByName", "gender"],
["getGrowthRateByName", "growth-rate"],
["getNatureByName", "nature"],
["getPokeathlonStatByName", "pokeathlon-stat"],
["getPokemonByName", "pokemon"],
["getPokemonColorByName", "pokemon-color"],
["getPokemonFormByName", "pokemon-form"],
["getPokemonHabitatByName", "pokemon-habitat"],
["getPokemonShapeByName", "pokemon-shape"],
["getPokemonSpeciesByName", "pokemon-species"],
["getStatByName", "stat"],
["getTypeByName", "type"],
["getMoveByName", "move"],
["getMoveAilmentByName", "move-ailment"],
["getMoveBattleStyleByName", "move-battle-style"],
["getMoveCategoryByName", "move-category"],
["getMoveDamageClassByName", "move-damage-class"],
["getMoveLearnMethodByName", "move-learn-method"],
["getMoveTargetByName", "move-target"],
["getLocationByName", "location"],
["getLocationAreaByName", "location-area"],
["getPalParkAreaByName", "pal-park-area"],
["getRegionByName", "region"],
["getAbilityByName", "ability"],
["getCharacteristicById", "characteristic"],
["getEggGroupByName", "egg-group"],
["getGenderByName", "gender"],
["getGrowthRateByName", "growth-rate"],
["getNatureByName", "nature"],
["getPokeathlonStatByName", "pokeathlon-stat"],
["getPokemonByName", "pokemon"],
["getPokemonColorByName", "pokemon-color"],
["getPokemonFormByName", "pokemon-form"],
["getPokemonHabitatByName", "pokemon-habitat"],
["getPokemonShapeByName", "pokemon-shape"],
["getPokemonSpeciesByName", "pokemon-species"],
["getStatByName", "stat"],
["getTypeByName", "type"],
["getLanguageByName", "language"]
]
2 changes: 1 addition & 1 deletion src/error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exports.handleError = function (error, cb) {
if (cb) {
cb('Pokedex-promise-v2 error', error);
cb('Pokedex-promise-v2 error', error)
} else {
throw error
}
Expand Down
10 changes: 5 additions & 5 deletions src/getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ exports.getJSON = async (values, url, cb) => {
}
try {
// retrive possible content from memory-cache
const cachedResult = values.cache.get(url);
const cachedResult = values.cache.get(url)
if (cachedResult !== null) {
if (cb) {
// call callback without errors
cb(cachedResult, false);
cb(cachedResult, false)
}
return cachedResult
} else {
Expand All @@ -29,15 +29,15 @@ exports.getJSON = async (values, url, cb) => {
response = response.data

if (values.cacheLimit > 0) {
values.cache.put(url, response, values.cacheLimit);
values.cache.put(url, response, values.cacheLimit)
}

// if a callback is present
if (cb) {
// call it, without errors
cb(response, false);
cb(response, false)
} else {
return response;
return response
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const pMap = require('p-map');
const cache = require('memory-cache');
const pMap = require('p-map')
const cache = require('memory-cache')

const { endpoints } = require('./endpoints.js')
const { rootEndpoints } = require('./rootEndpoints.js')
Expand All @@ -18,14 +18,14 @@ class Pokedex {
try {
const mapper = async name => {
const queryRes = await getJSON(this.values, `${this.values.protocol}${this.values.hostName}${this.values.versionPath}${endpoint[1]}/${name}/`)
return queryRes;
};
return queryRes
}

if (input) {

// if the user has submitted a Name or an Id, return the Json promise
if (typeof input === 'number' || typeof input === 'string') {
return getJSON(this.values, `${this.values.protocol}${this.values.hostName}${this.values.versionPath}${endpoint[1]}/${input}/`, cb);
return getJSON(this.values, `${this.values.protocol}${this.values.hostName}${this.values.versionPath}${endpoint[1]}/${input}/`, cb)
}

// if the user has submitted an Array
Expand All @@ -34,16 +34,16 @@ class Pokedex {
// fetch data asynchronously to be faster
const mappedResults = await pMap(input, mapper, {concurrency: 4})
if (cb) {
cb(mappedResults);
cb(mappedResults)
}
return mappedResults;
return mappedResults
}
}
} catch (error) {
handleError(error, cb)
}
}
});
})

rootEndpoints.forEach(rootEndpoint => {
this[rootEndpoint[0]] = async (config, cb) => {
Expand All @@ -63,7 +63,7 @@ class Pokedex {
handleError(error, cb)
}
}
});
})
}

async resource(path, cb) {
Expand All @@ -72,7 +72,7 @@ class Pokedex {
if (typeof path === 'string') {
result = getJSON(this.values, path)
} else if (typeof path === 'object') {
result = Promise.all(path.map(p => getJSON(this.values, p)));
result = Promise.all(path.map(p => getJSON(this.values, p)))
} else {
throw 'String or Array required'
}
Expand All @@ -85,19 +85,19 @@ class Pokedex {
}
}

getConfig = function() {
getConfig() {
return this.values
}

cacheSize() {
// Retuns the current number of entries in the cache
return this.values.cache.size();
return this.values.cache.size()
}

clearCache() {
// Deletes all keys in cache
this.values.cache.clear();
};
};
this.values.cache.clear()
}
}

module.exports = Pokedex
94 changes: 47 additions & 47 deletions src/rootEndpoints.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
exports.rootEndpoints = [
["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/"],
["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/"]
]
32 changes: 16 additions & 16 deletions src/values.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
class Values {
constructor(config={}, cache) {
this.protocol = 'https';
this.hostName = '://pokeapi.co';
this.versionPath = '/api/v2/';
this.offset = 0;
this.limit = 100000;
this.timeout = 20 * 1000; // 20 seconds
this.cacheLimit = 1000000 * 1000; // 11 days
this.cache = cache;
this.protocol = 'https'
this.hostName = '://pokeapi.co'
this.versionPath = '/api/v2/'
this.offset = 0
this.limit = 100000
this.timeout = 20 * 1000 // 20 seconds
this.cacheLimit = 1000000 * 1000 // 11 days
this.cache = cache

if (config.hasOwnProperty("protocol")) {
this.protocol = config.protocol;
this.protocol = config.protocol
}
if (config.hasOwnProperty("hostName")) {
this.hostName = `://${config.hostName}`;
this.hostName = `://${config.hostName}`
}
if (config.hasOwnProperty("versionPath")) {
this.versionPath = config.versionPath;
this.versionPath = config.versionPath
}
if (config.hasOwnProperty("offset")) {
this.offset = config.offset - 1;
this.offset = config.offset - 1
}
if (config.hasOwnProperty("limit")) {
this.limit = config.limit;
this.limit = config.limit
}
if (config.hasOwnProperty("timeout")) {
this.timeout = config.timeout;
this.timeout = config.timeout
}
if (config.hasOwnProperty("cacheLimit")) {
this.cacheLimit = config.cacheLimit;
this.cacheLimit = config.cacheLimit
}
}
}

exports.Values = Values;
exports.Values = Values

0 comments on commit 1aee529

Please sign in to comment.