airport-data-js 3.1.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 +163 -36
- 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 +71 -32
- 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 -513
- 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
|
|
@@ -32,18 +54,21 @@ Each airport object contains the following fields:
|
|
|
32
54
|
{
|
|
33
55
|
iata: "SIN", // 3-letter IATA code
|
|
34
56
|
icao: "WSSS", // 4-letter ICAO code
|
|
35
|
-
time: "Asia/Singapore", //
|
|
57
|
+
time: "Asia/Singapore", // IANA timezone identifier
|
|
58
|
+
utc: 8, // Deprecated: July snapshot of the UTC offset; use getUtcOffset(code, date) instead
|
|
36
59
|
country_code: "SG", // 2-letter country code
|
|
37
60
|
continent: "AS", // 2-letter continent code (AS, EU, NA, SA, AF, OC, AN)
|
|
38
61
|
airport: "Singapore Changi Airport", // Airport name
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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)
|
|
64
|
+
latitude: 1.35019, // Latitude in decimal degrees
|
|
65
|
+
longitude: 103.994003, // Longitude in decimal degrees
|
|
66
|
+
elevation_ft: 22, // Elevation in feet, or null when unknown
|
|
42
67
|
type: "large_airport", // Airport type
|
|
43
|
-
scheduled_service:
|
|
68
|
+
scheduled_service: "TRUE", // "TRUE" or "FALSE" (has scheduled commercial service)
|
|
44
69
|
wikipedia: "https://en.wikipedia.org/wiki/Singapore_Changi_Airport",
|
|
45
70
|
website: "https://www.changiairport.com",
|
|
46
|
-
runway_length:
|
|
71
|
+
runway_length: 13200, // Longest runway in feet, or null when unknown
|
|
47
72
|
flightradar24_url: "https://www.flightradar24.com/airport/SIN",
|
|
48
73
|
radarbox_url: "https://www.radarbox.com/airport/WSSS",
|
|
49
74
|
flightaware_url: "https://www.flightaware.com/live/airport/WSSS"
|
|
@@ -98,13 +123,84 @@ const airports = await getAirportByIcao('EGLL');
|
|
|
98
123
|
```
|
|
99
124
|
|
|
100
125
|
#### `searchByName(query)`
|
|
101
|
-
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).
|
|
102
127
|
|
|
103
128
|
```javascript
|
|
104
129
|
const airports = await searchByName('Heathrow');
|
|
105
130
|
// Returns airports with 'Heathrow' in their name
|
|
106
131
|
```
|
|
107
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
|
+
|
|
108
204
|
### Geographic Functions
|
|
109
205
|
|
|
110
206
|
#### `findNearbyAirports(lat, lon, radiusKm)`
|
|
@@ -182,11 +278,11 @@ const longRunwayAirports = await findAirports({
|
|
|
182
278
|
```
|
|
183
279
|
|
|
184
280
|
#### `getAutocompleteSuggestions(query)`
|
|
185
|
-
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.
|
|
186
282
|
|
|
187
283
|
```javascript
|
|
188
284
|
const suggestions = await getAutocompleteSuggestions('Lon');
|
|
189
|
-
//
|
|
285
|
+
// LHR, LGW, STN, LTN, LCY, ...
|
|
190
286
|
```
|
|
191
287
|
|
|
192
288
|
#### `getAirportLinks(code)`
|
|
@@ -363,11 +459,20 @@ console.log(`Distance: ${Math.round(distance)} km`);
|
|
|
363
459
|
|
|
364
460
|
### Build an airport search interface
|
|
365
461
|
```javascript
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
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})`);
|
|
370
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)
|
|
371
476
|
```
|
|
372
477
|
|
|
373
478
|
### Filter airports by multiple criteria
|
|
@@ -474,51 +579,73 @@ npm run build
|
|
|
474
579
|
```
|
|
475
580
|
airport-data-js/
|
|
476
581
|
βββ src/
|
|
477
|
-
β βββ
|
|
478
|
-
β
|
|
479
|
-
βββ
|
|
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
|
|
586
|
+
β βββ tools.ts # LLM tool-definition exports
|
|
587
|
+
β βββ airports.data.json # Gzip+base64 columnar dataset (generated)
|
|
588
|
+
β βββ airports.lite.data.json # Gzip+base64 lite dataset (generated)
|
|
589
|
+
βββ .tsbuild/ # Intermediate tsc output (generated, not committed)
|
|
590
|
+
βββ lib/ # Node.js CJS (.js) and ESM (.mjs) build output
|
|
480
591
|
βββ dist/ # Browser build output
|
|
481
592
|
βββ data/
|
|
482
|
-
β
|
|
593
|
+
β βββ airports.csv # Raw source data
|
|
594
|
+
β βββ airports.json # Converted JSON (source of truth for compression)
|
|
483
595
|
βββ scripts/
|
|
484
|
-
β βββ
|
|
485
|
-
β βββ
|
|
486
|
-
β βββ
|
|
487
|
-
β
|
|
596
|
+
β βββ csv_to_json.ts # Converts airports.csv to airports.json
|
|
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
|
|
600
|
+
β βββ check_duplicates.ts # Validates no duplicate IATA/ICAO codes
|
|
601
|
+
β βββ extract_latest_changelog.ts # Extracts changelog for GitHub releases
|
|
602
|
+
β βββ benchmark.ts # Performance benchmarks
|
|
488
603
|
βββ tests/
|
|
489
|
-
β
|
|
604
|
+
β βββ index.test.ts # Vitest test suite
|
|
605
|
+
β βββ v4_1.test.ts # City search, time zone, lite and ESM tests
|
|
490
606
|
βββ webpack.node.cjs # Webpack config for Node.js bundle
|
|
491
|
-
|
|
607
|
+
βββ webpack.browser.cjs # Webpack config for browser bundles (full + lite)
|
|
608
|
+
βββ webpack.esm.cjs # Webpack config for the ESM bundles
|
|
609
|
+
βββ webpack.tools.cjs # Webpack config for the tools bundle
|
|
492
610
|
```
|
|
493
611
|
|
|
612
|
+
Scripts are plain TypeScript run directly via [`tsx`](https://github.com/privatenumber/tsx) (no separate compile step needed for dev tooling).
|
|
613
|
+
|
|
494
614
|
### Available Scripts
|
|
495
615
|
|
|
496
616
|
| Command | Description |
|
|
497
617
|
|---------|-------------|
|
|
498
|
-
| `npm test` | Run the
|
|
499
|
-
| `npm run build` | Build
|
|
618
|
+
| `npm test` | Run the Vitest test suite |
|
|
619
|
+
| `npm run build` | Build declarations, transpile, then bundle Node.js (`lib/`) and browser (`dist/`) output |
|
|
500
620
|
| `npm run build:lib` | Build only the Node.js bundle |
|
|
501
|
-
| `npm run build:dist` | Build only the browser
|
|
502
|
-
| `npm run
|
|
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) |
|
|
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 |
|
|
625
|
+
| `npm run generate:json` | Regenerate `data/airports.json` from `data/airports.csv` |
|
|
626
|
+
| `npm run generate:compressed` | Regenerate `src/airports.data.json` and `src/airports.lite.data.json` from `data/airports.json` |
|
|
627
|
+
| `npm run benchmark` | Run performance benchmarks against the built browser bundle |
|
|
503
628
|
|
|
504
629
|
### Development Workflow
|
|
505
630
|
|
|
506
631
|
1. **Create a branch** from `main` for your changes
|
|
507
|
-
2. **Make your changes** in `src/
|
|
508
|
-
3. **Add or update tests** in `tests/index.test.
|
|
632
|
+
2. **Make your changes** in `src/core.ts` or `data/airports.json`
|
|
633
|
+
3. **Add or update tests** in `tests/index.test.ts`
|
|
509
634
|
4. **Run tests** to make sure everything passes: `npm test`
|
|
510
635
|
5. **Build** to verify the bundles compile: `npm run build`
|
|
511
636
|
6. **Submit a pull request** against `main`
|
|
512
637
|
|
|
513
638
|
### Updating Airport Data
|
|
514
639
|
|
|
515
|
-
|
|
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:
|
|
516
643
|
|
|
517
|
-
1. Edit `data/airports.json` directly
|
|
518
|
-
2. Run `npm run
|
|
519
|
-
3. Run `
|
|
644
|
+
1. Edit `data/airports.json` directly (or run `npm run refresh:data -- --write`)
|
|
645
|
+
2. Run `npm run generate:compressed` to regenerate `src/airports.data.json`
|
|
646
|
+
3. Run `npm run check:duplicates` to validate the dataset (it reads the compressed file)
|
|
520
647
|
4. Run `npm test` to verify the changes
|
|
521
|
-
5. Submit a pull request with both the JSON and
|
|
648
|
+
5. Submit a pull request with both the JSON and generated data changes
|
|
522
649
|
|
|
523
650
|
## Publishing a New Version
|
|
524
651
|
|
|
@@ -532,7 +659,7 @@ Releases are automated via the [release workflow](.github/workflows/release.yml)
|
|
|
532
659
|
```
|
|
533
660
|
4. **Commit your changes** to `main`
|
|
534
661
|
5. **Push or merge to the `release` branch** -- this triggers the CI pipeline which will:
|
|
535
|
-
- Run tests across Node.js
|
|
662
|
+
- Run tests across Node.js 22.x and 24.x
|
|
536
663
|
- Run a security audit (`npm audit --audit-level=critical`)
|
|
537
664
|
- Check for duplicate airport codes
|
|
538
665
|
- Build the package
|