UNPKG

scheduling-sdk

Version:

Brought to you by Recal - A TypeScript SDK for scheduling functionality

64 lines 2.13 kB
import type { WeeklyAvailability } from '../types/availability.types.ts'; /** * Validates a WeeklyAvailability object for correctness and consistency. * * Performs comprehensive validation including: * - Object structure validation * - Schedule array validation * - Day name validation * - Time format validation (HH:mm) * - Time range validation (start < end) * - Overlap detection between schedules on the same day * - Optional timezone format validation * * @param availability - The availability object to validate (can be undefined) * * @throws {Error} With descriptive message if validation fails * * @example * ```typescript * // Valid availability passes without error * const validAvailability = { * schedules: [ * { days: ['monday', 'tuesday'], start: '09:00', end: '17:00' } * ], * timezone: 'America/New_York' * } * validateWeeklyAvailability(validAvailability) // No error * * // Invalid availability throws descriptive error * const invalidAvailability = { * schedules: [ * { days: ['monday'], start: '17:00', end: '09:00' } // End before start! * ] * } * validateWeeklyAvailability(invalidAvailability) * // Throws: "Schedule at index 0: start time (17:00) must be before end time (09:00)" * ``` * * @example * ```typescript * // Use in error handling * try { * validateWeeklyAvailability(userInput) * const scheduler = new AvailabilityScheduler(userInput) * } catch (error) { * console.error('Invalid availability:', error.message) * // Show user-friendly error message * showError(`Availability configuration error: ${error.message}`) * } * ``` * * @example * ```typescript * // Undefined availability is valid (optional parameter) * validateWeeklyAvailability(undefined) // No error * validateWeeklyAvailability() // No error * * // Null or other types are invalid * validateWeeklyAvailability(null) // Throws error * validateWeeklyAvailability("invalid") // Throws error * ``` */ export declare function validateWeeklyAvailability(availability?: WeeklyAvailability): void; //# sourceMappingURL=availability.validator.d.ts.map