UNPKG

language-codes-collection

Version:

[DEPRECATED] A clean, typed, and reliable dataset of ISO 639-1 and 639-2 language codes — complete with English names, native names, and writing scripts.

72 lines (69 loc) 2.29 kB
/** * ISO 639-1 language code (2-letter) * @example 'en' for English */ type ISO6391Code = string; /** * ISO 639-2 language code (3-letter) * @example 'eng' for English */ type ISO6392Code = string; /** * ISO 15924 script code * @example 'Latn' for Latin script */ type ScriptCode = string; /** * Represents a language with its codes and names */ interface Language { /** ISO 639-1 code (2-letter) */ code6391: ISO6391Code; /** ISO 639-2 code (3-letter) */ code6392: ISO6392Code; /** English name of the language */ englishName: string; /** Native name of the language */ nativeName: string; /** Primary script used to write the language (ISO 15924 code) */ script?: ScriptCode; } /** * Array of all supported languages */ declare const languages: Readonly<Language[]>; /** * Map of languages indexed by their ISO 639-1 code */ declare const languageMap: Readonly<Record<ISO6391Code, Language>>; /** * Get a language by its ISO 639-1 or ISO 639-2 code * @param code - The ISO 639-1 or ISO 639-2 language code * @returns The language object or undefined if not found */ declare function getLanguageByCode(code: string): Language | undefined; /** * Get the native name of a language by its ISO 639-1 or ISO 639-2 code * @param code - The ISO 639-1 or ISO 639-2 language code * @returns The native name or undefined if not found */ declare function getNativeName(code: string): string | undefined; /** * Get the script code of a language by its ISO 639-1 or ISO 639-2 code * @param code - The ISO 639-1 or ISO 639-2 language code * @returns The script code or undefined if not found or not specified */ declare function getScript(code: string): ScriptCode | undefined; /** * Check if a given code is a valid ISO 639-1 or ISO 639-2 language code * @param code - The code to check * @returns true if the code is valid, false otherwise */ declare function isValidLanguageCode(code: string): boolean; /** * Search for languages by name (case-insensitive) * @param query - The search query * @returns Array of matching languages */ declare function searchLanguageByName(query: string): Language[]; export { getLanguageByCode, getNativeName, getScript, isValidLanguageCode, languageMap, languages, searchLanguageByName };