UNPKG

gtfs-to-html

Version:

Build human readable transit timetables as HTML, PDF or CSV from GTFS

214 lines 7.26 kB
import { ConfigAgency, Frequency, GtfsError, GtfsErrorCategory, GtfsErrorCode, GtfsWarning, GtfsWarningCode, ImportReport, Route, Stop, StopTime, Timetable, TimetablePage, Trip, formatGtfsError, isGtfsError, isGtfsValidationError } from "gtfs"; //#region src/types/config.d.ts interface Config { agencies: ConfigAgency[]; assetPath?: string; sqlitePath?: string; allowEmptyTimetables?: boolean; beautify?: boolean; coordinatePrecision?: number; dateFormat?: string; daysShortStrings?: string[]; daysStrings?: string[]; defaultOrientation?: string; deleteDbAfter?: boolean; effectiveDate?: string; endDate?: string; groupTimetablesIntoPages?: boolean; gtfsToHtmlVersion?: string; hasGtfsRealtimeVehiclePositions?: boolean; hasGtfsRealtimeTripUpdates?: boolean; hasGtfsRealtimeAlerts?: boolean; interpolatedStopSymbol?: string; interpolatedStopText?: string; linkStopUrls?: boolean; mapStyleUrl?: string; menuType?: 'none' | 'simple' | 'jump' | 'radio'; noDropoffSymbol?: string; noDropoffText?: string; noHead?: boolean; noPickupSymbol?: string; noPickupText?: string; noRegularServiceDaysText?: string; noServiceSymbol?: string; noServiceText?: string; outputFormat?: 'html' | 'pdf' | 'csv'; overwriteExistingFiles?: boolean; outputPath?: string; requestDropoffSymbol?: string; requestDropoffText?: string; requestPickupSymbol?: string; requestPickupText?: string; serviceNotProvidedOnText?: string; serviceProvidedOnText?: string; showArrivalOnDifference?: number; showCalendarExceptions?: boolean; showDuplicateTrips?: boolean; showMap?: boolean; showOnlyTimepoint?: boolean; showRouteTitle?: boolean; showStopCity?: boolean; showStopDescription?: boolean; showStoptimesForRequestStops?: boolean; skipImport?: boolean; sortingAlgorithm?: string; startDate?: string; templatePath?: string; timeFormat?: string; useParentStation?: boolean; verbose?: boolean; zipOutput?: boolean; logFunction?: (text: string) => void; } //#endregion //#region src/types/stoptime.d.ts type FormattedStopTime = Omit<StopTime, 'stop_sequence'> & { stop_sequence: number | null; id?: string | number | null; type?: 'arrival' | 'departure'; classes?: string[]; formatted_time?: string; noPickup?: boolean; requestPickup?: boolean; noDropoff?: boolean; requestDropoff?: boolean; interpolated?: boolean; skipped?: boolean; _id?: unknown; }; //#endregion //#region src/types/trip.d.ts interface BlockTrip extends Pick<Trip, 'trip_id' | 'route_id'> { firstStoptime?: FormattedStopTime; lastStoptime?: FormattedStopTime; route?: Route; } interface FormattedTrip extends Trip { stoptimes: FormattedStopTime[]; firstStoptime?: number; lastStoptime?: number; additional_service_ids?: string[]; dayList?: string; dayListLong?: string; route_short_name?: string | null; continues_from_route?: BlockTrip; continues_as_route?: BlockTrip; } //#endregion //#region src/types/stop.d.ts interface FormattedStop extends Stop { type?: 'arrival' | 'departure'; trips: FormattedStopTime[]; hourlyTimes?: string[]; is_timepoint?: boolean; stop_city?: string | null; } //#endregion //#region src/types/timetable.d.ts interface FormattedTimetable extends Timetable { route_ids: string[]; trip_ids: string[]; routes: Route[]; orderedTrips: FormattedTrip[]; stops: FormattedStop[]; service_ids?: string[]; warnings?: string[]; has_continues_as_route?: boolean; has_continues_from_route?: boolean; dayList?: string; dayListLong?: string; calendarDates?: { excludedDates: string[]; includedDates: string[]; }; notes?: unknown[]; geojson?: unknown; frequencies?: Frequency[]; frequencyExactTimes?: boolean; noServiceSymbolUsed?: boolean; requestDropoffSymbolUsed?: boolean; noDropoffSymbolUsed?: boolean; requestPickupSymbolUsed?: boolean; noPickupSymbolUsed?: boolean; interpolatedStopSymbolUsed?: boolean; showStopCity?: boolean; showStopDescription?: boolean; noServiceSymbol?: string | null; requestDropoffSymbol?: string | null; noDropoffSymbol?: string | null; requestPickupSymbol?: string | null; noPickupSymbol?: string | null; interpolatedStopSymbol?: string | null; } //#endregion //#region src/types/timetable-page.d.ts interface FormattedTimetablePage extends Omit<TimetablePage, 'timetable_page_label' | 'filename'> { timetable_page_label?: string | null; filename?: string | null; timetables: FormattedTimetable[]; routes: Route[]; relativePath?: string; consolidatedTimetables?: FormattedTimetable[]; dayList?: string; dayLists?: (string | undefined)[]; route_ids?: string[]; agency_ids?: string[]; } //#endregion //#region src/lib/gtfs-to-html.d.ts declare const gtfsToHtml: (initialConfig: Config) => Promise<string>; //#endregion //#region src/lib/errors.d.ts declare enum GtfsToHtmlErrorCategory { CONFIG = "config", DATABASE = "database", GTFS = "gtfs", FILE_SYSTEM = "file_system", TEMPLATE = "template", QUERY = "query", VALIDATION = "validation", INTERNAL = "internal" } /** * Error codes are a public API contract and should remain stable. */ declare enum GtfsToHtmlErrorCode { CONFIG_INVALID = "GTFS_TO_HTML_CONFIG_INVALID", CONFIG_FILE_NOT_FOUND = "GTFS_TO_HTML_CONFIG_FILE_NOT_FOUND", CONFIG_PARSE_FAILED = "GTFS_TO_HTML_CONFIG_PARSE_FAILED", CONFIG_DATE_INVALID = "GTFS_TO_HTML_CONFIG_DATE_INVALID", CONFIG_MISSING_AGENCIES = "GTFS_TO_HTML_CONFIG_MISSING_AGENCIES", DATABASE_OPEN_FAILED = "GTFS_TO_HTML_DATABASE_OPEN_FAILED", GTFS_IMPORT_FAILED = "GTFS_TO_HTML_GTFS_IMPORT_FAILED", FILE_SYSTEM_WRITE_FAILED = "GTFS_TO_HTML_FILE_SYSTEM_WRITE_FAILED", OUTPUT_DIRECTORY_NOT_EMPTY = "GTFS_TO_HTML_OUTPUT_DIRECTORY_NOT_EMPTY", QUERY_RESULT_NOT_FOUND = "GTFS_TO_HTML_QUERY_RESULT_NOT_FOUND", QUERY_RESULT_AMBIGUOUS = "GTFS_TO_HTML_QUERY_RESULT_AMBIGUOUS", QUERY_INVALID = "GTFS_TO_HTML_QUERY_INVALID", TIMETABLE_GENERATION_FAILED = "GTFS_TO_HTML_TIMETABLE_GENERATION_FAILED" } interface GtfsToHtmlErrorOptions { code: GtfsToHtmlErrorCode; category: GtfsToHtmlErrorCategory; isOperational?: boolean; details?: Record<string, unknown>; cause?: unknown; } declare class GtfsToHtmlError extends Error { code: GtfsToHtmlErrorCode; category: GtfsToHtmlErrorCategory; isOperational: boolean; details?: Record<string, unknown>; constructor(message: string, options: GtfsToHtmlErrorOptions); } declare function isGtfsToHtmlError(error: unknown): error is GtfsToHtmlError; /** * GTFS parsing failures can come from parsing, validation or GTFS zip structure checks. */ declare function isGtfsParsingError(error: unknown): boolean; declare function formatGtfsToHtmlError(error: unknown, options?: { verbosity: 'user' | 'developer'; }): string; //#endregion export { type Config, type FormattedTimetable, type FormattedTimetablePage, GtfsError, GtfsErrorCategory, GtfsErrorCode, GtfsToHtmlError, GtfsToHtmlErrorCategory, GtfsToHtmlErrorCode, type GtfsWarning, GtfsWarningCode, type ImportReport, gtfsToHtml as default, formatGtfsError, formatGtfsToHtmlError, isGtfsError, isGtfsParsingError, isGtfsToHtmlError, isGtfsValidationError }; //# sourceMappingURL=index.d.ts.map