acupedia-store-ui/src/constants/countries.ts

70 lines
3.6 KiB
TypeScript

import type { Currency } from '../types';
export interface CountryCode {
code: string;
label: string;
country: string;
currency: Currency;
minLength: number;
maxLength: number;
placeholder: string;
}
export const COUNTRY_CODES: CountryCode[] = [
{ code: '+91', label: '🇮🇳 +91', country: 'India', currency: 'INR', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' },
{ code: '+1', label: '🇺🇸 +1', country: 'United States', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' },
{ code: '+44', label: '🇬🇧 +44', country: 'United Kingdom', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' },
{ code: '+61', label: '🇦🇺 +61', country: 'Australia', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' },
{ code: '+49', label: '🇩🇪 +49', country: 'Germany', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' },
{ code: '+33', label: '🇫🇷 +33', country: 'France', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' },
{ code: '+81', label: '🇯🇵 +81', country: 'Japan', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' },
{ code: '+86', label: '🇨🇳 +86', country: 'China', currency: 'USD', minLength: 11, maxLength: 11, placeholder: '11-digit mobile number' },
{ code: '+971', label: '🇦🇪 +971', country: 'UAE', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' },
{ code: '+65', label: '🇸🇬 +65', country: 'Singapore', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' },
{ code: '+55', label: '🇧🇷 +55', country: 'Brazil', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' },
{ code: '+82', label: '🇰🇷 +82', country: 'South Korea', currency: 'USD', minLength: 9, maxLength: 11, placeholder: '9 to 11 digits' },
{ code: '+7', label: '🇷🇺 +7', country: 'Russia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' },
{ code: '+27', label: '🇿🇦 +27', country: 'South Africa', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' },
{ code: '+234', label: '🇳🇬 +234', country: 'Nigeria', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' },
];
export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91)
export const getCountryRuleByDialCode = (dialCode: string): CountryCode => {
return (
COUNTRY_CODES.find((c) => c.code === dialCode) || {
code: dialCode,
label: dialCode,
country: 'Other',
currency: 'USD',
minLength: 6,
maxLength: 15,
placeholder: 'Phone number',
}
);
};
export const getCountryRuleByName = (countryName: string): CountryCode => {
if (!countryName) return DEFAULT_COUNTRY;
const normalized = countryName.toLowerCase();
return (
COUNTRY_CODES.find(
(c) =>
c.country.toLowerCase() === normalized ||
(normalized.includes('india') && c.country === 'India') ||
(normalized.includes('united states') && c.country === 'United States') ||
(normalized.includes('united kingdom') && c.country === 'United Kingdom') ||
(normalized.includes('germany') && c.country === 'Germany') ||
(normalized.includes('australia') && c.country === 'Australia')
) || {
code: '+91',
label: '🇮🇳 +91',
country: countryName,
currency: normalized === 'india' ? 'INR' : 'USD',
minLength: 6,
maxLength: 15,
placeholder: 'Phone number',
}
);
};