Files
thebet365/packages/shared/scripts/generate-phone-countries.mjs
Mars db28390be9 feat(player): 接入创蓝短信手机注册与登录页优化
新增 SMS 验证码注册、8 国手机号选择与 Redis 频控;优化登录/注册 UI 及图形验证码样式。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-12 10:25:59 +08:00

38 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { all } from 'country-codes-list';
const __dirname = dirname(fileURLToPath(import.meta.url));
const outPath = join(__dirname, '../src/phone-dial-codes.json');
/** 平台开放注册/短信的国家ISO 3166-1 alpha-2 */
const ALLOWED_PHONE_ISO = ['MY', 'SG', 'IN', 'AU', 'TH', 'VN', 'BD', 'TW'];
/** 平台常用市场置顶(须为 ALLOWED_PHONE_ISO 子集) */
const PINNED_ISO = ['MY', 'SG', 'IN', 'AU', 'TH', 'VN', 'BD', 'TW'];
const entries = all()
.filter((c) => c.countryCallingCode && c.countryCode && ALLOWED_PHONE_ISO.includes(c.countryCode))
.map((c) => ({
iso: c.countryCode,
dial: c.countryCallingCode,
nameEn: c.countryNameEn,
nameLocal: c.countryNameLocal || c.countryNameEn,
flag: c.flag || '',
region: c.region || '',
}))
.sort((a, b) => {
const pa = PINNED_ISO.indexOf(a.iso);
const pb = PINNED_ISO.indexOf(b.iso);
if (pa !== -1 || pb !== -1) {
if (pa === -1) return 1;
if (pb === -1) return -1;
return pa - pb;
}
return a.nameEn.localeCompare(b.nameEn, 'en');
});
writeFileSync(outPath, `${JSON.stringify(entries, null, 2)}\n`, 'utf8');
console.log(`Wrote ${entries.length} countries to ${outPath}`);