add generateCountryOptions.ts

This commit is contained in:
turnoffthiscomputer
2024-10-26 11:10:28 +02:00
parent 792a1a454f
commit 5e8a8f9be6
2 changed files with 26 additions and 0 deletions

View File

@@ -17,6 +17,8 @@
"axios": "^1.7.2",
"buffer": "^6.0.3",
"chai": "^4.3.8",
"country-emoji": "^1.5.6",
"country-iso-3-to-2": "^1.1.1",
"elliptic": "^6.5.5",
"fs": "^0.0.1-security",
"js-sha1": "^0.7.0",

View File

@@ -0,0 +1,24 @@
import { countryCodes } from '../constants/constants';
import getCountryISO2 from "country-iso-3-to-2";
import { flag } from 'country-emoji';
import fs from 'fs';
import path from 'path';
try {
console.log('Generating country options...');
const countryOptions = Object.keys(countryCodes).map((countryCode, index) => ({
countryCode,
countryName: countryCodes[countryCode as keyof typeof countryCodes],
flagEmoji: flag(getCountryISO2(countryCode)),
index,
}));
const outputPath = path.join(__dirname, './countryOptions.json');
fs.writeFileSync(outputPath, JSON.stringify(countryOptions, null, 2));
console.log(`Generated country options at ${outputPath}`);
} catch (error) {
console.error('Error generating country options:', error);
process.exit(1);
}