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 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, // UTC offset in hours (DST-aware snapshot, not a fixed standard offset)
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
- // Returns up to 10 airports matching 'Lon' in name or IATA code
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
- // Get autocomplete suggestions
368
- const suggestions = await getAutocompleteSuggestions('New York');
369
- suggestions.forEach(airport => {
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
- β”‚ β”œβ”€β”€ index.ts # Library source code
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
- β”‚ └── airports.data.json # Gzip+base64 airport dataset (generated)
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 src/airports.data.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
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
- β”‚ └── index.test.ts # Vitest test suite
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 bundle
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 bundle |
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/index.ts` or `data/airports.json`
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
- 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:
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