UNPKG

pokedex-promise-v2

Version:

A library used to get information about Pokemons.

926 lines (925 loc) 119 kB
/* 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 needs to 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 = async (endpoints) => { const queryRes = await getJSON(this.options, endpoints); return queryRes; }; // 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 needs to 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 = async (endpoints) => { const queryRes = await getJSON(this.options, endpoints); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry-firmness/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}berry-flavor/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}contest-type/${nameOrIds}/`); return queryRes; }; // 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 = async (ids) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}contest-effect/${ids}/`); return queryRes; }; // 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 = async (ids) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}super-contest-effect/${ids}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-method/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-condition/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}encounter-condition-value/${nameOrIds}/`); return queryRes; }; // 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 = async (ids) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}evolution-chain/${ids}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}evolution-trigger/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}generation/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}pokedex/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}version/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}version-group/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-attribute/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-category/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-fling-effect/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}item-pocket/${nameOrIds}/`); return queryRes; }; // 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 = async (ids) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}machine/${ids}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-ailment/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-battle-style/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-category/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-damage-class/${nameOrIds}/`); return queryRes; }; // 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 = async (nameOrIds) => { const queryRes = await getJSON(this.options, `${this.options.protocol}${this.options.hostName}${this.options.versionPath}move-learn-method/${nameOrIds}/`); return queryRes; }; // 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);