-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.js
99 lines (80 loc) · 2.79 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const fs = require('fs')
const sortBy = require('lodash.sortby')
const { default: slugify } = require('slugify')
const airlines = require('./airlines.json')
const icons = fs.readdirSync(__dirname + '/icons')
const logos = fs.readdirSync(__dirname + '/logos')
const sorted = sortBy(airlines, (a) => a.name.toLowerCase())
const getFlagEmoji = (isoCode) => {
if (!isoCode) return '🏴'
if (isoCode === 'GB-ENG') {
return '🏴'
}
if (isoCode === 'GB-WLS') {
return '🏴'
}
if (isoCode === 'GB-SCT') {
return '🏴'
}
if (isoCode === 'GB-NIR') {
// The only official flag in Northern Ireland is the Union Flag of the United Kingdom.
return '🇬🇧'
}
return isoCode
.toUpperCase()
.replace(/./g, (char) =>
String.fromCodePoint(127397 + char.charCodeAt(0))
)
}
let md = `## Soaring Symbols: Airlines
This file provides an overview of the airlines included in the Soaring Symbols project and the types of logos available for each one.
> [!NOTE]
> * This list is not exhaustive and will be updated as new airlines are added to the project.
> * Flag next to airline name often means it's the national carrier.
| Airline | IATA | ICAO | Country | Alliance | Icon | Mono Icon | Logo | Mono Logo |
|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
`
sorted.forEach((airline) => {
const slug = slugify(airline.name, { lower: true })
const variations = []
const includedStates = []
if (icons.includes(`${slug}.svg`)) {
variations.push('icon')
includedStates.push('✓')
} else {
includedStates.push('')
}
if (icons.includes(`${slug}_mono.svg`)) {
variations.push('icon_mono')
includedStates.push('✓')
} else {
includedStates.push('')
}
if (logos.includes(`${slug}.svg`)) {
variations.push('logo')
includedStates.push('✓')
} else {
includedStates.push('')
}
if (logos.includes(`${slug}_mono.svg`)) {
variations.push('logo_mono')
includedStates.push('✓')
} else {
includedStates.push('')
}
airline.variations = variations
const { name, iata, website, icao, country, alliance, flag_carrier } =
airline
let airlineName = website ? `[${name}](${website})` : name
if (flag_carrier) {
const countries = country.split(',')
countries.forEach((code) => {
airlineName += ` ${getFlagEmoji(code)}`
})
}
md += `| ${airlineName} | ${iata} | ${icao} | ${country} | ${
alliance || ''
} | ${includedStates.join(' | ')} |\n`
})
fs.writeFileSync('airlines.json', JSON.stringify(sorted, null, 4))
fs.writeFileSync('AIRLINES.md', md)