UNPKG

@swimmable/sdk

Version:

Official JavaScript/TypeScript SDK for the Swimmable API - Real-time swimming conditions and water quality data

117 lines 3.65 kB
/** * Utility classes and functions for the Swimmable SDK */ import { Coordinates } from './types'; /** * Custom error class for Swimmable API errors */ export declare class SwimmableError extends Error { status?: number; code?: string; endpoint?: string; constructor(message: string, status?: number, code?: string, endpoint?: string); } /** * Utility functions for working with coordinates and locations */ export declare class LocationUtils { /** * Validate that coordinates are within valid ranges * @param coordinates - Coordinates to validate */ static validateCoordinates(coordinates: Coordinates): boolean; /** * Calculate the distance between two coordinates using the Haversine formula * @param coord1 - First coordinate * @param coord2 - Second coordinate * @returns Distance in kilometers */ static calculateDistance(coord1: Coordinates, coord2: Coordinates): number; /** * Convert degrees to radians * @param degrees - Degrees to convert */ private static toRadians; /** * Find the nearest spot from a list of coordinates * @param target - Target coordinates * @param spots - Array of spots with coordinates */ static findNearestSpot<T extends Coordinates>(target: Coordinates, spots: T[]): T | null; } /** * Utility functions for working with swimming conditions */ export declare class ConditionsUtils { /** * Convert temperature from Celsius to Fahrenheit * @param celsius - Temperature in Celsius */ static celsiusToFahrenheit(celsius: number): number; /** * Convert temperature from Fahrenheit to Celsius * @param fahrenheit - Temperature in Fahrenheit */ static fahrenheitToCelsius(fahrenheit: number): number; /** * Get a human-readable description of the swimmability score * @param score - Swimmability score (1-10) */ static getSwimmabilityDescription(score: number): string; /** * Get a color code for the swimmability score (useful for UI) * @param score - Swimmability score (1-10) */ static getSwimmabilityColor(score: number): string; /** * Check if conditions are safe for swimming based on various factors * @param conditions - Enhanced conditions object */ static isSafeForSwimming(conditions: any): boolean; } /** * Utility functions for API key management */ export declare class ApiKeyUtils { /** * Validate API key format * @param apiKey - API key to validate */ static validateApiKey(apiKey: string): boolean; /** * Get the prefix of an API key (for display purposes) * @param apiKey - Full API key */ static getKeyPrefix(apiKey: string): string; /** * Mask an API key for secure display * @param apiKey - API key to mask */ static maskApiKey(apiKey: string): string; } /** * Rate limiting utilities for client-side throttling */ export declare class RateLimiter { private requests; private maxRequests; private windowMs; constructor(maxRequests?: number, windowMs?: number); /** * Check if a request can be made without exceeding rate limits */ canMakeRequest(): boolean; /** * Record a request (call this after making a successful request) */ recordRequest(): void; /** * Get the number of requests remaining in the current window */ getRemainingRequests(): number; /** * Get the time until the rate limit window resets (in milliseconds) */ getResetTime(): number; } //# sourceMappingURL=utils.d.ts.map