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
package/README.md
CHANGED
|
@@ -8,10 +8,32 @@ A comprehensive JavaScript library for retrieving airport information by IATA co
|
|
|
8
8
|
npm install airport-data-js
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
### Entry points
|
|
12
|
+
|
|
13
|
+
| Import | Contents | Size (minified) |
|
|
14
|
+
|--------|----------|-----------------|
|
|
15
|
+
| `airport-data-js` | Full dataset (~18,800 airports, all fields) | ~1.3 MB |
|
|
16
|
+
| `airport-data-js/lite` | Same API, only airports with an IATA code (~10,200), without the `wikipedia`/`website`/tracker URL fields; coordinates rounded to 4 decimals (~11 m) | ~540 KB |
|
|
17
|
+
| `airport-data-js/tools` | LLM tool definitions (JSON Schema) | ~12 KB |
|
|
18
|
+
|
|
19
|
+
Both CommonJS and ES modules are supported:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
// ESM (Node, Vite, Next.js, Deno, bundlers)
|
|
23
|
+
import { search, getLocalTime } from 'airport-data-js';
|
|
24
|
+
import { search as searchLite } from 'airport-data-js/lite';
|
|
25
|
+
|
|
26
|
+
// CommonJS
|
|
27
|
+
const { search, getLocalTime } = require('airport-data-js');
|
|
28
|
+
```
|
|
29
|
+
|
|
11
30
|
## Features
|
|
12
31
|
|
|
13
32
|
- π Comprehensive airport database with worldwide coverage
|
|
14
|
-
- π Search by IATA codes, ICAO codes, country, continent, and more
|
|
33
|
+
- π Search by IATA codes, ICAO codes, city, country, continent, and more
|
|
34
|
+
- ποΈ City-aware, ranked search: `search('New York')` returns JFK, EWR and LGA; metro codes like `NYC`/`LON`; accent-insensitive and typo-tolerant
|
|
35
|
+
- π°οΈ DST-aware local time and UTC offsets for any airport, using built-in `Intl` (no dependencies)
|
|
36
|
+
- π¦ ESM + CommonJS builds, plus a ~540 KB `lite` entry point
|
|
15
37
|
- π Geographic proximity search with customizable radius
|
|
16
38
|
- π External links to Wikipedia, airport websites, and flight tracking services
|
|
17
39
|
- π Distance calculation between airports
|
|
@@ -33,10 +55,12 @@ Each airport object contains the following fields:
|
|
|
33
55
|
iata: "SIN", // 3-letter IATA code
|
|
34
56
|
icao: "WSSS", // 4-letter ICAO code
|
|
35
57
|
time: "Asia/Singapore", // IANA timezone identifier
|
|
36
|
-
utc: 8, //
|
|
58
|
+
utc: 8, // Deprecated: July snapshot of the UTC offset; use getUtcOffset(code, date) instead
|
|
37
59
|
country_code: "SG", // 2-letter country code
|
|
38
60
|
continent: "AS", // 2-letter continent code (AS, EU, NA, SA, AF, OC, AN)
|
|
39
61
|
airport: "Singapore Changi Airport", // Airport name
|
|
62
|
+
city: "Singapore", // City/municipality served ("" when unknown)
|
|
63
|
+
city_code: "SIN", // IATA city/metro code, e.g. "NYC" for JFK/LGA/EWR ("" when unknown)
|
|
40
64
|
latitude: 1.35019, // Latitude in decimal degrees
|
|
41
65
|
longitude: 103.994003, // Longitude in decimal degrees
|
|
42
66
|
elevation_ft: 22, // Elevation in feet, or null when unknown
|
|
@@ -99,13 +123,84 @@ const airports = await getAirportByIcao('EGLL');
|
|
|
99
123
|
```
|
|
100
124
|
|
|
101
125
|
#### `searchByName(query)`
|
|
102
|
-
Searches for airports by name (case-insensitive, minimum 2 characters).
|
|
126
|
+
Searches for airports by name (case- and accent-insensitive, minimum 2 characters). For city-aware, ranked results use [`search`](#searchquery-options).
|
|
103
127
|
|
|
104
128
|
```javascript
|
|
105
129
|
const airports = await searchByName('Heathrow');
|
|
106
130
|
// Returns airports with 'Heathrow' in their name
|
|
107
131
|
```
|
|
108
132
|
|
|
133
|
+
### City & Ranked Search
|
|
134
|
+
|
|
135
|
+
#### `search(query, options)`
|
|
136
|
+
Unified, ranked search across codes, cities and names. This is the best default for search boxes.
|
|
137
|
+
|
|
138
|
+
Ranking: exact IATA > exact ICAO > IATA metro code (`NYC`, `LON`) > exact city > city prefix > name prefix > name word prefix > substring > typo-tolerant match. Within each tier, large airports with scheduled service come first. An exact city match also pulls in the other airports of that city's metro area (EWR is in "Newark" but belongs to `NYC`).
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
await search('New York'); // JFK, EWR, LGA, ...
|
|
142
|
+
await search('LON'); // LHR, LGW, STN, LTN, LCY, ...
|
|
143
|
+
await search('zurich'); // ZRH ("ZΓΌrich" also works)
|
|
144
|
+
await search('frankfrut'); // FRA (typo-tolerant, matchType: 'fuzzy')
|
|
145
|
+
await search('paris', { scheduledOnly: true, country_code: 'FR', limit: 3 });
|
|
146
|
+
|
|
147
|
+
const [best] = await search('heathrow');
|
|
148
|
+
console.log(best.iata, best.matchType); // "LHR" "name"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Options: `limit` (1-100, default 10), `scheduledOnly`, `types` (e.g. `['large_airport']`), `country_code`, `fuzzy` (default `true`).
|
|
152
|
+
|
|
153
|
+
#### `getAirportsByCity(city)`
|
|
154
|
+
Airports whose city matches (case- and accent-insensitive), major airports first. Qualified municipalities match their base name ("Paris (Orly, Val-de-Marne)" matches "Paris").
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
const airports = await getAirportsByCity('London');
|
|
158
|
+
console.log(airports[0].iata); // "LHR"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### `getAirportsByCityCode(cityCode)`
|
|
162
|
+
All airports in an IATA city/metropolitan area code.
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
await getAirportsByCityCode('NYC'); // JFK, EWR, LGA, ...
|
|
166
|
+
await getAirportsByCityCode('TYO'); // NRT, HND, ...
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Time Zone & Local Time
|
|
170
|
+
|
|
171
|
+
The `utc` field is a fixed July snapshot, so it is wrong for about half the year in regions with daylight saving time (JFK reads `-4`, but it is `-5` in winter). These functions use the airport's IANA time zone with the built-in `Intl` API instead. `date` can be a `Date`, epoch milliseconds, or an ISO string, and defaults to now. Each returns `null` for an unknown airport.
|
|
172
|
+
|
|
173
|
+
#### `getUtcOffset(code, date)`
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
await getUtcOffset('JFK', '2026-07-01T12:00:00Z'); // -4
|
|
177
|
+
await getUtcOffset('JFK', '2026-12-01T12:00:00Z'); // -5
|
|
178
|
+
await getUtcOffset('DEL'); // 5.5
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### `getLocalTime(code, date)`
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
await getLocalTime('LHR', '2026-07-01T12:00:00Z');
|
|
185
|
+
// {
|
|
186
|
+
// timeZone: 'Europe/London',
|
|
187
|
+
// iso: '2026-07-01T13:00:00+01:00',
|
|
188
|
+
// date: '2026-07-01',
|
|
189
|
+
// time: '13:00:00',
|
|
190
|
+
// utcOffset: 1,
|
|
191
|
+
// utcOffsetString: '+01:00',
|
|
192
|
+
// isDst: true
|
|
193
|
+
// }
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### `formatAirportTime(code, options)`
|
|
197
|
+
Formats a moment in the airport's local time. Accepts `date`, `locale` (default `en-US`) and any `Intl.DateTimeFormat` option; defaults to `{ dateStyle: 'medium', timeStyle: 'short' }`.
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
await formatAirportTime('NRT', { date: '2026-11-10T00:00:00Z' }); // "Nov 10, 2026, 9:00 AM"
|
|
201
|
+
await formatAirportTime('CDG', { locale: 'fr-FR', timeStyle: 'short' }); // "14:05"
|
|
202
|
+
```
|
|
203
|
+
|
|
109
204
|
### Geographic Functions
|
|
110
205
|
|
|
111
206
|
#### `findNearbyAirports(lat, lon, radiusKm)`
|
|
@@ -183,11 +278,11 @@ const longRunwayAirports = await findAirports({
|
|
|
183
278
|
```
|
|
184
279
|
|
|
185
280
|
#### `getAutocompleteSuggestions(query)`
|
|
186
|
-
Provides autocomplete suggestions for search interfaces (returns max 10 results).
|
|
281
|
+
Provides autocomplete suggestions for search interfaces (returns max 10 results). Uses the same ranking as `search` (without typo tolerance) and returns plain airport objects.
|
|
187
282
|
|
|
188
283
|
```javascript
|
|
189
284
|
const suggestions = await getAutocompleteSuggestions('Lon');
|
|
190
|
-
//
|
|
285
|
+
// LHR, LGW, STN, LTN, LCY, ...
|
|
191
286
|
```
|
|
192
287
|
|
|
193
288
|
#### `getAirportLinks(code)`
|
|
@@ -364,11 +459,20 @@ console.log(`Distance: ${Math.round(distance)} km`);
|
|
|
364
459
|
|
|
365
460
|
### Build an airport search interface
|
|
366
461
|
```javascript
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
console.log(`${airport.iata} - ${airport.airport}`);
|
|
462
|
+
const results = await search('New York', { scheduledOnly: true });
|
|
463
|
+
results.forEach(airport => {
|
|
464
|
+
console.log(`${airport.iata} - ${airport.airport} (${airport.city})`);
|
|
371
465
|
});
|
|
466
|
+
// JFK - John F. Kennedy International Airport (New York)
|
|
467
|
+
// EWR - Newark Liberty International Airport (Newark)
|
|
468
|
+
// LGA - LaGuardia Airport (New York)
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### Show local departure time
|
|
472
|
+
```javascript
|
|
473
|
+
const departure = '2026-12-24T15:30:00Z';
|
|
474
|
+
const local = await getLocalTime('JFK', departure);
|
|
475
|
+
console.log(`Departs ${local.time} local (UTC${local.utcOffsetString})`); // Departs 10:30:00 local (UTC-05:00)
|
|
372
476
|
```
|
|
373
477
|
|
|
374
478
|
### Filter airports by multiple criteria
|
|
@@ -475,25 +579,33 @@ npm run build
|
|
|
475
579
|
```
|
|
476
580
|
airport-data-js/
|
|
477
581
|
βββ src/
|
|
478
|
-
β βββ
|
|
582
|
+
β βββ core.ts # Library source code (all functions and types)
|
|
583
|
+
β βββ index.ts # Full entry point: registers the full dataset
|
|
584
|
+
β βββ lite.ts # Lite entry point: registers the lite dataset
|
|
585
|
+
β βββ state.ts # Holds the dataset registered by the entry point
|
|
479
586
|
β βββ tools.ts # LLM tool-definition exports
|
|
480
|
-
β
|
|
587
|
+
β βββ airports.data.json # Gzip+base64 columnar dataset (generated)
|
|
588
|
+
β βββ airports.lite.data.json # Gzip+base64 lite dataset (generated)
|
|
481
589
|
βββ .tsbuild/ # Intermediate tsc output (generated, not committed)
|
|
482
|
-
βββ lib/ # Node.js CJS build output
|
|
590
|
+
βββ lib/ # Node.js CJS (.js) and ESM (.mjs) build output
|
|
483
591
|
βββ dist/ # Browser build output
|
|
484
592
|
βββ data/
|
|
485
593
|
β βββ airports.csv # Raw source data
|
|
486
594
|
β βββ airports.json # Converted JSON (source of truth for compression)
|
|
487
595
|
βββ scripts/
|
|
488
596
|
β βββ csv_to_json.ts # Converts airports.csv to airports.json
|
|
489
|
-
β βββ compress_json.ts # Gzips airports.json into
|
|
597
|
+
β βββ compress_json.ts # Gzips airports.json into the full and lite payloads
|
|
598
|
+
β βββ refresh_ourairports.ts # Syncs with OurAirports: new airports, IATA codes, cities
|
|
599
|
+
β βββ build_esm_types.ts # Creates .d.mts declarations for the ESM exports
|
|
490
600
|
β βββ check_duplicates.ts # Validates no duplicate IATA/ICAO codes
|
|
491
601
|
β βββ extract_latest_changelog.ts # Extracts changelog for GitHub releases
|
|
492
602
|
β βββ benchmark.ts # Performance benchmarks
|
|
493
603
|
βββ tests/
|
|
494
|
-
β
|
|
604
|
+
β βββ index.test.ts # Vitest test suite
|
|
605
|
+
β βββ v4_1.test.ts # City search, time zone, lite and ESM tests
|
|
495
606
|
βββ webpack.node.cjs # Webpack config for Node.js bundle
|
|
496
|
-
βββ webpack.browser.cjs # Webpack config for browser
|
|
607
|
+
βββ webpack.browser.cjs # Webpack config for browser bundles (full + lite)
|
|
608
|
+
βββ webpack.esm.cjs # Webpack config for the ESM bundles
|
|
497
609
|
βββ webpack.tools.cjs # Webpack config for the tools bundle
|
|
498
610
|
```
|
|
499
611
|
|
|
@@ -506,16 +618,18 @@ Scripts are plain TypeScript run directly via [`tsx`](https://github.com/private
|
|
|
506
618
|
| `npm test` | Run the Vitest test suite |
|
|
507
619
|
| `npm run build` | Build declarations, transpile, then bundle Node.js (`lib/`) and browser (`dist/`) output |
|
|
508
620
|
| `npm run build:lib` | Build only the Node.js bundle |
|
|
509
|
-
| `npm run build:dist` | Build only the browser
|
|
621
|
+
| `npm run build:dist` | Build only the browser bundles |
|
|
622
|
+
| `npm run build:esm` | Build only the ESM bundles (`lib/*.mjs`) |
|
|
623
|
+
| `npm run refresh:data` | Diff against the latest OurAirports export (dry run; add `-- --write` to save, `-- --add FSH,BZJ` to force-add codes) |
|
|
510
624
|
| `npm run check:duplicates` | Validate the dataset: duplicate IATA/ICAO codes, coordinate ranges, continent/type enums, country code format, `scheduled_service`/`utc` types, plus a data-completeness report |
|
|
511
625
|
| `npm run generate:json` | Regenerate `data/airports.json` from `data/airports.csv` |
|
|
512
|
-
| `npm run generate:compressed` | Regenerate `src/airports.data.json` from `data/airports.json` |
|
|
626
|
+
| `npm run generate:compressed` | Regenerate `src/airports.data.json` and `src/airports.lite.data.json` from `data/airports.json` |
|
|
513
627
|
| `npm run benchmark` | Run performance benchmarks against the built browser bundle |
|
|
514
628
|
|
|
515
629
|
### Development Workflow
|
|
516
630
|
|
|
517
631
|
1. **Create a branch** from `main` for your changes
|
|
518
|
-
2. **Make your changes** in `src/
|
|
632
|
+
2. **Make your changes** in `src/core.ts` or `data/airports.json`
|
|
519
633
|
3. **Add or update tests** in `tests/index.test.ts`
|
|
520
634
|
4. **Run tests** to make sure everything passes: `npm test`
|
|
521
635
|
5. **Build** to verify the bundles compile: `npm run build`
|
|
@@ -523,9 +637,11 @@ Scripts are plain TypeScript run directly via [`tsx`](https://github.com/private
|
|
|
523
637
|
|
|
524
638
|
### Updating Airport Data
|
|
525
639
|
|
|
526
|
-
|
|
640
|
+
A [weekly workflow](.github/workflows/data-refresh.yml) runs `refresh:data` against OurAirports every Monday and opens a PR when something changed: new scheduled-service airports, newly assigned IATA codes on existing records, and city names. IATA codes that differ between the dataset and OurAirports are listed in the PR for review but never changed automatically. You can also run it manually from the Actions tab and pass extra codes to add.
|
|
641
|
+
|
|
642
|
+
To add or update airport entries by hand:
|
|
527
643
|
|
|
528
|
-
1. Edit `data/airports.json` directly
|
|
644
|
+
1. Edit `data/airports.json` directly (or run `npm run refresh:data -- --write`)
|
|
529
645
|
2. Run `npm run generate:compressed` to regenerate `src/airports.data.json`
|
|
530
646
|
3. Run `npm run check:duplicates` to validate the dataset (it reads the compressed file)
|
|
531
647
|
4. Run `npm test` to verify the changes
|