mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-06 14:22:15 +00:00
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import * as i18nIsoCountries from 'i18n-iso-countries';
|
|
import { CountryCode, getCountries, getCountryCallingCode } from 'libphonenumber-js';
|
|
|
|
export interface CountryPhoneCode {
|
|
countryCode: string;
|
|
countryName: string;
|
|
countryCallingCode: string;
|
|
}
|
|
|
|
@Injectable()
|
|
export class CountryCallingCodesService {
|
|
constructor(private translateService: TranslateService) {}
|
|
|
|
public getCountryCallingCodes(): CountryPhoneCode[] {
|
|
const currentLang = this.translateService.currentLang ?? 'en';
|
|
const countryPhoneCodes = getCountries()
|
|
.filter((code: CountryCode) => i18nIsoCountries.getName(code.toString(), currentLang))
|
|
.map((code: CountryCode) => {
|
|
return <CountryPhoneCode>{
|
|
countryCode: code,
|
|
countryName: i18nIsoCountries.getName(code.toString(), currentLang),
|
|
countryCallingCode: getCountryCallingCode(code),
|
|
};
|
|
})
|
|
.sort((a, b) => a.countryName.localeCompare(b.countryName));
|
|
return countryPhoneCodes;
|
|
}
|
|
}
|