Airline
Module to generate airline and airport related data.
Overview
Several methods in this module return objects rather than strings. For example, you can use faker.airline.airport().iataCode
to pick out the specific property you need.
For a random airport, use airport()
.
For a random airline, use airline()
.
For a dummy booking, a passenger will generally book a flight on a specific flightNumber()
, airplane()
, be allocated a seat()
, and recordLocator()
.
Related Modules
- To generate sample passenger data, you can use the methods of the
faker.person
module.
aircraftType
Returns a random aircraft type.
Available since v8.0.0
Returns: 'narrowbody' | 'regional' | 'widebody'
function aircraftType(): AircraftType;
Examples
faker.airline.aircraftType() // 'narrowbody'
Source
airline
Generates a random airline.
Available since v8.0.0
Returns: Airline
function airline(): Airline;
Examples
faker.airline.airline() // { name: 'American Airlines', iataCode: 'AA' }
Source
airplane
Generates a random airplane.
Available since v8.0.0
Returns: Airplane
function airplane(): Airplane;
Examples
faker.airline.airplane() // { name: 'Airbus A321neo', iataTypeCode: '32Q' }
Source
airport
Generates a random airport.
Available since v8.0.0
Returns: Airport
function airport(): Airport;
Examples
faker.airline.airport() // { name: 'Dallas Fort Worth International Airport', iataCode: 'DFW' }
Source
flightNumber
Returns a random flight number. Flight numbers are always 1 to 4 digits long. Sometimes they are
used without leading zeros (e.g.: American Airlines flight 425
) and sometimes with leading
zeros, often with the airline code prepended (e.g.: AA0425
).
To generate a flight number prepended with an airline code, combine this function with the
airline()
function and use template literals:
`${faker.airline.airline().iataCode}${faker.airline.flightNumber({ addLeadingZeros: true })}` // 'AA0798'
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | The options to use. |
options.addLeadingZeros? | boolean | false | Whether to pad the flight number up to 4 digits with leading zeros. |
options.length? | number | { min: number; max: number; } | { min: 1, max: 4 } | The number or range of digits to generate. |
Returns: string
function flightNumber(
options: {
length?:
| number
| {
min: number;
max: number;
};
addLeadingZeros?: boolean;
} = {}
): string;
Examples
faker.airline.flightNumber() // '2405'
faker.airline.flightNumber({ addLeadingZeros: true }) // '0249'
faker.airline.flightNumber({ addLeadingZeros: true, length: 2 }) // '0042'
faker.airline.flightNumber({ addLeadingZeros: true, length: { min: 2, max: 3 } }) // '0624'
faker.airline.flightNumber({ length: 3 }) // '425'
faker.airline.flightNumber({ length: { min: 2, max: 3 } }) // '84'
Source
recordLocator
Generates a random record locator. Record locators are used by airlines to identify reservations. They're also known as booking reference numbers, locator codes, confirmation codes, or reservation codes.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | The options to use. |
options.allowNumerics? | boolean | false | Whether to allow numeric characters. |
options.allowVisuallySimilarCharacters? | boolean | false | Whether to allow visually similar characters such as '1' and 'I'. |
Returns: string
function recordLocator(
options: {
allowNumerics?: boolean;
allowVisuallySimilarCharacters?: boolean;
} = {}
): string;
Examples
faker.airline.recordLocator() // 'KIFRWE'
faker.airline.recordLocator({ allowNumerics: true }) // 'E5TYEM'
faker.airline.recordLocator({ allowVisuallySimilarCharacters: true }) // 'ANZNEI'
faker.airline.recordLocator({ allowNumerics: true, allowVisuallySimilarCharacters: true }) // '1Z2Z3E'
Source
seat
Generates a random seat.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | { ... } | {} | The options to use. |
options.aircraftType? | 'narrowbody' | 'regional' | 'widebody' | 'narrowbody' | The aircraft type. Can be one of |
Returns: string
function seat(
options: {
aircraftType?: AircraftType;
} = {}
): string;
Examples
faker.airline.seat() // '22C'
faker.airline.seat({ aircraftType: 'regional' }) // '7A'
faker.airline.seat({ aircraftType: 'widebody' }) // '42K'