Files
Investidor-V2/tools/country-iso-projection.mjs
T
2026-10-27 14:57:18 +02:00

12 lines
902 B
JavaScript

import fs from 'node:fs';
import crypto from 'node:crypto';
const source = new URL('../resources/data/iso3166.tab', import.meta.url);
const text = fs.readFileSync(source, 'utf8').replace(/\r\n/g, '\n');
const codes = text.split('\n').filter(line => line && !line.startsWith('#')).map(line => line.split('\t')[0]);
if (new Set(codes).size !== codes.length || codes.some(code => !/^[A-Z]{2}$/.test(code))) throw Error('Invalid existing ISO catalogue');
const hash = crypto.createHash('sha256').update(text).digest('hex');
fs.writeFileSync(new URL('../resources/js/lib/country-iso-codes.ts', import.meta.url),
'// Derived code projection of resources/data/iso3166.tab; keep the existing PHP catalogue authoritative.\n' +
'// Source SHA256 (LF): ' + hash + '; regenerate with node tools/country-iso-projection.mjs\n' +
"export const countryIsoCodes = '" + codes.join(' ') + "'.split(' ');\n");