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 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", // Timezone identifier
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
- latitude: "1.35019", // Latitude coordinate
40
- longitude: "103.994003", // Longitude coordinate
41
- elevation: "22", // Elevation in feet
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: true, // Has scheduled commercial 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: "13200", // Longest runway in feet
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
- // Returns up to 10 airports matching 'Lon' in name or IATA code
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
- // Get autocomplete suggestions
367
- const suggestions = await getAutocompleteSuggestions('New York');
368
- suggestions.forEach(airport => {
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
- β”‚ β”œβ”€β”€ index.js # Library source code
478
- β”‚ └── airports.compressed # Compressed airport dataset
479
- β”œβ”€β”€ lib/ # Node.js CJS build output
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
- β”‚ └── airports.json # Raw airport data (source of truth)
593
+ β”‚ β”œβ”€β”€ airports.csv # Raw source data
594
+ β”‚ └── airports.json # Converted JSON (source of truth for compression)
483
595
  β”œβ”€β”€ scripts/
484
- β”‚ β”œβ”€β”€ compress_json.js # Compresses airports.json for distribution
485
- β”‚ β”œβ”€β”€ check_duplicates.js # Validates no duplicate IATA/ICAO codes
486
- β”‚ β”œβ”€β”€ extract_latest_changelog.js # Extracts changelog for GitHub releases
487
- β”‚ └── benchmark.js # Performance benchmarks
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
- β”‚ └── index.test.js # Jest test suite
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
- └── webpack.browser.cjs # Webpack config for browser bundle
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 Jest test suite |
499
- | `npm run build` | Build both Node.js (`lib/`) and browser (`dist/`) bundles |
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 bundle |
502
- | `npm run check:duplicates` | Check for duplicate airport codes in the dataset |
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/index.js` or `data/airports.json`
508
- 3. **Add or update tests** in `tests/index.test.js`
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
- If you are adding or updating airport entries:
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 check:duplicates` to ensure no duplicate IATA/ICAO codes
519
- 3. Run `node scripts/compress_json.js` to regenerate the compressed dataset
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 compressed data changes
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 20.x, 22.x, and 24.x
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