UNPKG

tfl-ts

Version:

🚇 Fully-typed TypeScript client for Transport for London (TfL) API • Zero dependencies • Auto-generated types • Real-time arrivals • Journey planning • Universal compatibility

117 lines (116 loc) • 4.62 kB
/** * Bike Point Utilities * * This module provides utility functions for working with bike point data, * including status extraction, filtering, and property access. * * @example * import { getPropertyValue, findElectricBikes } from 'tfl-ts/utils/bikePoint'; * * // Get property values from bike point data * const bikes = getPropertyValue(bikePoint, 'NbBikes'); * console.log(`Bikes available: ${bikes || 0}`); * * // Filter bike points with electric bikes * const eBikePoints = findElectricBikes(allBikePoints); * console.log(`Found ${eBikePoints.length} bike points with electric bikes`); */ import { BikePointInfo, BikePointStatus } from '../bikePoint'; /** * Extract bike point status information from raw bike point data * * This internal utility function parses the additional properties of a bike point * to extract meaningful status information like available bikes, spaces, etc. * * @internal This function is used internally by the BikePoint class and should not be used directly. * @param bikePoint - Raw bike point information from the API * @param keepTflTypes - Whether to preserve original additional properties * @returns Structured bike point status information */ declare const extractStatus: (bikePoint: BikePointInfo, keepTflTypes?: boolean) => BikePointStatus; /** * Get a property value from bike point additional properties * * This utility function searches through the additional properties * of a bike point to find a specific property by its key. * * @param bikePoint - Bike point information * @param key - Property key to search for * @returns Property value or undefined if not found * @example * // Get number of bikes * const bikes = getPropertyValue(bikePoint, 'NbBikes'); * console.log(`Bikes available: ${bikes || 0}`); * * // Get terminal name * const terminal = getPropertyValue(bikePoint, 'TerminalName'); * if (terminal) { * console.log(`Terminal: ${terminal}`); * } */ export declare const getPropertyValue: (bikePoint: BikePointInfo, key: string) => string | undefined; export { extractStatus }; /** * Find bike points with electric bikes available * * This utility function filters bike points to find those with electric bikes * available for hire. * * @param bikePoints - Array of bike point information * @returns Array of bike points with electric bikes * @example * // Find bike points with electric bikes * const allBikePoints = await client.bikePoint.get(); * const eBikePoints = findElectricBikes(allBikePoints); * * console.log(`Found ${eBikePoints.length} bike points with electric bikes`); * * eBikePoints.forEach(bikePoint => { * const status = extractStatus(bikePoint); * console.log(`${status.name}: ${status.eBikes} electric bikes`); * }); */ export declare const findElectricBikes: (bikePoints: BikePointInfo[]) => BikePointInfo[]; /** * Sort bike points by distance from a location * * This utility function sorts bike points by their distance from a given * location, with closest points first. * * @param bikePoints - Array of bike point information * @param lat - Latitude of the reference point * @param lon - Longitude of the reference point * @returns Sorted array of bike points * @example * // Sort bike points by distance from a location * const allBikePoints = await client.bikePoint.get(); * const sortedByDistance = sortByDistance(allBikePoints, 51.508418, -0.067048); * * console.log('Closest bike points:'); * sortedByDistance.slice(0, 5).forEach((bikePoint, index) => { * const status = extractStatus(bikePoint); * console.log(`${index + 1}. ${status.name} (${bikePoint.distance?.toFixed(0)}m)`); * }); */ export declare const sortByDistance: (bikePoints: BikePointInfo[], lat: number, lon: number) => BikePointInfo[]; /** * Find the closest bike point with available bikes * * This utility function finds the nearest bike point that has bikes available * for hire. * * @param bikePoints - Array of bike point information * @returns Closest bike point with bikes, or undefined if none found * @example * // Find closest bike point with bikes * const allBikePoints = await client.bikePoint.get(); * const closestWithBikes = findClosestWithBikes(allBikePoints); * * if (closestWithBikes) { * const status = extractStatus(closestWithBikes); * console.log(`Closest bike point with bikes: ${status.name} (${closestWithBikes.distance?.toFixed(0)}m)`); * } else { * console.log('No bike points with available bikes found'); * } */ export declare const findClosestWithBikes: (bikePoints: BikePointInfo[]) => BikePointInfo | undefined;