Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ponlawat-w/gtfs-io
Type definitions and IO operations for GTFS datasets in TypeScript
https://github.com/ponlawat-w/gtfs-io
gtfs gtfs-feed reader writer
Last synced: 7 days ago
JSON representation
Type definitions and IO operations for GTFS datasets in TypeScript
- Host: GitHub
- URL: https://github.com/ponlawat-w/gtfs-io
- Owner: ponlawat-w
- Created: 2023-12-01T04:31:23.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-15T05:45:07.000Z (about 1 year ago)
- Last Synced: 2024-12-01T23:37:55.589Z (21 days ago)
- Topics: gtfs, gtfs-feed, reader, writer
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/gtfs-io
- Size: 203 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
Awesome Lists containing this project
README
# GTFS-IO
IO Operations for GTFS dataset in node / javascript.
## Installation
```bash
npm i gtfs-io
```## Examples
### Load Feed
```ts
// Synchronously
import { GTFSFeedReaderFromFile, GTFSFeedReaderFromMemory } from 'gtfs-io';
const reader = GTFSFeedReaderFromFile.fromZip('gtfs.zip');
const reader = GTFSFeedReaderFromFile.fromDirectory('path/to/dir');
const reader = GTFSFeedReaderFromMemory.fromZip(zipBuffer);
// OR
import { GTFSFeedReader } from 'gtfs-io/io/file';
const reader = GTFSFeedReader.fromZip('gtfs.zip');
const reader = GTFSFeedReader.fromDirectory('path/to/dir');
// OR
import { GTFSFeedReader } from 'gtfs-io/io/memory';
const reader = GTFSFeedReader.fromZip(zipBuffer);
// THEN
const feed = reader.loadFeed();
console.log(feed.stops[0].stop_id);
console.log(feed.trips[1].trip_id);// ===
// Asynchronously
import { GTFSAsyncFeedReaderFromFile, GTFSAsyncFeedReaderFromMemory } from 'gtfs-io';
const reader = GTFSAsyncFeedReaderFromFile.fromZip('gtfs.zip');
const reader = GTFSAsyncFeedReaderFromFile.fromDirectory('path/to/dir');
const reader = GTFSAsyncFeedReaderFromMemory.fromZip(zipBuffer);
// OR
import { GTFSAsyncFeedReader } from 'gtfs-io/io/file';
const reader = GTFSAsyncFeedReader.fromZip('gtfs.zip');
const reader = GTFSAsyncFeedReader.fromDirectory('path/to/dir');
// OR
import { GTFSAsyncFeedReader } from 'gtfs-io/io/memory';
const reader = GTFSAsyncFeedReader.fromZip(zipBuffer);
// THEN
const feed = await reader.loadFeed();
console.log(feed.stops[0].stop_id);
console.log(feed.trips[1].trip_id);
```### Write Feed
```ts
import { GTFSLoadedFeed } from 'gtfs-io';
const feed = new GTFSLoadedFeed({
agency: [{ agency_id: '...', agency_name: '...', ... }, ...],
stops: [{ stop_id: '...', ... }, { ... }, ...],
routes: [{ ... }, { ... }, ...],
trips: [{ ... }, ...],
...
});// Synchronously
import { GTFSFeedWriterToFile } from 'gtfs-io';
GTFSFeedWriterToFile.toZip(feed, 'gtfs.zip');
GTFSFeedWriterToFile.toDirectory(feed, 'path/to/dir');
// OR
import { GTFSFeedWriter } from 'gtfs-io/io/file';
GTFSFeedWriter.toZip(feed, 'gtfs.zip');
GTFSFeedWriter.toDirectory(feed, 'path/to/dir');// ===
// Asynchronously
import { GTFSAsyncFeedWriterToFile } from 'gtfs-io';
await GTFSAsyncFeedWriterToFile.toZip(feed, 'gtfs.zip');
await GTFSAsyncFeedWriterToFiler.toDirectory(feed, 'path/to/dir');
// OR
import { GTFSAsyncFeedWriter } from 'gtfs-io/io/file';
await GTFSAsyncFeedWriter.toZip(feed, 'gtfs.zip');
await GTFSAsyncFeedWriter.toDirectory(feed, 'path/to/dir');
```---