airport-data-js 1.0.6 → 3.0.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 CHANGED
@@ -1,174 +1,448 @@
1
- # airport-data-js
1
+ # Airport Data JS
2
2
 
3
- A comprehensive library providing easy retrieval of airport data based on IATA, ICAO, city codes, country codes, and continents. Ideal for developers building applications related to aviation, travel, and geography.
3
+ A comprehensive JavaScript library for retrieving airport information by IATA codes, ICAO codes, and various other criteria. This library provides easy access to a large dataset of airports worldwide with detailed information including coordinates, timezone, type, and external links.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install airport-data-js
9
+ ```
4
10
 
5
- #### NPM: https://www.npmjs.com/package/airport-data-js
6
-
7
11
  ## Features
8
12
 
9
- - Retrieve airport data using IATA code.
10
- - Retrieve airport data using ICAO code.
11
- - Fetch data using city codes.
12
- - Fetch data using country codes.
13
- - Retrieve data based on continents.
14
- - Built-in error handling for invalid input formats.
15
- - Efficiently packaged with minimized and gzipped data.
16
- - **Comprehensive Data Access**: Retrieve airport data using IATA code, ICAO code, city codes, country codes, and continents.
17
- - **Unique Link Integration**: The first library to provide direct links to [FlightRadar24](https://www.flightradar24.com/), [Radarbox](https://www.radarbox.com/), and [FlightAware](https://www.flightaware.com/) for each airport, giving users immediate access to live flight tracking and airport data.
18
- - 9143 Aiports in total.
19
-
20
- ## Updates from 1.0.4 to 1.0.6
21
- - Added 500+ aiports
22
- - Fixed cities
23
- - Added Wikipedia links
13
+ - 🌍 Comprehensive airport database with worldwide coverage
14
+ - 🔍 Search by IATA codes, ICAO codes, country, continent, and more
15
+ - 📍 Geographic proximity search with customizable radius
16
+ - 🔗 External links to Wikipedia, airport websites, and flight tracking services
17
+ - 📏 Distance calculation between airports
18
+ - 🏷️ Filter by airport type (large_airport, medium_airport, small_airport, heliport, seaplane_base)
19
+ - 🕒 Timezone-based airport lookup
20
+ - 💡 Autocomplete suggestions for search interfaces
21
+ - 🎯 Advanced multi-criteria filtering
22
+ - 📊 Statistical analysis by country and continent
23
+ - 🔢 Bulk operations for multiple airports
24
+ - ✅ Code validation utilities
25
+ - 🎚️ Airport ranking by runway length and elevation
24
26
 
25
- ## Installation
27
+ ## Airport Data Structure
26
28
 
27
- You can install `airport-data-js` using npm:
29
+ Each airport object contains the following fields:
28
30
 
29
- ```bash
30
- npm install airport-data-js
31
+ ```javascript
32
+ {
33
+ iata: "SIN", // 3-letter IATA code
34
+ icao: "WSSS", // 4-letter ICAO code
35
+ time: "Asia/Singapore", // Timezone identifier
36
+ country_code: "SG", // 2-letter country code
37
+ continent: "AS", // 2-letter continent code (AS, EU, NA, SA, AF, OC, AN)
38
+ airport: "Singapore Changi Airport", // Airport name
39
+ latitude: "1.35019", // Latitude coordinate
40
+ longitude: "103.994003", // Longitude coordinate
41
+ elevation: "22", // Elevation in feet
42
+ type: "large_airport", // Airport type
43
+ scheduled_service: true, // Has scheduled commercial service
44
+ wikipedia: "https://en.wikipedia.org/wiki/Singapore_Changi_Airport",
45
+ website: "https://www.changiairport.com",
46
+ runway_length: "13200", // Longest runway in feet
47
+ flightradar24_url: "https://www.flightradar24.com/airport/SIN",
48
+ radarbox_url: "https://www.radarbox.com/airport/WSSS",
49
+ flightaware_url: "https://www.flightaware.com/live/airport/WSSS"
50
+ }
31
51
  ```
32
52
 
33
- For detailed instructions on how to use this library in different environments, please refer to the following links:
34
-
35
- - [Node.js Instructions](https://github.com/aashishvanand/airport-data-js/blob/nodejs-sample/README.md)
36
- - [React Instructions](https://github.com/aashishvanand/airport-data-js/blob/reactjs-sample/README.md)
37
-
38
- ## Usage
39
-
40
- Here's how you can use the library:
41
-
42
- ```javascript
43
- const airportData = require('airport-data-js');
44
-
45
- // Retrieve airport data using IATA code
46
- const airportByIATA = airportData.getAirportByIata("AAA");
47
- console.log(airportByIATA);
48
-
49
- // Retrieve airport data using ICAO code
50
- const airportByICAO = airportData.getAirportByIcao("NTGA");
51
- console.log(airportByICAO);
52
-
53
- // Fetch data using city codes
54
- const airportByCityCode = airportData.getAirportByCityCode("NYC");
55
- console.log(airportByCityCode);
56
-
57
- // Fetch data using country codes
58
- const airportByCountryCode = airportData.getAirportByCountryCode("US");
59
- console.log(airportByCountryCode);
60
-
61
- // Retrieve data based on continents
62
- const airportByContinent = airportData.getAirportByContinent("AS");
63
- console.log(airportByContinent);
64
-
65
-
66
- ```
67
-
68
- ## Example Data Fields
69
-
70
- For Chennai International Airport:
71
-
72
- | Field Name | Data |
73
- |----------------------|----------------------------------------------------------|
74
- | IATA | MAA |
75
- | ICAO | VOMM |
76
- | Time Zone | Asia/Kolkata |
77
- | City Code | MAA |
78
- | Country Code | IN |
79
- | Name | Chennai International Airport |
80
- | Latitude | 12.99 |
81
- | Longitude | 80.1693 |
82
- | Altitude (in feet) | 52 |
83
- | State | Tamil Nadu |
84
- | City | Chennai |
85
- | County | Kancheepuram |
86
- | State Code | Tamil Nadu |
87
- | Airport Type | large_airport |
88
- | Continent | AS |
89
- | State Abbreviation | IN-TN |
90
- | International | TRUE |
91
- | Wikipedia Link | [Wikipedia](https://en.wikipedia.org/wiki/Chennai_International_Airport)|
92
- | Official Website | [Chennai Airport](http://chennaiairport.com) |
93
- | Location ID | 12513629 |
94
- | Phone Number | 044-2340551 |
95
- | Runway Length (in meters) | 10050 |
96
- | Flightradar24 | [Flightradar24](https://www.flightradar24.com/airport/MAA)|
97
- | Radarbox | [Radarbox](https://www.radarbox.com/airport/VOMM) |
98
- | Flightaware Link | [Flightaware](https://www.flightaware.com/live/airport/VOMM)|
99
-
100
- ### Singapore Changi Airport:
101
-
102
- | Field Name | Data |
103
- |----------------------|----------------------------------------------------------|
104
- | IATA | SIN |
105
- | ICAO | WSSS |
106
- | Time Zone | Asia/Singapore |
107
- | City Code | SIN |
108
- | Country Code | SG |
109
- | Name | Singapore Changi Airport |
110
- | Latitude | 1.35019 |
111
- | Longitude | 103.994 |
112
- | Altitude (in feet) | 22 |
113
- | State | Singapore |
114
- | City | Singapore |
115
- | County | Singapore |
116
- | State Code | South East |
117
- | Airport Type | large_airport |
118
- | Continent | AS |
119
- | State Abbreviation | SG-04 |
120
- | International | TRUE |
121
- | Wikipedia Link | [Wikipedia](https://en.wikipedia.org/wiki/Singapore_Changi_Airport)|
122
- | Official Website | [Changi Airport](http://www.changiairport.com/) |
123
- | Location ID | 12517525 |
124
- | Phone Number | (65) 6542 1122 |
125
- | Runway Length (in meters) | 13200 |
126
- | Flightradar24 | [Flightradar24](https://www.flightradar24.com/airport/SIN)|
127
- | Radarbox | [Radarbox](https://www.radarbox.com/airport/WSSS) |
128
- | Flightaware | [Flightaware](https://www.flightaware.com/live/airport/WSSS)|
129
-
130
-
131
- ## Running the Project Locally
132
-
133
- 1. Clone the repository:
53
+ ## Basic Usage
134
54
 
135
- ```bash
136
- git clone https://github.com/aashishvanand/airport-data-js.git
55
+ ```javascript
56
+ const {
57
+ getAirportByIata,
58
+ getAirportByIcao,
59
+ searchByName,
60
+ findNearbyAirports
61
+ } = require('airport-data-js');
62
+
63
+ // Get airport by IATA code
64
+ const [airport] = await getAirportByIata('SIN');
65
+ console.log(airport.airport); // "Singapore Changi Airport"
66
+
67
+ // Get airport by ICAO code
68
+ const [airport] = await getAirportByIcao('WSSS');
69
+ console.log(airport.country_code); // "SG"
70
+
71
+ // Search airports by name
72
+ const airports = await searchByName('Singapore');
73
+ console.log(airports.length); // Multiple airports matching "Singapore"
74
+
75
+ // Find nearby airports (within 50km of coordinates)
76
+ const nearby = await findNearbyAirports(1.35019, 103.994003, 50);
77
+ console.log(nearby); // Airports near Singapore Changi
137
78
  ```
138
79
 
139
- 2. Change into the cloned directory:
80
+ ## API Reference
140
81
 
141
- ```bash
142
- cd airport-data-js
82
+ ### Core Search Functions
83
+
84
+ #### `getAirportByIata(iataCode)`
85
+ Finds airports by their 3-letter IATA code.
86
+
87
+ ```javascript
88
+ const airports = await getAirportByIata('LHR');
89
+ // Returns array of airports with IATA code 'LHR'
143
90
  ```
144
91
 
145
- 3. Install the necessary dependencies:
92
+ #### `getAirportByIcao(icaoCode)`
93
+ Finds airports by their 4-character ICAO code.
146
94
 
147
- ```bash
148
- npm install
95
+ ```javascript
96
+ const airports = await getAirportByIcao('EGLL');
97
+ // Returns array of airports with ICAO code 'EGLL'
149
98
  ```
150
99
 
151
- 4. To bundle the source code using Webpack:
100
+ #### `searchByName(query)`
101
+ Searches for airports by name (case-insensitive, minimum 2 characters).
152
102
 
153
- ```bash
154
- npm run build
103
+ ```javascript
104
+ const airports = await searchByName('Heathrow');
105
+ // Returns airports with 'Heathrow' in their name
155
106
  ```
156
107
 
157
- 5. To run tests:
108
+ ### Geographic Functions
158
109
 
159
- ```bash
160
- npm test
110
+ #### `findNearbyAirports(lat, lon, radiusKm)`
111
+ Finds airports within a specified radius of given coordinates.
112
+
113
+ ```javascript
114
+ const nearby = await findNearbyAirports(51.5074, -0.1278, 100);
115
+ // Returns airports within 100km of London coordinates
116
+ ```
117
+
118
+ #### `calculateDistance(code1, code2)`
119
+ Calculates the great-circle distance between two airports using IATA or ICAO codes.
120
+
121
+ ```javascript
122
+ const distance = await calculateDistance('LHR', 'JFK');
123
+ // Returns distance in kilometers (approximately 5540)
124
+ ```
125
+
126
+ ### Filtering Functions
127
+
128
+ #### `getAirportByCountryCode(countryCode)`
129
+ Finds all airports in a specific country.
130
+
131
+ ```javascript
132
+ const usAirports = await getAirportByCountryCode('US');
133
+ // Returns all airports in the United States
134
+ ```
135
+
136
+ #### `getAirportByContinent(continentCode)`
137
+ Finds all airports on a specific continent.
138
+
139
+ ```javascript
140
+ const asianAirports = await getAirportByContinent('AS');
141
+ // Returns all airports in Asia
142
+ // Continent codes: AS, EU, NA, SA, AF, OC, AN
143
+ ```
144
+
145
+ #### `getAirportsByType(type)`
146
+ Finds airports by their type.
147
+
148
+ ```javascript
149
+ const largeAirports = await getAirportsByType('large_airport');
150
+ // Available types: large_airport, medium_airport, small_airport, heliport, seaplane_base
151
+
152
+ // Convenience search for all airports
153
+ const allAirports = await getAirportsByType('airport');
154
+ // Returns large_airport, medium_airport, and small_airport
155
+ ```
156
+
157
+ #### `getAirportsByTimezone(timezone)`
158
+ Finds all airports within a specific timezone.
159
+
160
+ ```javascript
161
+ const londonAirports = await getAirportsByTimezone('Europe/London');
162
+ // Returns airports in London timezone
163
+ ```
164
+
165
+ ### Advanced Functions
166
+
167
+ #### `findAirports(filters)`
168
+ Finds airports matching multiple criteria.
169
+
170
+ ```javascript
171
+ // Find large airports in Great Britain with scheduled service
172
+ const airports = await findAirports({
173
+ country_code: 'GB',
174
+ type: 'large_airport',
175
+ has_scheduled_service: true
176
+ });
177
+
178
+ // Find airports with minimum runway length
179
+ const longRunwayAirports = await findAirports({
180
+ min_runway_ft: 10000
181
+ });
182
+ ```
183
+
184
+ #### `getAutocompleteSuggestions(query)`
185
+ Provides autocomplete suggestions for search interfaces (returns max 10 results).
186
+
187
+ ```javascript
188
+ const suggestions = await getAutocompleteSuggestions('Lon');
189
+ // Returns up to 10 airports matching 'Lon' in name or IATA code
190
+ ```
191
+
192
+ #### `getAirportLinks(code)`
193
+ Gets external links for an airport using IATA or ICAO code.
194
+
195
+ ```javascript
196
+ const links = await getAirportLinks('SIN');
197
+ // Returns:
198
+ // {
199
+ // website: "https://www.changiairport.com",
200
+ // wikipedia: "https://en.wikipedia.org/wiki/Singapore_Changi_Airport",
201
+ // flightradar24: "https://www.flightradar24.com/airport/SIN",
202
+ // radarbox: "https://www.radarbox.com/airport/WSSS",
203
+ // flightaware: "https://www.flightaware.com/live/airport/WSSS"
204
+ // }
205
+ ```
206
+
207
+ ### Statistical & Analytical Functions
208
+
209
+ #### `getAirportStatsByCountry(countryCode)`
210
+ Gets comprehensive statistics about airports in a specific country.
211
+
212
+ ```javascript
213
+ const stats = await getAirportStatsByCountry('US');
214
+ // Returns:
215
+ // {
216
+ // total: 5432,
217
+ // byType: {
218
+ // large_airport: 139,
219
+ // medium_airport: 467,
220
+ // small_airport: 4826
221
+ // },
222
+ // withScheduledService: 606,
223
+ // averageRunwayLength: 5234,
224
+ // averageElevation: 1245,
225
+ // timezones: ['America/New_York', 'America/Chicago', ...]
226
+ // }
227
+ ```
228
+
229
+ #### `getAirportStatsByContinent(continentCode)`
230
+ Gets comprehensive statistics about airports on a specific continent.
231
+
232
+ ```javascript
233
+ const stats = await getAirportStatsByContinent('AS');
234
+ // Returns statistics including count by type, by country,
235
+ // scheduled service count, average runway length, elevation, and timezones
236
+ ```
237
+
238
+ #### `getLargestAirportsByContinent(continentCode, limit, sortBy)`
239
+ Gets the largest airports on a continent by runway length or elevation.
240
+
241
+ ```javascript
242
+ // Get top 5 airports in Asia by runway length
243
+ const airports = await getLargestAirportsByContinent('AS', 5, 'runway');
244
+
245
+ // Get top 10 airports in South America by elevation
246
+ const highAltitude = await getLargestAirportsByContinent('SA', 10, 'elevation');
247
+ ```
248
+
249
+ ### Bulk Operations
250
+
251
+ #### `getMultipleAirports(codes)`
252
+ Fetches multiple airports by their IATA or ICAO codes in one call.
253
+
254
+ ```javascript
255
+ const airports = await getMultipleAirports(['SIN', 'LHR', 'JFK', 'WSSS']);
256
+ // Returns array of airport objects (null for codes not found)
257
+ // Efficiently fetches multiple airports at once
258
+ ```
259
+
260
+ #### `calculateDistanceMatrix(codes)`
261
+ Calculates distances between all pairs of airports in a list.
262
+
263
+ ```javascript
264
+ const matrix = await calculateDistanceMatrix(['SIN', 'LHR', 'JFK']);
265
+ // Returns:
266
+ // {
267
+ // airports: [
268
+ // { code: 'SIN', name: 'Singapore Changi Airport', iata: 'SIN', icao: 'WSSS' },
269
+ // { code: 'LHR', name: 'London Heathrow Airport', iata: 'LHR', icao: 'EGLL' },
270
+ // { code: 'JFK', name: 'John F Kennedy International Airport', iata: 'JFK', icao: 'KJFK' }
271
+ // ],
272
+ // distances: {
273
+ // SIN: { SIN: 0, LHR: 10872, JFK: 15344 },
274
+ // LHR: { SIN: 10872, LHR: 0, JFK: 5540 },
275
+ // JFK: { SIN: 15344, LHR: 5540, JFK: 0 }
276
+ // }
277
+ // }
278
+ ```
279
+
280
+ #### `findNearestAirport(lat, lon, filters)`
281
+ Finds the single nearest airport to given coordinates, optionally with filters.
282
+
283
+ ```javascript
284
+ // Find nearest airport to coordinates
285
+ const nearest = await findNearestAirport(1.35019, 103.994003);
286
+ // Returns airport object with additional 'distance' field in km
287
+
288
+ // Find nearest large airport with scheduled service
289
+ const nearestHub = await findNearestAirport(1.35019, 103.994003, {
290
+ type: 'large_airport',
291
+ has_scheduled_service: true
292
+ });
293
+ ```
294
+
295
+ ### Validation & Utilities
296
+
297
+ #### `validateIataCode(code)`
298
+ Validates if an IATA code exists in the database.
299
+
300
+ ```javascript
301
+ const isValid = await validateIataCode('SIN'); // true
302
+ const isInvalid = await validateIataCode('XYZ'); // false
303
+ const isBadFormat = await validateIataCode('ABCD'); // false
304
+ ```
305
+
306
+ #### `validateIcaoCode(code)`
307
+ Validates if an ICAO code exists in the database.
308
+
309
+ ```javascript
310
+ const isValid = await validateIcaoCode('WSSS'); // true
311
+ const isInvalid = await validateIcaoCode('XXXX'); // false
312
+ ```
313
+
314
+ #### `getAirportCount(filters)`
315
+ Gets the count of airports matching the given filters without fetching all data.
316
+
317
+ ```javascript
318
+ // Get total airport count
319
+ const total = await getAirportCount();
320
+
321
+ // Get count of large airports in the US
322
+ const count = await getAirportCount({
323
+ country_code: 'US',
324
+ type: 'large_airport'
325
+ });
326
+ ```
327
+
328
+ #### `isAirportOperational(code)`
329
+ Checks if an airport has scheduled commercial service.
330
+
331
+ ```javascript
332
+ const operational = await isAirportOperational('SIN'); // true
333
+ const notOperational = await isAirportOperational('SOME_SMALL_AIRPORT'); // false
334
+ ```
335
+
336
+ ## Error Handling
337
+
338
+ All functions return promises and may throw errors for invalid input or when no data is found.
339
+
340
+ ```javascript
341
+ try {
342
+ const airport = await getAirportByIata('XYZ');
343
+ } catch (error) {
344
+ console.error(error.message); // "No data found for IATA code: XYZ"
345
+ }
346
+ ```
347
+
348
+ ## Examples
349
+
350
+ ### Find airports near a city
351
+ ```javascript
352
+ // Find airports within 100km of Paris
353
+ const parisAirports = await findNearbyAirports(48.8566, 2.3522, 100);
354
+ console.log(`Found ${parisAirports.length} airports near Paris`);
355
+ ```
356
+
357
+ ### Get flight distance
358
+ ```javascript
359
+ // Calculate distance between Singapore and London
360
+ const distance = await calculateDistance('SIN', 'LHR');
361
+ console.log(`Distance: ${Math.round(distance)} km`);
362
+ ```
363
+
364
+ ### Build an airport search interface
365
+ ```javascript
366
+ // Get autocomplete suggestions
367
+ const suggestions = await getAutocompleteSuggestions('New York');
368
+ suggestions.forEach(airport => {
369
+ console.log(`${airport.iata} - ${airport.airport}`);
370
+ });
371
+ ```
372
+
373
+ ### Filter airports by multiple criteria
374
+ ```javascript
375
+ // Find large airports in Asia with scheduled service
376
+ const asianHubs = await findAirports({
377
+ continent: 'AS',
378
+ type: 'large_airport',
379
+ has_scheduled_service: true
380
+ });
381
+ ```
382
+
383
+ ### Get airport statistics
384
+ ```javascript
385
+ // Get comprehensive statistics for US airports
386
+ const usStats = await getAirportStatsByCountry('US');
387
+ console.log(`Total airports: ${usStats.total}`);
388
+ console.log(`Large airports: ${usStats.byType.large_airport}`);
389
+ console.log(`Average runway length: ${usStats.averageRunwayLength} ft`);
390
+
391
+ // Get statistics for Asian airports
392
+ const asiaStats = await getAirportStatsByContinent('AS');
393
+ console.log(`Countries with airports: ${Object.keys(asiaStats.byCountry).length}`);
394
+ ```
395
+
396
+ ### Bulk operations
397
+ ```javascript
398
+ // Fetch multiple airports at once
399
+ const airports = await getMultipleAirports(['SIN', 'LHR', 'JFK', 'NRT']);
400
+ airports.forEach(airport => {
401
+ if (airport) {
402
+ console.log(`${airport.iata}: ${airport.airport}`);
403
+ }
404
+ });
405
+
406
+ // Calculate distance matrix for route planning
407
+ const matrix = await calculateDistanceMatrix(['SIN', 'LHR', 'JFK']);
408
+ console.log(`Distance from SIN to LHR: ${matrix.distances.SIN.LHR} km`);
409
+ console.log(`Distance from LHR to JFK: ${matrix.distances.LHR.JFK} km`);
410
+ ```
411
+
412
+ ### Validation utilities
413
+ ```javascript
414
+ // Validate airport codes before processing
415
+ const codes = ['SIN', 'XYZ', 'LHR', 'ABCD'];
416
+ for (const code of codes) {
417
+ const isValid = await validateIataCode(code);
418
+ console.log(`${code}: ${isValid ? 'Valid' : 'Invalid'}`);
419
+ }
420
+
421
+ // Check if airport is operational
422
+ const operational = await isAirportOperational('SIN');
423
+ console.log(`Singapore Changi is operational: ${operational}`);
424
+ ```
425
+
426
+ ### Find nearest airport
427
+ ```javascript
428
+ // Find nearest airport to current location
429
+ const nearest = await findNearestAirport(1.35019, 103.994003);
430
+ console.log(`Nearest airport: ${nearest.airport} (${nearest.distance} km away)`);
431
+
432
+ // Find nearest large airport with scheduled service
433
+ const nearestHub = await findNearestAirport(1.35019, 103.994003, {
434
+ type: 'large_airport',
435
+ has_scheduled_service: true
436
+ });
161
437
  ```
162
438
 
163
- ## Troubleshooting
439
+ ## Changelog
164
440
 
165
- 1. **Issue**: "Module not found: Error: Can't resolve 'babel-loader'".
166
- **Solution**: Ensure that you have installed all the necessary dependencies. If the issue persists, reinstall the library.
441
+ See [CHANGELOG.md](CHANGELOG.md) for the full version history and release notes.
167
442
 
168
- 2. **Issue**: "Error: Automatic publicPath is not supported in this browser".
169
- **Solution**: Ensure that you're using the library in a supported environment (Node.js or a modern browser).
443
+ ## Data Source
170
444
 
171
- If you encounter other issues, consider raising an issue on the [GitHub repository](https://github.com/aashishvanand/airport-data-js/issues).
445
+ This library uses a comprehensive dataset of worldwide airports with regular updates to ensure accuracy and completeness.
172
446
 
173
447
  ## License
174
448