@blizzard-api/hs
Version:
A series of helpers to interact with the Hearthstone Blizzard API
157 lines (121 loc) • 3.71 kB
JavaScript
//#region src/card-backs/card-backs.ts
/**
* Returns a list of card backs based on the search parameters provided.
* @param options The options for fetching card backs. See {@link CardBackSearchParameters}.
* @returns The card back search resource. See {@link CardBackSearchResponse}.
*/
function cardBackSearch(options) {
return {
parameters: options,
path: "hearthstone/cardbacks"
};
}
/**
* Returns a single card back based on the ID provided.
* @param id The card back ID
* @param locale The locale to use for fetching the card back (optional).
* @returns The card back resource. See {@link SingleCardBackSearchResponse}.
*/
function fetchOneCardBack(id, locale) {
return {
parameters: { locale },
path: `hearthstone/cardbacks/${id}`
};
}
//#endregion
//#region src/cards/cards.ts
/**
* Returns a list of cards based on the search parameters provided.
* @param options The options for fetching cards. See {@link CardSearchParameters}.
* @returns The card search resource. See {@link CardSearchResponse}.
*/
function cardSearch(options) {
let attack = void 0;
let defaultMercenary = void 0;
let health = void 0;
let mercenaryId = void 0;
if (options.attack) attack = Array.isArray(options.attack) ? options.attack.join(",") : `${options.attack}`;
if (options.defaultMercenary) defaultMercenary = Array.isArray(options.defaultMercenary) ? options.defaultMercenary.join(",") : `${options.defaultMercenary}`;
if (options.health) health = Array.isArray(options.health) ? options.health.join(",") : `${options.health}`;
if (options.mercenaryId) mercenaryId = Array.isArray(options.mercenaryId) ? options.mercenaryId.join(",") : `${options.mercenaryId}`;
return {
parameters: {
...options,
attack,
defaultMercenary,
health,
mercenaryId
},
path: "hearthstone/cards"
};
}
/**
* Returns a single card based on the ID provided.
* @param id The card ID
* @param options The options for fetching a card.
* @param options.gameMode The game mode to use for fetching the card (optional).
* @param options.locale The locale to use for fetching the card (optional).
* @returns The card resource. See {@link FetchOneCardResponse}.
*/
function fetchOneCard(id, options) {
const { gameMode = "constructed", locale } = options ?? {};
return {
parameters: {
gameMode,
locale
},
path: `hearthstone/cards/${id}`
};
}
//#endregion
//#region src/decks/decks.ts
/**
* Returns a deck based on the code provided.
* @param options The options for fetching a deck.
* @returns The deck resource. See {@link DeckResponse}.
*/
function getDeck(options) {
if ("code" in options) return {
parameters: { code: encodeURI(options.code) },
path: "hearthstone/deck"
};
return {
parameters: {
hero: options.hero,
ids: options.ids?.join(",")
},
path: "hearthstone/deck"
};
}
//#endregion
//#region src/metadata/metadata.ts
/**
* Returns all metadata
* @returns The all metadata resource. See {@link AllMetadataResponse}.
*/
function allMetadata() {
return { path: "hearthstone/metadata" };
}
/**
* Returns specific metadata based on the type requested.
* @param type The type of metadata to retrieve.
* @returns The specific metadata resource. See {@link SpecificMetadataResponse}.
*/
function specificMetadata(type) {
return { path: `hearthstone/metadata/${type}` };
}
//#endregion
//#region src/index.ts
const hs = {
cardBackSearch,
fetchOneCardBack,
cardSearch,
fetchOneCard,
getDeck,
allMetadata,
specificMetadata
};
var src_default = hs;
//#endregion
export { allMetadata, cardBackSearch, cardSearch, src_default as default, fetchOneCard, fetchOneCardBack, getDeck, hs, specificMetadata };
//# sourceMappingURL=index.js.map