UNPKG

flight-planner

Version:

Plan and route VFR flights

56 lines (55 loc) 2.08 kB
/** * Checks if the given string is a valid aircraft registration. * * @param registration - The string to check * @returns True if the string is a valid aircraft registration, false otherwise */ export const isAircraftRegistration = (registration) => { return /^[A-Z0-9]{1,3}-?[A-Z0-9]+$/.test(registration.toUpperCase()); }; /** * Normalizes the given aircraft registration to uppercase. * * @param registration - The aircraft registration to normalize * @returns The normalized aircraft registration */ export const aircraftNormalizeRegistration = (registration) => { return registration.toUpperCase().replace(/-/g, ''); }; /** * Calculates the maximum payload of the aircraft based on its maximum takeoff weight and empty weight. * * @param aircraft - The aircraft object * @returns The maximum payload in kilograms, or undefined if the weights are not provided */ export const aircraftMaxPayload = (aircraft) => { if (aircraft.maxTakeoffWeight && aircraft.emptyWeight) { return aircraft.maxTakeoffWeight - aircraft.emptyWeight; } return undefined; }; /** * Calculates the range of the aircraft based on its fuel capacity, fuel consumption, and cruise speed. * * @param aircraft - The aircraft object * @returns The range in nautical miles, or undefined if the required properties are not provided */ export const aircraftRange = (aircraft) => { const endurance = aircraftEndurance(aircraft); if (endurance && aircraft.cruiseSpeed) { return endurance * aircraft.cruiseSpeed; } return undefined; }; /** * Calculates the endurance of the aircraft based on its fuel capacity and fuel consumption. * * @param aircraft - The aircraft object * @returns The endurance in hours, or undefined if the required properties are not provided or fuelConsumption is zero */ export const aircraftEndurance = (aircraft) => { if (aircraft.fuelCapacity && aircraft.fuelConsumption && aircraft.fuelConsumption > 0) { return aircraft.fuelCapacity / aircraft.fuelConsumption; } return undefined; };