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