UNPKG

trento-parking

Version:

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.

96 lines (92 loc) 3.21 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // src/models/index.ts var models_exports = {}; __export(models_exports, { ParkingData: () => ParkingData, ParkingType: () => ParkingType }); module.exports = __toCommonJS(models_exports); // src/models/parking-data.ts var ParkingData = class { constructor(data) { __publicField(this, "id"); __publicField(this, "driver"); __publicField(this, "geom"); __publicField(this, "name"); __publicField(this, "type"); __publicField(this, "city"); __publicField(this, "color"); __publicField(this, "capacity"); __publicField(this, "freeslots"); __publicField(this, "diag"); __publicField(this, "threshold"); __publicField(this, "timestamp"); __publicField(this, "distances"); __publicField(this, "currentTimestamp"); __publicField(this, "address"); __publicField(this, "gmaps"); __publicField(this, "link"); __publicField(this, "offline"); __publicField(this, "opening"); __publicField(this, "open"); __publicField(this, "phone"); __publicField(this, "website"); __publicField(this, "openingFlag"); Object.assign(this, data); } getDistances() { try { return JSON.parse(this.distances); } catch (error) { console.error("Error parsing distances JSON:", error); return []; } } getDistancesCompleted(parkings) { const distances = this.getDistances(); const distancesCompleted = distances.map((distance) => { const parking = parkings.find((p) => p.id === distance.id); if (!parking) { return null; } return { ...distance, ...parking }; }); return distancesCompleted.filter((distance) => distance !== null); } isAvailable() { return this.freeslots > 0; } isFull() { return this.freeslots === 0 && this.capacity > 0; } }; // src/models/parking-types.ts var ParkingType = /* @__PURE__ */ ((ParkingType2) => { ParkingType2["BIKE"] = "bike"; ParkingType2["PARK"] = "park"; return ParkingType2; })(ParkingType || {}); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ParkingData, ParkingType });