UNPKG

@azurapi/azurapi

Version:

Open Source Azur Lane Local Database

89 lines 3.31 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Barrages = void 0; const api_1 = __importStar(require("./api")); /** * Special barrage class for extended functionality */ class Barrages extends api_1.default { /** * Constructor * @param client An AzurAPI instance */ constructor(client) { super(client, ['id', 'name']); } /** * Get by id * @param id String of number */ id(id) { for (let item of this.raw) if (api_1.normalize(item.id.toUpperCase()) === api_1.normalize(id.toUpperCase())) return item; return undefined; } /** * Get barrage by name * @param name Barrage name */ name(name) { return this.raw.filter(barrage => api_1.normalize(barrage.name.toUpperCase()) === api_1.normalize(name.toUpperCase())); } /** * Get barrage by type * @param type Barrage type */ type(type) { return this.raw.filter(barrage => api_1.normalize(barrage.type.toUpperCase()) === api_1.normalize(type.toUpperCase())); } /** * Get barrage by hull type * @param hull Hull type */ hull(hull) { return this.raw.filter(barrage => api_1.normalize(barrage.hull.toUpperCase()) === api_1.normalize(hull.toUpperCase())); } /** * Sort barrages by compatable ship * @param ship A ship name */ ships(ship) { return this.raw.filter(barrage => barrage.ships.map(ship => api_1.normalize(ship.toUpperCase())).includes(api_1.normalize(ship.toUpperCase()))); } get(query) { if (this.client.queryIsShipName(query)) { // Get barrages with this ship in it's `ships` array. return this.raw.filter(r => { // TODO: On api initialization, pre-uppercase and normalize ship names and overwrite (or store as memoized) so every search doesnt loop over the array const comparisonArr = r.ships.map(s => s.toUpperCase()); if (comparisonArr.indexOf(query.toUpperCase()) !== -1) { // Faster than `.includes` return true; } return false; }); } return this.fuze(query).map(s => s.item); } } exports.Barrages = Barrages; //# sourceMappingURL=api_barrage.js.map