airport-data-js 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -20
- package/dist/airport-data.lite.min.js +1 -0
- package/dist/airport-data.min.js +1 -1
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -0
- package/lib/lite.js +1 -0
- package/lib/lite.mjs +1 -0
- package/lib/tools.js +1 -1
- package/lib/tools.mjs +1 -0
- package/package.json +51 -21
- package/types/core.d.mts +705 -0
- package/types/core.d.ts +705 -0
- package/types/index.d.mts +9 -0
- package/types/index.d.ts +5 -510
- package/types/lite.d.mts +7 -0
- package/types/lite.d.ts +7 -0
- package/types/state.d.mts +13 -0
- package/types/state.d.ts +13 -0
- package/types/tools.d.mts +50 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module airport-data
|
|
3
|
+
* @description A comprehensive TypeScript library for airport data lookup by IATA, ICAO,
|
|
4
|
+
* city, country, continent, timezone, coordinates, and more. Includes LLM-friendly typed interfaces.
|
|
5
|
+
*
|
|
6
|
+
* This entry point ships the full dataset. Use `airport-data-js/lite` for a smaller
|
|
7
|
+
* bundle without the website, Wikipedia, and flight-tracker URL fields.
|
|
8
|
+
*/
|
|
9
|
+
export * from './core.mjs';
|
package/types/index.d.ts
CHANGED
|
@@ -1,514 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a single airport record from the database.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```typescript
|
|
6
|
-
* const [airport] = await getAirportByIata('SIN');
|
|
7
|
-
* console.log(airport.airport); // "Singapore Changi Airport"
|
|
8
|
-
* console.log(airport.country_code); // "SG"
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export interface Airport {
|
|
12
|
-
/** 3-letter IATA airport code (e.g., "SIN", "LHR", "JFK") */
|
|
13
|
-
iata: string;
|
|
14
|
-
/** 4-letter ICAO airport code (e.g., "WSSS", "EGLL", "KJFK") */
|
|
15
|
-
icao: string;
|
|
16
|
-
/** IANA timezone identifier (e.g., "Asia/Singapore") */
|
|
17
|
-
time: string;
|
|
18
|
-
/** UTC offset in hours (e.g., 8, 5.5, -3.5). A DST-aware snapshot, not a fixed standard offset. */
|
|
19
|
-
utc: number;
|
|
20
|
-
/** ISO 3166-1 alpha-2 country code (e.g., "SG", "GB", "US") */
|
|
21
|
-
country_code: string;
|
|
22
|
-
/** 2-letter continent code: AF, AN, AS, EU, NA, OC, SA */
|
|
23
|
-
continent: string;
|
|
24
|
-
/** Full airport name (e.g., "Singapore Changi Airport") */
|
|
25
|
-
airport: string;
|
|
26
|
-
/** Latitude in decimal degrees */
|
|
27
|
-
latitude: number;
|
|
28
|
-
/** Longitude in decimal degrees */
|
|
29
|
-
longitude: number;
|
|
30
|
-
/** Elevation above sea level in feet, or null when unknown */
|
|
31
|
-
elevation_ft: number | null;
|
|
32
|
-
/** Airport classification: "large_airport" | "medium_airport" | "small_airport" | "heliport" | "seaplane_base" | "closed" */
|
|
33
|
-
type: string;
|
|
34
|
-
/** Whether the airport has scheduled commercial service */
|
|
35
|
-
scheduled_service: boolean | string;
|
|
36
|
-
/** Wikipedia article URL */
|
|
37
|
-
wikipedia?: string;
|
|
38
|
-
/** Airport official website URL */
|
|
39
|
-
website?: string;
|
|
40
|
-
/** Longest runway length in feet, or null when unknown */
|
|
41
|
-
runway_length?: number | null;
|
|
42
|
-
/** FlightRadar24 tracking URL */
|
|
43
|
-
flightradar24_url?: string;
|
|
44
|
-
/** RadarBox tracking URL */
|
|
45
|
-
radarbox_url?: string;
|
|
46
|
-
/** FlightAware tracking URL */
|
|
47
|
-
flightaware_url?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* An airport record with distance from a reference point, returned by proximity search functions.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* const nearest = await findNearestAirport(1.35, 103.99);
|
|
55
|
-
* console.log(nearest.distance); // 0.52 (km)
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export interface AirportWithDistance extends Airport {
|
|
59
|
-
/** Distance from the search point in kilometers */
|
|
60
|
-
distance: number;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Filter criteria for searching airports. All fields are optional and combined with AND logic.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* // Find large airports in the US with scheduled service
|
|
68
|
-
* const airports = await findAirports({
|
|
69
|
-
* country_code: 'US',
|
|
70
|
-
* type: 'large_airport',
|
|
71
|
-
* has_scheduled_service: true
|
|
72
|
-
* });
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export interface AirportFilters {
|
|
76
|
-
iata?: string;
|
|
77
|
-
icao?: string;
|
|
78
|
-
time?: string;
|
|
79
|
-
utc?: number;
|
|
80
|
-
country_code?: string;
|
|
81
|
-
continent?: string;
|
|
82
|
-
airport?: string;
|
|
83
|
-
latitude?: number;
|
|
84
|
-
longitude?: number;
|
|
85
|
-
elevation_ft?: number | null;
|
|
86
|
-
type?: string;
|
|
87
|
-
scheduled_service?: boolean | string;
|
|
88
|
-
wikipedia?: string;
|
|
89
|
-
website?: string;
|
|
90
|
-
runway_length?: number | null;
|
|
91
|
-
flightradar24_url?: string;
|
|
92
|
-
radarbox_url?: string;
|
|
93
|
-
flightaware_url?: string;
|
|
94
|
-
/** Filter by scheduled service availability (true = has scheduled service) */
|
|
95
|
-
has_scheduled_service?: boolean;
|
|
96
|
-
/** Minimum runway length in feet */
|
|
97
|
-
min_runway_ft?: number;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* External links associated with an airport.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const links = await getAirportLinks('LHR');
|
|
105
|
-
* console.log(links.wikipedia); // "https://en.wikipedia.org/wiki/Heathrow_Airport"
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export interface AirportLinks {
|
|
109
|
-
website?: string;
|
|
110
|
-
wikipedia?: string;
|
|
111
|
-
flightradar24?: string;
|
|
112
|
-
radarbox?: string;
|
|
113
|
-
flightaware?: string;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Aggregated statistics for airports in a country.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```typescript
|
|
120
|
-
* const stats = await getAirportStatsByCountry('US');
|
|
121
|
-
* console.log(stats.total); // 19000+
|
|
122
|
-
* console.log(stats.byType.large_airport); // 180+
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
export interface AirportCountryStats {
|
|
126
|
-
/** Total number of airports */
|
|
127
|
-
total: number;
|
|
128
|
-
/** Count of airports grouped by type */
|
|
129
|
-
byType: Record<string, number>;
|
|
130
|
-
/** Number of airports with scheduled commercial service */
|
|
131
|
-
withScheduledService: number;
|
|
132
|
-
/** Average runway length in feet across airports that have runway data */
|
|
133
|
-
averageRunwayLength: number;
|
|
134
|
-
/** Average elevation in feet */
|
|
135
|
-
averageElevation: number;
|
|
136
|
-
/** List of unique IANA timezones */
|
|
137
|
-
timezones: string[];
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Aggregated statistics for airports on a continent.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```typescript
|
|
144
|
-
* const stats = await getAirportStatsByContinent('EU');
|
|
145
|
-
* console.log(stats.byCountry['GB']); // number of UK airports
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
export interface AirportContinentStats extends AirportCountryStats {
|
|
149
|
-
/** Count of airports grouped by country code */
|
|
150
|
-
byCountry: Record<string, number>;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Result of a distance matrix calculation between multiple airports.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```typescript
|
|
157
|
-
* const matrix = await calculateDistanceMatrix(['SIN', 'LHR', 'JFK']);
|
|
158
|
-
* console.log(matrix.distances['SIN']['LHR']); // 10846
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export interface DistanceMatrix {
|
|
162
|
-
/** Summary info for each airport in the matrix */
|
|
163
|
-
airports: Array<{
|
|
164
|
-
code: string;
|
|
165
|
-
name: string;
|
|
166
|
-
iata: string;
|
|
167
|
-
icao: string;
|
|
168
|
-
}>;
|
|
169
|
-
/** Symmetric distance matrix: distances[codeA][codeB] = km (rounded) */
|
|
170
|
-
distances: Record<string, Record<string, number>>;
|
|
171
|
-
}
|
|
172
|
-
/** Sort criteria for ranking airports */
|
|
173
|
-
export type SortBy = 'runway' | 'elevation';
|
|
174
|
-
/**
|
|
175
|
-
* Finds airports by their 3-letter IATA code.
|
|
176
|
-
*
|
|
177
|
-
* @param iataCode - The IATA code of the airport (e.g., 'LHR').
|
|
178
|
-
* @returns Array of matching airport objects.
|
|
179
|
-
* @throws If the IATA code format is invalid or no data is found.
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```typescript
|
|
183
|
-
* const [airport] = await getAirportByIata('LHR');
|
|
184
|
-
* console.log(airport.airport); // "London Heathrow Airport"
|
|
185
|
-
* console.log(airport.country_code); // "GB"
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
export declare function getAirportByIata(iataCode?: string): Promise<Airport[]>;
|
|
189
|
-
/**
|
|
190
|
-
* Finds airports by their 4-character ICAO code.
|
|
191
|
-
*
|
|
192
|
-
* @param icaoCode - The ICAO code of the airport (e.g., 'EGLL').
|
|
193
|
-
* @returns Array of matching airport objects.
|
|
194
|
-
* @throws If the ICAO code format is invalid or no data is found.
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* const [airport] = await getAirportByIcao('EGLL');
|
|
199
|
-
* console.log(airport.airport); // "London Heathrow Airport"
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
export declare function getAirportByIcao(icaoCode?: string): Promise<Airport[]>;
|
|
203
|
-
/**
|
|
204
|
-
* Finds airports by their 2-letter ISO country code.
|
|
205
|
-
* Uses a pre-built index for O(1) lookup.
|
|
206
|
-
*
|
|
207
|
-
* @param countryCode - The ISO 3166-1 alpha-2 country code (e.g., 'US').
|
|
208
|
-
* @returns Array of matching airport objects.
|
|
209
|
-
* @throws If the country code format is invalid or no data is found.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```typescript
|
|
213
|
-
* const airports = await getAirportByCountryCode('US');
|
|
214
|
-
* console.log(airports.length); // 19000+
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
export declare function getAirportByCountryCode(countryCode?: string): Promise<Airport[]>;
|
|
218
|
-
/**
|
|
219
|
-
* Finds airports by their 2-letter continent code.
|
|
220
|
-
* Uses a pre-built index for O(1) lookup.
|
|
221
|
-
*
|
|
222
|
-
* Valid continent codes: AF (Africa), AN (Antarctica), AS (Asia),
|
|
223
|
-
* EU (Europe), NA (North America), OC (Oceania), SA (South America).
|
|
224
|
-
*
|
|
225
|
-
* @param continentCode - The continent code (e.g., 'AS' for Asia).
|
|
226
|
-
* @returns Array of matching airport objects.
|
|
227
|
-
* @throws If the continent code format is invalid or no data is found.
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* const airports = await getAirportByContinent('EU');
|
|
232
|
-
* console.log(airports.every(a => a.continent === 'EU')); // true
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
export declare function getAirportByContinent(continentCode?: string): Promise<Airport[]>;
|
|
236
|
-
/**
|
|
237
|
-
* Searches for airports by name. Case-insensitive partial matching.
|
|
238
|
-
*
|
|
239
|
-
* @param query - The name or partial name to search for (2-100 characters).
|
|
240
|
-
* @returns Array of matching airport objects.
|
|
241
|
-
* @throws If the query is too short or too long.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```typescript
|
|
245
|
-
* const airports = await searchByName('Heathrow');
|
|
246
|
-
* console.log(airports[0].iata); // "LHR"
|
|
247
|
-
* ```
|
|
248
|
-
*/
|
|
249
|
-
export declare function searchByName(query?: string): Promise<Airport[]>;
|
|
250
|
-
/**
|
|
251
|
-
* Finds airports within a specified radius of a geographic point.
|
|
252
|
-
* Uses a bounding-box pre-filter to skip expensive Haversine calculations for distant airports.
|
|
253
|
-
*
|
|
254
|
-
* @param lat - Latitude of the center point (-90 to 90).
|
|
255
|
-
* @param lon - Longitude of the center point (-180 to 180).
|
|
256
|
-
* @param radiusKm - The search radius in kilometers (default: 100).
|
|
257
|
-
* @returns Array of airports within the radius.
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* ```typescript
|
|
261
|
-
* // Find airports within 50km of central London
|
|
262
|
-
* const airports = await findNearbyAirports(51.5074, -0.1278, 50);
|
|
263
|
-
* console.log(airports.some(a => a.iata === 'LHR')); // true
|
|
264
|
-
* ```
|
|
265
|
-
*/
|
|
266
|
-
export declare function findNearbyAirports(lat: number, lon: number, radiusKm?: number): Promise<Airport[]>;
|
|
267
|
-
/**
|
|
268
|
-
* Finds airports by their type classification.
|
|
269
|
-
* Uses a pre-built index for O(1) lookup on exact matches.
|
|
270
|
-
*
|
|
271
|
-
* Valid types: "large_airport", "medium_airport", "small_airport", "heliport",
|
|
272
|
-
* "seaplane_base", "closed". Pass "airport" to match all airport types.
|
|
273
|
-
*
|
|
274
|
-
* @param type - The type of airport to filter by (case-insensitive).
|
|
275
|
-
* @returns Array of matching airport objects.
|
|
276
|
-
* @throws If the type is not a non-empty string.
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* ```typescript
|
|
280
|
-
* const largeAirports = await getAirportsByType('large_airport');
|
|
281
|
-
* console.log(largeAirports.length); // 300+
|
|
282
|
-
* ```
|
|
283
|
-
*/
|
|
284
|
-
export declare function getAirportsByType(type?: string): Promise<Airport[]>;
|
|
285
|
-
/**
|
|
286
|
-
* Calculates the great-circle distance between two airports using the Haversine formula.
|
|
287
|
-
*
|
|
288
|
-
* @param code1 - The IATA or ICAO code of the first airport.
|
|
289
|
-
* @param code2 - The IATA or ICAO code of the second airport.
|
|
290
|
-
* @returns The distance in kilometers, or null if an airport is not found.
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
* ```typescript
|
|
294
|
-
* const km = await calculateDistance('LHR', 'JFK');
|
|
295
|
-
* console.log(Math.round(km!)); // 5541
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
|
-
export declare function calculateDistance(code1: string, code2: string): Promise<number | null>;
|
|
299
|
-
/**
|
|
300
|
-
* Provides autocomplete suggestions based on a partial query.
|
|
301
|
-
* Searches by airport name and IATA code. Returns up to 10 results.
|
|
302
|
-
*
|
|
303
|
-
* @param query - The partial query string (2-100 characters).
|
|
304
|
-
* @returns Array of up to 10 matching airports.
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* ```typescript
|
|
308
|
-
* const suggestions = await getAutocompleteSuggestions('Lon');
|
|
309
|
-
* // Returns airports matching "Lon" (London Heathrow, London Gatwick, etc.)
|
|
310
|
-
* ```
|
|
311
|
-
*/
|
|
312
|
-
export declare function getAutocompleteSuggestions(query?: string): Promise<Airport[]>;
|
|
313
|
-
/**
|
|
314
|
-
* Finds airports that match multiple filter criteria (combined with AND logic).
|
|
315
|
-
* Uses indexed lookups where possible for performance.
|
|
316
|
-
*
|
|
317
|
-
* @param filters - An object of filter criteria to apply.
|
|
318
|
-
* @returns Array of matching airports.
|
|
319
|
-
* @throws If an unrecognized filter key is provided.
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* ```typescript
|
|
323
|
-
* const airports = await findAirports({
|
|
324
|
-
* country_code: 'GB',
|
|
325
|
-
* type: 'large_airport',
|
|
326
|
-
* has_scheduled_service: true
|
|
327
|
-
* });
|
|
328
|
-
* ```
|
|
329
|
-
*/
|
|
330
|
-
export declare function findAirports(filters?: AirportFilters): Promise<Airport[]>;
|
|
331
|
-
/**
|
|
332
|
-
* Finds all airports within a specific IANA timezone.
|
|
333
|
-
* Uses a pre-built index for O(1) lookup.
|
|
334
|
-
*
|
|
335
|
-
* @param timezone - The IANA timezone identifier (e.g., 'Europe/London', 'Asia/Singapore').
|
|
336
|
-
* @returns Array of matching airports.
|
|
337
|
-
* @throws If the timezone string is empty.
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```typescript
|
|
341
|
-
* const airports = await getAirportsByTimezone('Europe/London');
|
|
342
|
-
* console.log(airports.every(a => a.time === 'Europe/London')); // true
|
|
343
|
-
* ```
|
|
344
|
-
*/
|
|
345
|
-
export declare function getAirportsByTimezone(timezone?: string): Promise<Airport[]>;
|
|
346
|
-
/**
|
|
347
|
-
* Gets a map of external links (Wikipedia, FlightRadar24, etc.) for an airport.
|
|
348
|
-
*
|
|
349
|
-
* @param code - The IATA or ICAO code of the airport.
|
|
350
|
-
* @returns An object of links, or null if the airport is not found.
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* ```typescript
|
|
354
|
-
* const links = await getAirportLinks('LHR');
|
|
355
|
-
* console.log(links?.wikipedia); // "https://en.wikipedia.org/wiki/Heathrow_Airport"
|
|
356
|
-
* ```
|
|
357
|
-
*/
|
|
358
|
-
export declare function getAirportLinks(code: string): Promise<AirportLinks | null>;
|
|
359
|
-
/**
|
|
360
|
-
* Gets comprehensive statistics about airports in a specific country.
|
|
361
|
-
* Includes counts by type, average runway length, average elevation, and timezones.
|
|
362
|
-
*
|
|
363
|
-
* @param countryCode - The 2-letter ISO country code (e.g., 'US').
|
|
364
|
-
* @returns Aggregated statistics object.
|
|
365
|
-
* @throws If the country code format is invalid or no airports are found.
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
* ```typescript
|
|
369
|
-
* const stats = await getAirportStatsByCountry('US');
|
|
370
|
-
* console.log(stats.total); // 19000+
|
|
371
|
-
* console.log(stats.byType.large_airport); // 180+
|
|
372
|
-
* console.log(stats.withScheduledService); // number
|
|
373
|
-
* ```
|
|
374
|
-
*/
|
|
375
|
-
export declare function getAirportStatsByCountry(countryCode?: string): Promise<AirportCountryStats>;
|
|
376
|
-
/**
|
|
377
|
-
* Gets comprehensive statistics about airports on a specific continent.
|
|
378
|
-
* Includes counts by type, by country, average runway length, average elevation, and timezones.
|
|
379
|
-
*
|
|
380
|
-
* @param continentCode - The 2-letter continent code (e.g., 'AS' for Asia).
|
|
381
|
-
* @returns Aggregated statistics object with country breakdown.
|
|
382
|
-
* @throws If the continent code format is invalid or no airports are found.
|
|
383
|
-
*
|
|
384
|
-
* @example
|
|
385
|
-
* ```typescript
|
|
386
|
-
* const stats = await getAirportStatsByContinent('EU');
|
|
387
|
-
* console.log(stats.byCountry['GB']); // number of UK airports
|
|
388
|
-
* console.log(stats.byCountry['FR']); // number of French airports
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
export declare function getAirportStatsByContinent(continentCode?: string): Promise<AirportContinentStats>;
|
|
392
|
-
/**
|
|
393
|
-
* Gets the largest airports on a continent, ranked by runway length or elevation.
|
|
394
|
-
*
|
|
395
|
-
* @param continentCode - The 2-letter continent code (e.g., 'AS').
|
|
396
|
-
* @param limit - Maximum number of airports to return (1-1000, default: 10).
|
|
397
|
-
* @param sortBy - Sort criteria: 'runway' or 'elevation' (default: 'runway').
|
|
398
|
-
* @returns Array of airports sorted by the specified criteria (descending).
|
|
399
|
-
* @throws If the continent code format is invalid.
|
|
400
|
-
*
|
|
401
|
-
* @example
|
|
402
|
-
* ```typescript
|
|
403
|
-
* const top5 = await getLargestAirportsByContinent('AS', 5, 'runway');
|
|
404
|
-
* console.log(top5[0].runway_length); // longest runway in Asia
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
407
|
-
export declare function getLargestAirportsByContinent(continentCode?: string, limit?: number, sortBy?: SortBy): Promise<Airport[]>;
|
|
408
|
-
/**
|
|
409
|
-
* Fetches multiple airports by their IATA or ICAO codes in a single call.
|
|
410
|
-
* Returns null for codes that don't match any airport.
|
|
411
|
-
*
|
|
412
|
-
* @param codes - Array of IATA or ICAO codes (max 500).
|
|
413
|
-
* @returns Array of airport objects (null for unresolved codes), in the same order as input.
|
|
414
|
-
* @throws If codes is not an array or exceeds 500 entries.
|
|
415
|
-
*
|
|
416
|
-
* @example
|
|
417
|
-
* ```typescript
|
|
418
|
-
* const airports = await getMultipleAirports(['SIN', 'LHR', 'JFK']);
|
|
419
|
-
* console.log(airports[0]?.iata); // "SIN"
|
|
420
|
-
* console.log(airports[1]?.iata); // "LHR"
|
|
421
|
-
* ```
|
|
422
|
-
*/
|
|
423
|
-
export declare function getMultipleAirports(codes?: string[]): Promise<(Airport | null)[]>;
|
|
424
|
-
/**
|
|
425
|
-
* Calculates the great-circle distance between all pairs of airports.
|
|
426
|
-
* Exploits distance symmetry (d(A,B) === d(B,A)) to halve calculations.
|
|
427
|
-
*
|
|
428
|
-
* @param codes - Array of IATA or ICAO codes (2-100).
|
|
429
|
-
* @returns Distance matrix with airport summaries and symmetric distance table.
|
|
430
|
-
* @throws If fewer than 2 codes or any code is invalid.
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* ```typescript
|
|
434
|
-
* const matrix = await calculateDistanceMatrix(['SIN', 'LHR', 'JFK']);
|
|
435
|
-
* console.log(matrix.distances['SIN']['LHR']); // distance in km
|
|
436
|
-
* console.log(matrix.distances['LHR']['SIN']); // same value (symmetric)
|
|
437
|
-
* ```
|
|
438
|
-
*/
|
|
439
|
-
export declare function calculateDistanceMatrix(codes?: string[]): Promise<DistanceMatrix>;
|
|
440
|
-
/**
|
|
441
|
-
* Finds the single nearest airport to given coordinates, optionally filtered.
|
|
442
|
-
*
|
|
443
|
-
* @param lat - Latitude of the search point (-90 to 90).
|
|
444
|
-
* @param lon - Longitude of the search point (-180 to 180).
|
|
445
|
-
* @param filters - Optional filter criteria (e.g., `{ type: 'large_airport' }`).
|
|
446
|
-
* @returns The nearest airport with a `distance` field (km), or null if none found.
|
|
447
|
-
*
|
|
448
|
-
* @example
|
|
449
|
-
* ```typescript
|
|
450
|
-
* // Nearest large airport to central NYC
|
|
451
|
-
* const nearest = await findNearestAirport(40.7128, -74.006, { type: 'large_airport' });
|
|
452
|
-
* console.log(nearest?.iata); // e.g., "EWR"
|
|
453
|
-
* console.log(nearest?.distance); // distance in km
|
|
454
|
-
* ```
|
|
455
|
-
*/
|
|
456
|
-
export declare function findNearestAirport(lat: number, lon: number, filters?: AirportFilters): Promise<AirportWithDistance | null>;
|
|
457
|
-
/**
|
|
458
|
-
* Validates whether an IATA code exists in the airport database.
|
|
459
|
-
*
|
|
460
|
-
* @param code - The 3-letter IATA code to validate.
|
|
461
|
-
* @returns True if the code exists, false otherwise.
|
|
462
|
-
*
|
|
463
|
-
* @example
|
|
464
|
-
* ```typescript
|
|
465
|
-
* await validateIataCode('SIN'); // true
|
|
466
|
-
* await validateIataCode('ZZZ'); // false
|
|
467
|
-
* ```
|
|
468
|
-
*/
|
|
469
|
-
export declare function validateIataCode(code?: string): Promise<boolean>;
|
|
470
|
-
/**
|
|
471
|
-
* Validates whether an ICAO code exists in the airport database.
|
|
472
|
-
*
|
|
473
|
-
* @param code - The 4-character ICAO code to validate.
|
|
474
|
-
* @returns True if the code exists, false otherwise.
|
|
475
|
-
*
|
|
476
|
-
* @example
|
|
477
|
-
* ```typescript
|
|
478
|
-
* await validateIcaoCode('WSSS'); // true
|
|
479
|
-
* await validateIcaoCode('XXXX'); // false
|
|
480
|
-
* ```
|
|
481
|
-
*/
|
|
482
|
-
export declare function validateIcaoCode(code?: string): Promise<boolean>;
|
|
483
|
-
/**
|
|
484
|
-
* Gets the count of airports matching the given filters without returning full airport data.
|
|
485
|
-
*
|
|
486
|
-
* @param filters - Optional filter criteria. Omit for total count.
|
|
487
|
-
* @returns Count of matching airports.
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```typescript
|
|
491
|
-
* const total = await getAirportCount(); // all airports
|
|
492
|
-
* const usLarge = await getAirportCount({ country_code: 'US', type: 'large_airport' });
|
|
493
|
-
* ```
|
|
494
|
-
*/
|
|
495
|
-
export declare function getAirportCount(filters?: AirportFilters): Promise<number>;
|
|
496
|
-
/**
|
|
497
|
-
* Checks if an airport has scheduled commercial service.
|
|
498
|
-
*
|
|
499
|
-
* @param code - The IATA or ICAO code of the airport.
|
|
500
|
-
* @returns True if the airport has scheduled service.
|
|
501
|
-
* @throws If the airport is not found.
|
|
502
|
-
*
|
|
503
|
-
* @example
|
|
504
|
-
* ```typescript
|
|
505
|
-
* await isAirportOperational('SIN'); // true (Changi has scheduled flights)
|
|
506
|
-
* await isAirportOperational('WSSS'); // true (same airport, ICAO code)
|
|
507
|
-
* ```
|
|
508
|
-
*/
|
|
509
|
-
export declare function isAirportOperational(code: string): Promise<boolean>;
|
|
510
1
|
/**
|
|
511
2
|
* @module airport-data
|
|
512
3
|
* @description A comprehensive TypeScript library for airport data lookup by IATA, ICAO,
|
|
513
|
-
* country, continent, timezone, coordinates, and more. Includes LLM-friendly typed interfaces.
|
|
4
|
+
* city, country, continent, timezone, coordinates, and more. Includes LLM-friendly typed interfaces.
|
|
5
|
+
*
|
|
6
|
+
* This entry point ships the full dataset. Use `airport-data-js/lite` for a smaller
|
|
7
|
+
* bundle without the website, Wikipedia, and flight-tracker URL fields.
|
|
514
8
|
*/
|
|
9
|
+
export * from './core';
|
package/types/lite.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module airport-data/lite
|
|
3
|
+
* @description Same API as `airport-data-js`, backed by a smaller dataset that omits
|
|
4
|
+
* the `wikipedia`, `website`, `flightradar24_url`, `radarbox_url` and `flightaware_url`
|
|
5
|
+
* fields. `getAirportLinks` therefore returns an object with every link undefined.
|
|
6
|
+
*/
|
|
7
|
+
export * from './core.mjs';
|
package/types/lite.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module airport-data/lite
|
|
3
|
+
* @description Same API as `airport-data-js`, backed by a smaller dataset that omits
|
|
4
|
+
* the `wikipedia`, `website`, `flightradar24_url`, `radarbox_url` and `flightaware_url`
|
|
5
|
+
* fields. `getAirportLinks` therefore returns an object with every link undefined.
|
|
6
|
+
*/
|
|
7
|
+
export * from './core';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holds the compressed dataset for the current entry point.
|
|
3
|
+
* `index.ts` registers the full dataset, `lite.ts` the lite one; `core.ts`
|
|
4
|
+
* reads it lazily on first use.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface CompressedPayload {
|
|
8
|
+
gzip: string;
|
|
9
|
+
}
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function setPayload(p: CompressedPayload): void;
|
|
12
|
+
/** @internal */
|
|
13
|
+
export declare function getPayload(): CompressedPayload;
|
package/types/state.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holds the compressed dataset for the current entry point.
|
|
3
|
+
* `index.ts` registers the full dataset, `lite.ts` the lite one; `core.ts`
|
|
4
|
+
* reads it lazily on first use.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface CompressedPayload {
|
|
8
|
+
gzip: string;
|
|
9
|
+
}
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function setPayload(p: CompressedPayload): void;
|
|
12
|
+
/** @internal */
|
|
13
|
+
export declare function getPayload(): CompressedPayload;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module airport-data/tools
|
|
3
|
+
*
|
|
4
|
+
* Pre-built JSON Schema tool definitions for all airport-data functions.
|
|
5
|
+
* Use these with LLM tool-calling frameworks like OpenAI function calling,
|
|
6
|
+
* Anthropic tool use, Vercel AI SDK, or LangChain.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { airportTools } from 'airport-data-js/tools';
|
|
11
|
+
*
|
|
12
|
+
* // OpenAI function calling
|
|
13
|
+
* const response = await openai.chat.completions.create({
|
|
14
|
+
* model: 'gpt-4',
|
|
15
|
+
* messages: [...],
|
|
16
|
+
* tools: airportTools.map(t => ({ type: 'function', function: t })),
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Anthropic tool use
|
|
20
|
+
* const response = await anthropic.messages.create({
|
|
21
|
+
* model: 'claude-sonnet-4-20250514',
|
|
22
|
+
* messages: [...],
|
|
23
|
+
* tools: airportTools.map(t => ({
|
|
24
|
+
* name: t.name,
|
|
25
|
+
* description: t.description,
|
|
26
|
+
* input_schema: t.parameters,
|
|
27
|
+
* })),
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface ToolDefinition {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
parameters: {
|
|
35
|
+
type: 'object';
|
|
36
|
+
properties: Record<string, {
|
|
37
|
+
type: string;
|
|
38
|
+
description: string;
|
|
39
|
+
enum?: string[];
|
|
40
|
+
items?: {
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
default?: unknown;
|
|
44
|
+
minimum?: number;
|
|
45
|
+
maximum?: number;
|
|
46
|
+
}>;
|
|
47
|
+
required: string[];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare const airportTools: ToolDefinition[];
|