@dylmye/flight-designator
TypeScript icon, indicating that this package has built-in type declarations

4.1.3 • Public • Published

Flight Designator

npm npm license npm downloads Build Status

A fork of Jonas Hermsmeier's Flight Designator validation, converted to TypeScript and ES6 classes. Requires Node 10 or above.

Install via npm or yarn

$ npm install --save @dylmye/flight-designator
$ yarn add @dylmye/flight-designator

Usage

import FlightDesignator from "@dylmye/flight-designator";

Parse

FlightDesignator.parse('U24511A') // OR
new FlightDesignator().parse('U24511A')
> FlightDesignator {
  airlineCode: 'U2',
  flightNumber: 4511,
  operationalSuffix: 'A'
}
Validate
FlightDesignator.isValid('KLM0180')
> true
FlightDesignator.isValidAirlineCode('KLM')
> true
FlightDesignator.isValidFlightNumber('0180')
> true
Construct & validate instance
// Construct a flight designator
const flight = new FlightDesignator('KLM', '645')
> FlightDesignator {
  airlineCode: 'KLM',
  flightNumber: 645,
  operationalSuffix: ''
}
// Check whether it's valid
flight.isValid()
> true
Format flight designators
FlightDesignator.format('u2 0350A')
// Compact
> 'U2350A'
// With spaces
FlightDesignator.format('u2 0350A', true)
> 'U2 350 A'
// With zero-padded flight number
FlightDesignator.format('u2350A', true, true)
> 'U2 0350 A'
var flight = new FlightDesignator('LH', 254, 'X')
// Compact
flight.toString()
> 'LH254X'
// With spaces
flight.toString(true)
> 'LH 254 X'
// With zero-padded flight number
flight.toString(true, true)
> 'LH 0254 X'

Package Sidebar

Install

npm i @dylmye/flight-designator

Weekly Downloads

1

Version

4.1.3

License

MIT

Unpacked Size

21.3 kB

Total Files

12

Last publish

Collaborators

  • dylmye