airline-codes 1.0.2 → 1.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/convert.js CHANGED
@@ -9,7 +9,7 @@ var readStream = fs.createReadStream('airlines.dat');
9
9
  var writeStream = fs.createWriteStream('airlines.json');
10
10
 
11
11
  var transformer = csv.transform(function(data) {
12
- return _.object(columns, data);
12
+ return _.zipObject(columns, data);
13
13
  });
14
14
 
15
15
  readStream
package/normalize.js ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * normalize.js
3
+ *
4
+ * Applies corrections to airlines.dat after fetching upstream OpenFlights data.
5
+ * Upstream (jpatokal/openflights) uses different country name conventions and
6
+ * has some data quality issues that this project has historically corrected.
7
+ *
8
+ * Run: node normalize.js
9
+ * Reads airlines.dat, applies corrections, writes airlines.dat in-place.
10
+ */
11
+ var csv = require('csv');
12
+ var fs = require('fs');
13
+
14
+ // Country name corrections: upstream value -> our preferred value
15
+ var COUNTRY_CORRECTIONS = {
16
+ 'Macao': 'Macau',
17
+ 'Republic of Korea': 'South Korea',
18
+ "Democratic People's Republic of Korea": 'North Korea',
19
+ 'Russian Federation': 'Russia',
20
+ 'Syrian Arab Republic': 'Syria',
21
+ 'Hong Kong SAR of China': 'Hong Kong',
22
+ 'Canadian Territories': 'Canada',
23
+ 'Macedonia': 'North Macedonia',
24
+ 'Myanmar': 'Myanmar (Burma)',
25
+ 'Burma': 'Myanmar (Burma)',
26
+ 'Congo (Kinshasa)': 'Democratic Republic of the Congo',
27
+ 'Congo (Brazzaville)': 'Republic of the Congo',
28
+ };
29
+
30
+ // Per-ID field corrections for data corruption and specific known fixes.
31
+ // Keys are airline IDs (as strings). Values are objects with field overrides.
32
+ // Fields: name, alias, iata, icao, callsign, country, active
33
+ var ID_CORRECTIONS = {
34
+ // Alaska Airlines: upstream has country="ALASKA" (callsign leaked into country field)
35
+ '439': { country: 'United States' },
36
+ // Dragonair: upstream has country="DRAGON" (callsign leaked into country field)
37
+ '2056': { country: 'Hong Kong' },
38
+ // Defunct/duplicate airlines incorrectly marked active upstream:
39
+ '2988': { active: 'N' }, // Japan Airlines Domestic (dup of JAL, same ICAO JAL)
40
+ '3384': { active: 'N' }, // Malmo Aviation (defunct)
41
+ '3386': { active: 'N' }, // Malmö Aviation (dup of above, same ICAO SCW)
42
+ '4264': { active: 'N' }, // Royal Nepal Airlines (defunct, replaced by Nepal Airlines)
43
+ '4560': { active: 'N' }, // Swissair (defunct, dup of Swiss Intl, same ICAO SWR)
44
+ };
45
+
46
+ var columns = ['id', 'name', 'alias', 'iata', 'icao', 'callsign', 'country', 'active'];
47
+
48
+ var content = fs.readFileSync('airlines.dat', 'utf8');
49
+ var rows = [];
50
+ var changed = 0;
51
+
52
+ csv.parse(content, function(err, records) {
53
+ if (err) throw err;
54
+
55
+ records.forEach(function(row) {
56
+ var id = row[0];
57
+ var original = row.slice();
58
+
59
+ // Apply country name corrections
60
+ var countryIdx = 6;
61
+ if (COUNTRY_CORRECTIONS[row[countryIdx]]) {
62
+ row[countryIdx] = COUNTRY_CORRECTIONS[row[countryIdx]];
63
+ }
64
+
65
+ // Apply per-ID corrections
66
+ if (ID_CORRECTIONS[id]) {
67
+ var fixes = ID_CORRECTIONS[id];
68
+ Object.keys(fixes).forEach(function(field) {
69
+ var idx = columns.indexOf(field);
70
+ if (idx !== -1) row[idx] = fixes[field];
71
+ });
72
+ }
73
+
74
+ if (row.join(',') !== original.join(',')) changed++;
75
+ rows.push(row);
76
+ });
77
+
78
+ // Re-serialize as CSV matching the original dat format
79
+ csv.stringify(rows, function(err, output) {
80
+ if (err) throw err;
81
+ fs.writeFileSync('airlines.dat', output, 'utf8');
82
+ console.log('Normalized ' + changed + ' rows in airlines.dat');
83
+ });
84
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "airline-codes",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Airline codes (IATA) and information pulled from OpenFlights.org.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,6 +18,10 @@
18
18
  ],
19
19
  "author": "Nissan Pow <npow@uwaterloo.ca>",
20
20
  "license": "ISC",
21
+ "publishConfig": {
22
+ "provenance": true,
23
+ "access": "public"
24
+ },
21
25
  "bugs": {
22
26
  "url": "https://github.com/npow/airline-codes/issues"
23
27
  },
@@ -25,7 +29,7 @@
25
29
  "dependencies": {
26
30
  "JSONStream": "^1.0.4",
27
31
  "backbone": "^1.1.2",
28
- "csv": "^0.4.5",
29
- "lodash": "^2.4.2"
32
+ "csv": "^5.1.3",
33
+ "lodash": "^4.17.21"
30
34
  }
31
35
  }
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules/