pokedex-promise-v2
Version:
A library used to get information about Pokemons.
889 lines • 113 kB
JavaScript
/* eslint-disable */
/*
* DO NOT MODIFY, THIS IS AUTO GENERATED
* Execute `npm run generate` to regenerate
*/
import pMap from "p-map";
import NodeCache from "node-cache";
import PokeAPIOptions from "./interfaces/PokeAPIOptions.js";
import handleError from "./utils/ErrorHandler.js";
import getJSON from "./utils/Getter.js";
export default class Pokedex {
constructor(options) {
this.options = new PokeAPIOptions(options, new NodeCache());
}
async getResource(endpoint, callback) {
try {
// Fail if the endpoint is not supplied
if (!endpoint) {
throw new Error('Param "endpoint" is required and must be a string or array of strings');
}
// Fail if the input types aren't accepted
if (!Array.isArray(endpoint) && typeof endpoint !== 'string') {
throw new Error('Param "endpoint" needs to be a string or array of strings');
}
// If the user has submitted a string, return the JSON promise
if (typeof endpoint === 'string') {
return getJSON(this.options, endpoint, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (endpoints) => getJSON(this.options, endpoints);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(endpoint, mapper, { concurrency: 4 });
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
/** @deprecated - will be removed on the next version. Use {@link getResource} instead */
async resource(endpoint, callback) {
try {
// Fail if the endpoint is not supplied
if (!endpoint) {
throw new Error('Param "endpoint" is required and must be a string or array of strings');
}
// Fail if the input types aren't accepted
if (!Array.isArray(endpoint) && typeof endpoint !== 'string') {
throw new Error('Param "endpoint" needs to be a string or array of strings');
}
// If the user has submitted a string, return the JSON promise
if (typeof endpoint === 'string') {
return getJSON(this.options, endpoint, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (endpoints) => getJSON(this.options, endpoints);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(endpoint, mapper, { concurrency: 4 });
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getBerryByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getBerryFirmnessByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry-firmness/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry-firmness/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getBerryFlavorByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry-flavor/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry-flavor/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getContestTypeByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}contest-type/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}contest-type/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getContestEffectById(id, callback) {
try {
// Fail if the param is not supplied
if (!id) {
throw new Error('Param "id" is required (Must be a number or array of numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(id) && typeof id !== 'number' && typeof id !== 'string') {
throw new Error('Param "id" must be a number or array of numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof id === 'number' || typeof id === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}contest-effect/${id}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (ids) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}contest-effect/${ids}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(id, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getSuperContestEffectById(id, callback) {
try {
// Fail if the param is not supplied
if (!id) {
throw new Error('Param "id" is required (Must be a number or array of numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(id) && typeof id !== 'number' && typeof id !== 'string') {
throw new Error('Param "id" must be a number or array of numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof id === 'number' || typeof id === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}super-contest-effect/${id}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (ids) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}super-contest-effect/${ids}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(id, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getEncounterMethodByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-method/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-method/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getEncounterConditionByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-condition/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-condition/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getEncounterConditionValueByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-condition-value/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-condition-value/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getEvolutionChainById(id, callback) {
try {
// Fail if the param is not supplied
if (!id) {
throw new Error('Param "id" is required (Must be a number or array of numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(id) && typeof id !== 'number' && typeof id !== 'string') {
throw new Error('Param "id" must be a number or array of numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof id === 'number' || typeof id === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}evolution-chain/${id}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (ids) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}evolution-chain/${ids}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(id, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getEvolutionTriggerByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}evolution-trigger/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}evolution-trigger/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getGenerationByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}generation/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}generation/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getPokedexByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}pokedex/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}pokedex/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getVersionByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}version/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}version/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getVersionGroupByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}version-group/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}version-group/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getItemByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getItemAttributeByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-attribute/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-attribute/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getItemCategoryByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-category/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-category/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getItemFlingEffectByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-fling-effect/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-fling-effect/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getItemPocketByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-pocket/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-pocket/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMachineById(id, callback) {
try {
// Fail if the param is not supplied
if (!id) {
throw new Error('Param "id" is required (Must be a number or array of numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(id) && typeof id !== 'number' && typeof id !== 'string') {
throw new Error('Param "id" must be a number or array of numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof id === 'number' || typeof id === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}machine/${id}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (ids) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}machine/${ids}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(id, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMoveByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMoveAilmentByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-ailment/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-ailment/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMoveBattleStyleByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-battle-style/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-battle-style/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMoveCategoryByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-category/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-category/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMoveDamageClassByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-damage-class/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-damage-class/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMoveLearnMethodByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-learn-method/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-learn-method/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getMoveTargetByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-target/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-target/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getLocationByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'string') {
throw new Error('Param "nameOrId" must be a string, array of strings or array of string and/or numbers');
}
// If the user has submitted a Name or an ID, return the JSON promise
if (typeof nameOrId === 'number' || typeof nameOrId === 'string') {
return getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}location/${nameOrId}/`, callback);
}
// If the user has submitted an Array return a new promise which will resolve when all getJSON calls are ended
const mapper = (nameOrIds) => getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}location/${nameOrIds}/`);
// Fetch data asynchronously to be faster
const mappedResults = await pMap(nameOrId, mapper, { concurrency: 4 });
// Invoke the callback if we have one
if (callback) {
callback(mappedResults);
}
return mappedResults;
}
catch (error) {
handleError(error, callback);
}
}
async getLocationAreaByName(nameOrId, callback) {
try {
// Fail if the param is not supplied
if (!nameOrId) {
throw new Error('Param "nameOrId" is required (Must be a string, array of strings or array of string and/or numbers )');
}
// Fail if the input types aren't accepted
if (!Array.isArray(nameOrId) && typeof nameOrId !== 'number' && typeof nameOrId !== 'stri