@aleksejdix/ally-bcp47
Version:
TypeScript package for working with BCP-47 language tags
71 lines (70 loc) • 2.55 kB
TypeScript
/**
* ISO 639 language codes registry
* This file contains data for validating language subtags against the official registry
*/
/**
* Map of valid ISO 639-1/639-2/639-3 language codes
* Key: language code, Value: language name
*/
export declare const ISO_639_LANGUAGES: Record<string, string>;
/**
* Map of common incorrect language codes to their correct forms
* Key: incorrect code, Value: correct code
*/
export declare const LANGUAGE_CODE_CORRECTIONS: Record<string, string>;
/**
* Map of preferred values for language codes
* According to BCP-47 canonicalization rules
*/
export declare const LANGUAGE_PREFERRED_VALUES: Record<string, string>;
/**
* Extended language subtags (ISO 639-3 codes used as extlang)
* These can appear as extlang subtags after a macrolanguage
*/
export declare const EXTENDED_LANGUAGE_SUBTAGS: string[];
/**
* Map of extlang subtags to their preferred values
*/
export declare const EXTLANG_PREFERRED_VALUES: Record<string, string>;
/**
* Checks if a language code is valid according to ISO 639
*
* @param code The language code to validate
* @returns True if the code is valid, false otherwise
*/
export declare function isValidLanguageCode(code: string): boolean;
/**
* Gets a suggestion for an invalid language code
*
* @param code The invalid language code
* @returns A suggested correction or undefined if no suggestion is available
*/
export declare function getSuggestedLanguageCode(code: string): string | undefined;
/**
* Checks if a language code has a preferred value in the registry
*
* @param code The language code to check
* @returns True if the code has a preferred value, false otherwise
*/
export declare function hasPreferredLanguageValue(code: string): boolean;
/**
* Gets the preferred value for a language code
*
* @param code The language code to get the preferred value for
* @returns The preferred value or the original code if no preferred value exists
*/
export declare function getLanguagePreferredValue(code: string): string;
/**
* Checks if a code is an extended language subtag
*
* @param code The code to check
* @returns True if the code is an extended language subtag, false otherwise
*/
export declare function isExtendedLanguageSubtag(code: string): boolean;
/**
* Gets the preferred value for an extlang subtag
*
* @param code The extlang code to get the preferred value for
* @returns The preferred value or the original code if no preferred value exists
*/
export declare function getExtlangPreferredValue(code: string): string;