@aleksejdix/ally-bcp47
Version:
TypeScript package for working with BCP-47 language tags
48 lines (47 loc) • 1.67 kB
TypeScript
/**
* ISO 3166 country/region codes registry
* This file contains data for validating region subtags against the official registry
*/
/**
* Map of valid ISO 3166-1 alpha-2 country codes
* Key: country code, Value: country name
*/
export declare const ISO_3166_REGIONS: Record<string, string>;
/**
* Map of common incorrect region codes to their correct forms
* Key: incorrect code, Value: correct code
*/
export declare const REGION_CODE_CORRECTIONS: Record<string, string>;
/**
* Map of preferred values for region codes
* According to BCP-47 canonicalization rules
*/
export declare const REGION_PREFERRED_VALUES: Record<string, string>;
/**
* Checks if a region code is valid according to ISO 3166
*
* @param code The region code to validate
* @returns True if the code is valid, false otherwise
*/
export declare function isValidRegionCode(code: string): boolean;
/**
* Gets a suggestion for an invalid region code
*
* @param code The invalid region code
* @returns A suggested correction or undefined if no suggestion is available
*/
export declare function getSuggestedRegionCode(code: string): string | undefined;
/**
* Checks if a region code has a preferred value in the registry
*
* @param code The region code to check
* @returns True if the code has a preferred value, false otherwise
*/
export declare function hasPreferredRegionValue(code: string): boolean;
/**
* Gets the preferred value for a region code
*
* @param code The region code to get the preferred value for
* @returns The preferred value or the original code if no preferred value exists
*/
export declare function getRegionPreferredValue(code: string): string;