gtfs-to-html
Version:
Build human readable transit timetables as HTML, PDF or CSV from GTFS
132 lines (125 loc) • 4.69 kB
TypeScript
import { ConfigAgency, Timetable, Route, Trip, Stop, TimetablePage } from 'gtfs';
export { GtfsError, GtfsErrorCategory, GtfsErrorCode, GtfsWarning, GtfsWarningCode, ImportReport, formatGtfsError, isGtfsError, isGtfsValidationError } from 'gtfs';
interface Config {
agencies: ConfigAgency[];
assetPath?: string;
sqlitePath?: string;
allowEmptyTimetables?: boolean;
beautify?: boolean;
coordinatePrecision?: number;
dateFormat?: string;
daysShortStrings?: string[];
daysStrings?: string[];
defaultOrientation?: string;
effectiveDate?: string;
endDate?: string;
groupTimetablesIntoPages?: 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;
}
interface FormattedTimetable extends Timetable {
route_ids: string[];
trip_ids: string[];
routes: Route[];
orderedTrips: Trip[];
stops: Stop[];
service_ids?: string[];
warnings?: string[];
has_continues_as_route?: boolean;
has_continues_from_route?: boolean;
}
interface FormattedTimetablePage extends TimetablePage {
timetables: FormattedTimetable[];
routes: Route[];
relativePath?: string;
}
declare const gtfsToHtml: (initialConfig: Config) => Promise<string>;
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;
export { type Config, type FormattedTimetable, type FormattedTimetablePage, GtfsToHtmlError, GtfsToHtmlErrorCategory, GtfsToHtmlErrorCode, gtfsToHtml as default, formatGtfsToHtmlError, isGtfsParsingError, isGtfsToHtmlError };