iata-city-codes
v0.1.0
Published
Map IATA city (metro-area) codes to the airports they group, and back.
Maintainers
Readme
iata-city-codes
Map IATA city codes (metropolitan-area codes) to the individual airport codes they group, and back. Example: LON → [LHR, LGW, STN, LTN, LCY, SEN, BQH].
import { getAirportsByCityCode } from "iata-city-codes";
getAirportsByCityCode("LON").map((a) => a.iata);
// ["BQH", "LCY", "LGW", "LHR", "LTN", "SEN", "STN"]Unofficial data — read this first
This is community-sourced, unofficial data, not IATA's own City Code Directory (which is a paid product — see iata.org if you need guaranteed-authoritative, contractually-supported data).
Not every city code is accepted as search input by every flight-search API or GDS. This package gives you the mapping; whether a given booking engine treats LON as a searchable origin/destination is a decision made by that engine, not by this package.
See DATA_SOURCES.md for exact provenance and fetch dates.
Install
npm install iata-city-codesZero runtime dependencies. Ships ESM + CJS + types.
Size
The dataset covers the full worldwide IATA airport list (9,250 airports, 8,827 city codes, 286 of them multi-airport). Minified bundle is ~1.2MB per module format — most of that is airport names/countries for single-airport codes, which gzip well in transit. If you only need multi-airport groupings, getAllMultiAirportCities() narrows that down to 286 cities.
API
getAirportsByCityCode(cityCode: string): Airport[]
getAirportsByCityCode("WAS");
// [{ iata: "BWI", ... }, { iata: "DCA", ... }, { iata: "IAD", ... }]getCityCodeForAirport(airportCode: string): string | null
Returns the city code an airport belongs to — or the airport's own code if it IS the city code (single-airport city).
getCityCodeForAirport("LHR"); // "LON"
getCityCodeForAirport("GVA"); // "GVA" (Geneva: single-airport city)
getCityCodeForAirport("ZZZ"); // nullgetCityForAirport(airportCode: string): City | null
getCityForAirport("LGW");
// { code: "LON", name: "London", countryCode: "GB", airports: [...] }getCity(cityCode: string): City | null
getCity("LON");
// { code: "LON", name: "London", countryCode: "GB", airports: [...] }isCityCode(code: string): boolean
isCityCode("LON"); // true
isCityCode("GVA"); // true (single-airport city, code doubles as both)
isCityCode("LHR"); // false — LHR is an airport, not a city codeisAirportCode(code: string): boolean
isAirportCode("LHR"); // true
isAirportCode("LON"); // false — LON has no airport of its own
isAirportCode("GVA"); // truegetAllMultiAirportCities(): City[]
Returns all 286 cities with 2+ airports grouped under them.
Known edge cases
- Basel–Mulhouse–Freiburg: one physical airport, three codes —
EAP(binational),BSL(Swiss side),MLH(French side). All three are exposed as distinct entries under city codeEAP, each with anotesfield explaining the relationship (pricing/domestic-status differs by code). - Washington, D.C. (
WAS): groupsDCA,IAD, andBWI. - Single-airport cities (e.g. Geneva
GVA): the city code and airport code coincide.isCityCode()andisAirportCode()both returntruefor these.
Regenerating the data
npm run build:dataFetches the source CSVs fresh, re-derives src/data/airports.generated.ts and src/data/cities.generated.ts, and cross-checks the multi-airport city list against Wikipedia (warns on discrepancies, doesn't fail the build).
License
MIT
