UNPKG

@spasea/uz-booking-client

Version:
45 lines (44 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const stations_1 = require("../assets/stations/stations"); class Station { /** * Construct station class. * @param {string} [lang] - language * @param {auth} [auth] - the credentials to authenticate to UzBoojking. If auth is * not provided requests will be made unauthenticated * @param {string} [apiBase] - the base UzBooking API URL */ constructor(lang, auth, apiBase) { // super(lang, auth, apiBase); this.lang = lang; } /** * Find station by name * @param {string} stationName - the name of station * @param {Function} callback - callback function * @returns {Promise} - the promise for the http request */ // tslint:disable-next-line find(stationName, callback) { const filteredStations = []; for (const property in stations_1.default) { if (Object.prototype.hasOwnProperty.call(stations_1.default, property)) { if (stations_1.default[property][this.lang] && stations_1.default[property][this.lang].title .toLowerCase() .startsWith(stationName.toLowerCase())) { filteredStations.push({ title: stations_1.default[property][this.lang].title, value: property, }); } } } if (callback) { return callback(null, { data: filteredStations }); } return Promise.resolve({ data: filteredStations }); } } exports.default = Station;