-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
76 lines (67 loc) · 2.86 KB
/
Copy pathexample.ts
File metadata and controls
76 lines (67 loc) · 2.86 KB
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
import {
UnitedStates,
Germany,
Japan,
Brazil,
Australia,
France,
Canada,
Continent,
ContinentNames,
} from "./src/index";
console.log("=== TypeScript Countries Example ===\n");
// Example 1: United States
console.log("Example 1: United States");
const usa = new UnitedStates();
console.log(` English name: ${usa.en}`);
console.log(` ISO Alpha-2: ${usa.alpha2}`);
console.log(` ISO Alpha-3: ${usa.alpha3}`);
console.log(` Calling code: ${usa.callingCode}`);
console.log(` Capital: ${usa.capital}`);
console.log(` Continent: ${ContinentNames[usa.continent]}`);
console.log("");
// Example 2: Germany - Multi-language names
console.log("Example 2: Germany - Multi-language names");
const germany = new Germany();
console.log(` English: ${germany.getName("en")}`);
console.log(` German: ${germany.getName("de")}`);
console.log(` French: ${germany.getName("fr")}`);
console.log(` Spanish: ${germany.getName("es")}`);
console.log(` Italian: ${germany.getName("it")}`);
console.log(` Portuguese: ${germany.getName("pt")}`);
console.log(` Hungarian: ${germany.getName("hu")}`);
console.log("");
// Example 3: Japan - Convert to JSON
console.log("Example 3: Japan - Convert to JSON");
const japan = new Japan();
console.log(JSON.stringify(japan.toJSON(), null, 2));
console.log("");
// Example 4: Multiple countries comparison
console.log("Example 4: Country Comparison Table");
const countries = [
new UnitedStates(),
new Canada(),
new Brazil(),
new Germany(),
new France(),
new Japan(),
new Australia(),
];
console.log("┌─────────────────────┬──────┬─────────┬──────────────┬──────────────────┐");
console.log("│ Country │ Code │ Calling │ Capital │ Continent │");
console.log("├─────────────────────┼──────┼─────────┼──────────────┼──────────────────┤");
countries.forEach((country) => {
const name = country.en.padEnd(19);
const code = country.alpha2.padEnd(4);
const calling = country.callingCode.padEnd(7);
const capital = country.capital.padEnd(12);
const continent = ContinentNames[country.continent].padEnd(16);
console.log(`│ ${name} │ ${code} │ ${calling} │ ${capital} │ ${continent} │`);
});
console.log("└─────────────────────┴──────┴────────┴──────────────┴──────────────────┘");
console.log("");
// Example 5: All continents
console.log("Example 5: Continents");
Object.entries(ContinentNames).forEach(([code, name]) => {
console.log(` ${code}: ${name}`);
});