trento-parking
v1.1.0
Published
A TypeScript library providing easy access to parking and bike slot availability, location, and details in Trento, Italy. Fetches data from the official Comune di Trento parking services.
Maintainers
Readme
Trento Parking
A TypeScript library providing easy access to parking and bike slot availability, location, and details in Trento, Italy. This library fetches real-time data from the official Comune di Trento parking services.
Features
- Real-time parking availability data
- Bike slot information
- Parking location details
- Distance calculations between parking locations
- Filtering capabilities (by type, availability, etc.)
- TypeScript support with full type definitions
Installation
npm install trento-parking
# or
yarn add trento-parking
# or
pnpm add trento-parkingUsage
import { ParkingDataCollection } from 'trento-parking';
// Initialize the parking collection
const parkingCollection = new ParkingDataCollection();
// Refresh the data
await parkingCollection.refresh();
// Get all parking locations
const allParkings = parkingCollection.all();
// Get a specific parking by ID
const parkingById = parkingCollection.byId(211);
// Get available parking spots
const availableParkings = parkingCollection.getAvailable();
// Get full parking locations
const fullParkings = parkingCollection.getFull();
// Get parking locations by type
const parkingsByType = parkingCollection.byType('park');
// Get distances between parking locations
const parkingWithDistances = parkingCollection.byId(211);
const distances = parkingWithDistances?.getDistancesCompleted(parkingCollection.all());API Reference
ParkingDataCollection
The main class for interacting with parking data.
Methods
refresh(): Fetches the latest parking dataall(): Returns all parking locationsbyId(id: number): Returns a specific parking location by IDbyType(type: ParkingType): Returns parking locations filtered by typegetAvailable(): Returns parking locations with available spotsgetFull(): Returns parking locations that are at capacitygetLastRefresh(): Returns the timestamp of the last data refresh
Parking Data Model
Each parking location includes:
id: Unique identifiername: Parking location nametype: Type of parking facilitycapacity: Total number of spotsfreeslots: Number of available spotscoordinates: Location coordinatesgetDistances(): Calculates distances to other parking locations
Requirements
- Node.js >= 18
- TypeScript (for TypeScript projects)
Development
This project uses:
- TypeScript for type safety
- Vitest for testing
- Biome for linting and formatting
- Changesets for version management
- tsup for building
Setup
- Clone the repository
- Install dependencies:
pnpm install - Run tests:
pnpm test
Available Scripts
pnpm build: Build the librarypnpm test: Run testspnpm format: Format codepnpm lint: Lint codepnpm type-check: Check TypeScript types
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
