+6
-0
@@ -20,2 +20,4 @@ import { defaultEndpoints, subwayRouteColors } from "./src/defaults"; | ||
| SubwayArrivalQuery, | ||
| SubwayDirectionQuery, | ||
| SubwayDirectionResolution, | ||
| TransitMode, | ||
@@ -137,2 +139,6 @@ Vehicle, | ||
| direction(query: SubwayDirectionQuery): Promise<SubwayDirectionResolution> { | ||
| return this.mta.hostedJson<SubwayDirectionResolution>("/api/v1/subway/direction", query); | ||
| } | ||
| private feedForRoute(route: string) { | ||
@@ -139,0 +145,0 @@ const feed = this.mta.endpoints.subwayFeeds[route]; |
+1
-1
| { | ||
| "name": "mta-js", | ||
| "version": "2.1.1", | ||
| "version": "2.2.0", | ||
| "description": "A TypeScript client for MTA realtime feeds and the hosted MTA API.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+18
-11
@@ -29,21 +29,27 @@ # mta-js | ||
| }); | ||
| const direction = await mta.subway.direction({ | ||
| route: "L", | ||
| fromStopId: "L06", | ||
| destination: "Union Sq", | ||
| }); | ||
| ``` | ||
| Arrival rows include display-oriented fields when destination metadata is | ||
| available: | ||
| Arrival rows may include display-oriented fields. `destination` depends on | ||
| destination metadata, while `displayDirection` may still be present as a | ||
| generic fallback label: | ||
| ```ts | ||
| for (const arrival of lTrain) { | ||
| const direction = | ||
| arrival.displayDirection ?? | ||
| (arrival.destination | ||
| ? `toward ${arrival.destination}` | ||
| : arrival.headsign | ||
| ? `toward ${arrival.headsign}` | ||
| : arrival.direction); | ||
| console.log(`${arrival.route.shortName} ${direction} from ${arrival.stop.name}`); | ||
| console.log( | ||
| `${arrival.route.shortName} ${arrival.displayDirection} from ${arrival.stop.displayName}`, | ||
| ); | ||
| } | ||
| ``` | ||
| Use `mta.subway.direction(...)` when a rider enters an intermediate destination | ||
| such as `Union Sq`; the hosted API resolves it against static GTFS route order | ||
| and returns a typed `direction`, `destinationStop`, and terminal-facing | ||
| `displayDirection` such as `toward 8 Av`. | ||
| NYC Subway realtime feeds use NYCT's `north`/`south` stop directions, even on | ||
@@ -113,2 +119,3 @@ east-west lines. For the L train, `mta-js` accepts rider-facing `east`/`west` | ||
| - `mta.subway.arrivals(...)` | ||
| - `mta.subway.direction(...)` | ||
| - `mta.bus.arrivals(...)` | ||
@@ -115,0 +122,0 @@ - `mta.bus.vehicles(...)` |
+33
-1
@@ -24,3 +24,6 @@ import type { | ||
| export type Direction = "north" | "south" | "east" | "west" | "unknown"; | ||
| export type SubwayResolvedDirection = "north" | "south"; | ||
| export type DirectionHeadsigns = Record<string, string[]>; | ||
| export interface MTAOptions { | ||
@@ -135,13 +138,22 @@ apiKey?: string; | ||
| name: string; | ||
| displayName?: string; | ||
| lat?: number; | ||
| lon?: number; | ||
| parentStation?: string; | ||
| parentId?: string; | ||
| mode?: TransitMode; | ||
| } | ||
| export type ServedRoute = Route & { | ||
| headsigns?: string[]; | ||
| directionHeadsigns?: DirectionHeadsigns; | ||
| directions?: number[]; | ||
| }; | ||
| export type NearbyStop = Stop & { | ||
| distanceMeters?: number; | ||
| servedRoutes?: Route[]; | ||
| servedRoutes?: ServedRoute[]; | ||
| routeMatch?: boolean; | ||
| routeHeadsigns?: string[]; | ||
| directionHeadsigns?: DirectionHeadsigns; | ||
| note?: string; | ||
@@ -205,2 +217,22 @@ }; | ||
| export interface SubwayDirectionQuery { | ||
| route: SubwayRoute; | ||
| fromStopId: SubwayStopId; | ||
| destination: string; | ||
| } | ||
| export interface SubwayDirectionResolution { | ||
| route: Route; | ||
| destination: string; | ||
| normalizedDestination: string; | ||
| resolved: boolean; | ||
| direction?: SubwayResolvedDirection; | ||
| displayDirection?: string; | ||
| terminal?: string; | ||
| fromStop?: Stop; | ||
| destinationStop?: Stop; | ||
| matches?: Stop[]; | ||
| reason?: string; | ||
| } | ||
| export interface BusArrivalQuery { | ||
@@ -207,0 +239,0 @@ stopId: BusStopId; |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
140415
0.95%8912
0.37%123
6.03%