All files / app/features/auth/verification countries.ts

100% Statements 7/7
50% Branches 1/2
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 182x                 12x 12x 12x   12x 2940x 16728x    
import { getCountries } from "react-phone-number-input";
 
export type CountryOption = { code: string; name: string };
 
/**
 * ISO 3166-1 alpha-2 codes with localized names, sorted for the given language.
 * The code list is borrowed from react-phone-number-input's metadata (already a
 * dependency) so we don't ship a second copy of the world.
 */
export function getLocalizedCountries(language: string): CountryOption[] {
  const displayNames = new Intl.DisplayNames([language], { type: "region", fallback: "code" });
  const collator = new Intl.Collator(language);
 
  return getCountries()
    .map((code) => ({ code, name: displayNames.of(code) ?? code }))
    .sort((a, b) => collator.compare(a.name, b.name));
}