UNPKG

gatelogue-types

Version:

Types for loading and reading Gatelogue data

130 lines 3.83 kB
/** * # Usage * The data can be imported into your JavaScript/TypeScript project with classes and type definitions. * * retrieving from npmjs.com: * * npm: `npm i gatelogue-types` * * yarn: `yarn add gatelogue-types` * * pnpm: `pnpm add gatelogue-types` * * denoL `deno add npm:gatelogue-types` * * bun: `bun add gatelogue-types` * * retrieving from jsr.io: * * npm: `npx jsr add @mrt-map/gatelogue-types` * * yarn: `yarn add jsr:@mrt-map/gatelogue-types` * * pnpm: `pnpm i jsr:@mrt-map/gatelogue-types` * * deno: `deno add jsr:@mrt-map/gatelogue-types` * * bun: `bunx jsr add @mrt-map/gatelogue-types` * * To import directly from the repository: * * npm: `npm i 'https://gitpkg.vercel.app/mrt-map/gatelogue/gatelogue-types-ts?main'` * * yarn: `yarn add 'https://gitpkg.vercel.app/mrt-map/gatelogue/gatelogue-types-ts?main'` * * pnpm: `pnpm add mrt-map/gatelogue#path:/gatelogue-types-ts` * * bun: `bun add 'git+https://gitpkg.vercel.app/mrt-map/gatelogue/gatelogue-types-ts?main'` * * To retrieve the data: * @example * ```ts * import { GD } from "gatelogue-types"; * await GD.get() // retrieve data, with sources * await GD.getNoSources() // retrieve data, no sources * ``` * * @packageDocumentation */ // noinspection JSUnusedGlobalSymbols export class GD { data; constructor(data) { this.data = data; } static async get() { return new GD(await fetch("https://raw.githubusercontent.com/MRT-Map/gatelogue/dist/data.json").then((res) => res.json())); } static async getNoSources() { return new GD(await fetch("https://raw.githubusercontent.com/MRT-Map/gatelogue/dist/data_no_sources.json").then((res) => res.json())); } node(id) { return this.data.nodes[id]; } get nodes() { return Object.values(this.data.nodes); } airFlight(id) { return this.node(id); } get airFlights() { return this.nodes.filter((a) => a.type === "AirFlight"); } airAirport(id) { return this.node(id); } get airAirports() { return this.nodes.filter((a) => a.type === "AirAirport"); } airGate(id) { return this.node(id); } get airGates() { return this.nodes.filter((a) => a.type === "AirGate"); } airAirline(id) { return this.node(id); } get airAirlines() { return this.nodes.filter((a) => a.type === "AirAirline"); } railCompany(id) { return this.node(id); } get railCompanies() { return this.nodes.filter((a) => a.type === "RailCompany"); } railLine(id) { return this.node(id); } get railLines() { return this.nodes.filter((a) => a.type === "RailLine"); } railStation(id) { return this.node(id); } get railStations() { return this.nodes.filter((a) => a.type === "RailStation"); } seaCompany(id) { return this.node(id); } get seaCompanies() { return this.nodes.filter((a) => a.type === "SeaCompany"); } seaLine(id) { return this.node(id); } get seaLines() { return this.nodes.filter((a) => a.type === "SeaLine"); } seaStop(id) { return this.node(id); } get seaStops() { return this.nodes.filter((a) => a.type === "SeaStop"); } busCompany(id) { return this.node(id); } get busCompanies() { return this.nodes.filter((a) => a.type === "BusCompany"); } busLine(id) { return this.node(id); } get busLines() { return this.nodes.filter((a) => a.type === "BusLine"); } busStop(id) { return this.node(id); } get busStops() { return this.nodes.filter((a) => a.type === "BusStop"); } } //# sourceMappingURL=lib.js.map