airport-data-js 4.0.0 β†’ 4.1.1

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
@@ -31,12 +53,15 @@ Each airport object contains the following fields:
31
53
  ```javascript
32
54
  {
33
55
  iata: "SIN", // 3-letter IATA code
34
- icao: "WSSS", // 4-letter ICAO code
56
+ icao: "WSSS", // 4-letter ICAO code ("" when unknown)
57
+ faa_code: "80F", // Optional: FAA/local identifier for airports without a 4-character ICAO code
35
58
  time: "Asia/Singapore", // IANA timezone identifier
36
- utc: 8, // UTC offset in hours (DST-aware snapshot, not a fixed standard offset)
59
+ utc: 8, // Deprecated: July snapshot of the UTC offset; use getUtcOffset(code, date) instead
37
60
  country_code: "SG", // 2-letter country code
38
61
  continent: "AS", // 2-letter continent code (AS, EU, NA, SA, AF, OC, AN)
39
62
  airport: "Singapore Changi Airport", // Airport name
63
+ city: "Singapore", // City/municipality served ("" when unknown)
64
+ city_code: "SIN", // IATA city/metro code, e.g. "NYC" for JFK/LGA/EWR ("" when unknown)
40
65
  latitude: 1.35019, // Latitude in decimal degrees
41
66
  longitude: 103.994003, // Longitude in decimal degrees
42
67
  elevation_ft: 22, // Elevation in feet, or null when unknown
@@ -80,6 +105,8 @@ console.log(nearby); // Airports near Singapore Changi
80
105
 
81
106
  ## API Reference
82
107
 
108
+ Code arguments (IATA, ICAO, country, continent, city, and mixed code lookups) are trimmed and accepted in any case, so `'lhr'`, `' LHR '` and `'LHR'` are equivalent.
109
+
83
110
  ### Core Search Functions
84
111
 
85
112
  #### `getAirportByIata(iataCode)`
@@ -99,21 +126,98 @@ const airports = await getAirportByIcao('EGLL');
99
126
  ```
100
127
 
101
128
  #### `searchByName(query)`
102
- Searches for airports by name (case-insensitive, minimum 2 characters).
129
+ Searches for airports by name (case- and accent-insensitive, minimum 2 characters). For city-aware, ranked results use [`search`](#searchquery-options).
103
130
 
104
131
  ```javascript
105
132
  const airports = await searchByName('Heathrow');
106
133
  // Returns airports with 'Heathrow' in their name
107
134
  ```
108
135
 
136
+ ### City & Ranked Search
137
+
138
+ #### `search(query, options)`
139
+ Unified, ranked search across codes, cities and names. This is the best default for search boxes.
140
+
141
+ 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`).
142
+
143
+ ```javascript
144
+ await search('New York'); // JFK, EWR, LGA, ...
145
+ await search('LON'); // LHR, LGW, STN, LTN, LCY, ...
146
+ await search('zurich'); // ZRH ("ZΓΌrich" also works)
147
+ await search('frankfrut'); // FRA (typo-tolerant, matchType: 'fuzzy')
148
+ await search('paris', { scheduledOnly: true, country_code: 'FR', limit: 3 });
149
+
150
+ const [best] = await search('heathrow');
151
+ console.log(best.iata, best.matchType); // "LHR" "name"
152
+ ```
153
+
154
+ Options: `limit` (1-100, default 10), `scheduledOnly`, `types` (e.g. `['large_airport']`), `country_code`, `fuzzy` (default `true`).
155
+
156
+ Queries are matched against Latin-script, ASCII-folded names, so accented and non-decomposing letters work (`Zürich`, `Tromsø`). Non-Latin queries (e.g. `東京`) are not transliterated and return no results.
157
+
158
+ #### `getAirportsByCity(city)`
159
+ Airports whose city matches (case- and accent-insensitive), major airports first. Qualified municipalities match their base name ("Paris (Orly, Val-de-Marne)" matches "Paris").
160
+
161
+ ```javascript
162
+ const airports = await getAirportsByCity('London');
163
+ console.log(airports[0].iata); // "LHR"
164
+ ```
165
+
166
+ #### `getAirportsByCityCode(cityCode)`
167
+ All airports in an IATA city/metropolitan area code.
168
+
169
+ ```javascript
170
+ await getAirportsByCityCode('NYC'); // JFK, EWR, LGA, ...
171
+ await getAirportsByCityCode('TYO'); // NRT, HND, ...
172
+ ```
173
+
174
+ ### Time Zone & Local Time
175
+
176
+ 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.
177
+
178
+ #### `getUtcOffset(code, date)`
179
+
180
+ ```javascript
181
+ await getUtcOffset('JFK', '2026-07-01T12:00:00Z'); // -4
182
+ await getUtcOffset('JFK', '2026-12-01T12:00:00Z'); // -5
183
+ await getUtcOffset('DEL'); // 5.5
184
+ ```
185
+
186
+ #### `getLocalTime(code, date)`
187
+
188
+ ```javascript
189
+ await getLocalTime('LHR', '2026-07-01T12:00:00Z');
190
+ // {
191
+ // timeZone: 'Europe/London',
192
+ // iso: '2026-07-01T13:00:00+01:00',
193
+ // date: '2026-07-01',
194
+ // time: '13:00:00',
195
+ // utcOffset: 1,
196
+ // utcOffsetString: '+01:00',
197
+ // isDst: true
198
+ // }
199
+ ```
200
+
201
+ #### `formatAirportTime(code, options)`
202
+ 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' }`.
203
+
204
+ ```javascript
205
+ await formatAirportTime('NRT', { date: '2026-11-10T00:00:00Z' }); // "Nov 10, 2026, 9:00 AM"
206
+ await formatAirportTime('CDG', { locale: 'fr-FR', timeStyle: 'short' }); // "14:05"
207
+ ```
208
+
109
209
  ### Geographic Functions
110
210
 
111
- #### `findNearbyAirports(lat, lon, radiusKm)`
112
- Finds airports within a specified radius of given coordinates.
211
+ #### `findNearbyAirports(lat, lon, radiusKm, limit?)`
212
+ Finds airports within a specified radius of given coordinates, nearest first. Each result has a `distance` field in kilometers.
113
213
 
114
214
  ```javascript
115
215
  const nearby = await findNearbyAirports(51.5074, -0.1278, 100);
116
- // Returns airports within 100km of London coordinates
216
+ // Returns airports within 100km of London coordinates, sorted by distance
217
+ console.log(nearby[0].iata, nearby[0].distance);
218
+
219
+ // Optional limit
220
+ const closest = await findNearbyAirports(51.5074, -0.1278, 100, 5);
117
221
  ```
118
222
 
119
223
  #### `calculateDistance(code1, code2)`
@@ -143,13 +247,16 @@ const asianAirports = await getAirportByContinent('AS');
143
247
  // Continent codes: AS, EU, NA, SA, AF, OC, AN
144
248
  ```
145
249
 
146
- #### `getAirportsByType(type)`
250
+ #### `getAirportsByType(type, limit?)`
147
251
  Finds airports by their type.
148
252
 
149
253
  ```javascript
150
254
  const largeAirports = await getAirportsByType('large_airport');
151
255
  // Available types: large_airport, medium_airport, small_airport, heliport, seaplane_base
152
256
 
257
+ // Optional limit
258
+ const firstTen = await getAirportsByType('large_airport', 10);
259
+
153
260
  // Convenience search for all airports
154
261
  const allAirports = await getAirportsByType('airport');
155
262
  // Returns large_airport, medium_airport, and small_airport
@@ -182,12 +289,14 @@ const longRunwayAirports = await findAirports({
182
289
  });
183
290
  ```
184
291
 
292
+ Filter values are type-checked: numbers must be finite (`NaN`/`Infinity` throw), `country_code`/`continent`/`iata`/`icao`/`city_code` accept any case, `type` is case-insensitive, and `scheduled_service` accepts a boolean or `"TRUE"`/`"FALSE"`. `undefined` values are ignored; an unknown key or a non-object argument throws.
293
+
185
294
  #### `getAutocompleteSuggestions(query)`
186
- Provides autocomplete suggestions for search interfaces (returns max 10 results).
295
+ 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
296
 
188
297
  ```javascript
189
298
  const suggestions = await getAutocompleteSuggestions('Lon');
190
- // Returns up to 10 airports matching 'Lon' in name or IATA code
299
+ // LHR, LGW, STN, LTN, LCY, ...
191
300
  ```
192
301
 
193
302
  #### `getAirportLinks(code)`
@@ -364,11 +473,20 @@ console.log(`Distance: ${Math.round(distance)} km`);
364
473
 
365
474
  ### Build an airport search interface
366
475
  ```javascript
367
- // Get autocomplete suggestions
368
- const suggestions = await getAutocompleteSuggestions('New York');
369
- suggestions.forEach(airport => {
370
- console.log(`${airport.iata} - ${airport.airport}`);
476
+ const results = await search('New York', { scheduledOnly: true });
477
+ results.forEach(airport => {
478
+ console.log(`${airport.iata} - ${airport.airport} (${airport.city})`);
371
479
  });
480
+ // JFK - John F. Kennedy International Airport (New York)
481
+ // EWR - Newark Liberty International Airport (Newark)
482
+ // LGA - LaGuardia Airport (New York)
483
+ ```
484
+
485
+ ### Show local departure time
486
+ ```javascript
487
+ const departure = '2026-12-24T15:30:00Z';
488
+ const local = await getLocalTime('JFK', departure);
489
+ console.log(`Departs ${local.time} local (UTC${local.utcOffsetString})`); // Departs 10:30:00 local (UTC-05:00)
372
490
  ```
373
491
 
374
492
  ### Filter airports by multiple criteria
@@ -475,25 +593,35 @@ npm run build
475
593
  ```
476
594
  airport-data-js/
477
595
  β”œβ”€β”€ src/
478
- β”‚ β”œβ”€β”€ index.ts # Library source code
596
+ β”‚ β”œβ”€β”€ core.ts # Library source code (all functions and types)
597
+ β”‚ β”œβ”€β”€ index.ts # Full entry point: registers the full dataset
598
+ β”‚ β”œβ”€β”€ lite.ts # Lite entry point: registers the lite dataset
599
+ β”‚ β”œβ”€β”€ state.ts # Holds the dataset registered by the entry point
479
600
  β”‚ β”œβ”€β”€ tools.ts # LLM tool-definition exports
480
- β”‚ └── airports.data.json # Gzip+base64 airport dataset (generated)
601
+ β”‚ β”œβ”€β”€ airports.data.json # Gzip+base64 columnar dataset (generated)
602
+ β”‚ └── airports.lite.data.json # Gzip+base64 lite dataset (generated)
481
603
  β”œβ”€β”€ .tsbuild/ # Intermediate tsc output (generated, not committed)
482
- β”œβ”€β”€ lib/ # Node.js CJS build output
604
+ β”œβ”€β”€ lib/ # Node.js CJS (.js) and ESM (.mjs) build output
483
605
  β”œβ”€β”€ dist/ # Browser build output
484
606
  β”œβ”€β”€ data/
485
607
  β”‚ β”œβ”€β”€ airports.csv # Raw source data
486
608
  β”‚ └── airports.json # Converted JSON (source of truth for compression)
487
609
  β”œβ”€β”€ scripts/
488
610
  β”‚ β”œβ”€β”€ csv_to_json.ts # Converts airports.csv to airports.json
489
- β”‚ β”œβ”€β”€ compress_json.ts # Gzips airports.json into src/airports.data.json
611
+ β”‚ β”œβ”€β”€ compress_json.ts # Gzips airports.json into the full and lite payloads
612
+ β”‚ β”œβ”€β”€ refresh_ourairports.ts # Syncs with OurAirports: new airports, IATA codes, cities
613
+ β”‚ β”œβ”€β”€ upgrade_https.ts # Upgrades http:// links to https:// where the host supports TLS
614
+ β”‚ β”œβ”€β”€ build_payload.ts # Writes the shared lib/payload.*.js dataset modules
615
+ β”‚ β”œβ”€β”€ build_esm_types.ts # Creates .d.mts declarations for the ESM exports
490
616
  β”‚ β”œβ”€β”€ check_duplicates.ts # Validates no duplicate IATA/ICAO codes
491
617
  β”‚ β”œβ”€β”€ extract_latest_changelog.ts # Extracts changelog for GitHub releases
492
618
  β”‚ └── benchmark.ts # Performance benchmarks
493
619
  β”œβ”€β”€ tests/
494
- β”‚ └── index.test.ts # Vitest test suite
620
+ β”‚ β”œβ”€β”€ index.test.ts # Vitest test suite
621
+ β”‚ └── v4_1.test.ts # City search, time zone, lite and ESM tests
495
622
  β”œβ”€β”€ webpack.node.cjs # Webpack config for Node.js bundle
496
- β”œβ”€β”€ webpack.browser.cjs # Webpack config for browser bundle
623
+ β”œβ”€β”€ webpack.browser.cjs # Webpack config for browser bundles (full + lite)
624
+ β”œβ”€β”€ webpack.esm.cjs # Webpack config for the ESM bundles
497
625
  └── webpack.tools.cjs # Webpack config for the tools bundle
498
626
  ```
499
627
 
@@ -506,16 +634,20 @@ Scripts are plain TypeScript run directly via [`tsx`](https://github.com/private
506
634
  | `npm test` | Run the Vitest test suite |
507
635
  | `npm run build` | Build declarations, transpile, then bundle Node.js (`lib/`) and browser (`dist/`) output |
508
636
  | `npm run build:lib` | Build only the Node.js bundle |
509
- | `npm run build:dist` | Build only the browser bundle |
637
+ | `npm run build:dist` | Build only the browser bundles |
638
+ | `npm run build:esm` | Build only the ESM bundles (`lib/*.mjs`) |
639
+ | `npm run build:payload` | Write the shared dataset modules (`lib/payload.full.js`, `lib/payload.lite.js`) |
640
+ | `npm run refresh:data` | Diff against the latest OurAirports export (dry run; add `-- --write` to save, `-- --add FSH,BZJ` to force-add codes) |
641
+ | `npm run upgrade:https` | Probe `http://` links and upgrade hosts that support HTTPS (dry run; add `-- --write` to save) |
510
642
  | `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
643
  | `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` |
644
+ | `npm run generate:compressed` | Regenerate `src/airports.data.json` and `src/airports.lite.data.json` from `data/airports.json` |
513
645
  | `npm run benchmark` | Run performance benchmarks against the built browser bundle |
514
646
 
515
647
  ### Development Workflow
516
648
 
517
649
  1. **Create a branch** from `main` for your changes
518
- 2. **Make your changes** in `src/index.ts` or `data/airports.json`
650
+ 2. **Make your changes** in `src/core.ts` or `data/airports.json`
519
651
  3. **Add or update tests** in `tests/index.test.ts`
520
652
  4. **Run tests** to make sure everything passes: `npm test`
521
653
  5. **Build** to verify the bundles compile: `npm run build`
@@ -523,13 +655,18 @@ Scripts are plain TypeScript run directly via [`tsx`](https://github.com/private
523
655
 
524
656
  ### Updating Airport Data
525
657
 
526
- If you are adding or updating airport entries:
658
+ A [weekly workflow](.github/workflows/data-refresh.yml) compares the dataset with OurAirports every Monday without changing it, and opens an issue (label `data-refresh`) when there is something to review: new scheduled-service airports (with links to their OurAirports pages), newly assigned IATA codes on existing records, continent changes, city updates, and IATA codes that differ between the two. Airports are never added automatically. After checking them, run the workflow from the Actions tab with `mode: apply` and the checked IATA codes in `add` (e.g. `FSH,BZJ`); it opens a PR with those airports plus the routine updates. IATA mismatches are never changed automatically.
659
+
660
+ Locally, `npm run refresh:data -- --no-auto-add` lists new airports as candidates instead of adding them, and `--add FSH,BZJ --write` adds only the listed ones.
661
+
662
+ To add or update airport entries by hand:
527
663
 
528
- 1. Edit `data/airports.json` directly
529
- 2. Run `npm run generate:compressed` to regenerate `src/airports.data.json`
530
- 3. Run `npm run check:duplicates` to validate the dataset (it reads the compressed file)
531
- 4. Run `npm test` to verify the changes
532
- 5. Submit a pull request with both the JSON and generated data changes
664
+ 1. Edit `data/airports.json` directly (or run `npm run refresh:data -- --write`)
665
+ 2. Optionally run `npm run upgrade:https -- --write` to upgrade links on hosts that serve HTTPS
666
+ 3. Run `npm run generate:compressed` to regenerate `src/airports.data.json`
667
+ 4. Run `npm run check:duplicates` to validate the dataset (it reads the compressed file)
668
+ 5. Run `npm test` to verify the changes
669
+ 6. Submit a pull request with both the JSON and generated data changes
533
670
 
534
671
  ## Publishing a New Version
535
672