UNPKG

language-scripts-map

Version:

[DEPRECATED] A reliable mapping of language codes to their default writing scripts (Latin, Cyrillic, Arabic, Devanagari, etc.).

78 lines (75 loc) 3.02 kB
/** * ISO 639-1 language code type * @example 'en', 'fr', 'de' */ type ISO6391Code = string; /** * ISO 15924 script code type * @example 'Latn', 'Cyrl', 'Arab', 'Deva' */ type ISO15924ScriptCode = string; /** * Interface for the language to script mapping data */ interface LanguageScriptMapData { [languageCode: ISO6391Code]: ISO15924ScriptCode; } /** * Interface for detailed language script information */ interface LanguageScriptDetail { defaultScript: ISO15924ScriptCode; scriptName?: string; otherScripts?: ISO15924ScriptCode[]; } /** * Interface for script grouping data */ interface ScriptGroups { RTL: ISO15924ScriptCode[]; LTR: ISO15924ScriptCode[]; } declare const languageScriptsMap: Readonly<Readonly<LanguageScriptMapData>>; declare const SCRIPT_GROUPS: Readonly<Readonly<ScriptGroups>>; /** * Gets the default script code for a given language code * @param languageCode - ISO 639-1 language code (case-insensitive) * @returns The ISO 15924 script code for the language, or undefined if not found * @example * getScriptByLanguageCode('en') // returns 'Latn' * getScriptByLanguageCode('ar') // returns 'Arab' * getScriptByLanguageCode('invalid') // returns undefined */ declare function getScriptByLanguageCode(languageCode: ISO6391Code | string): ISO15924ScriptCode | undefined; /** * Gets all language codes that use a given script * @param scriptCode - ISO 15924 script code (case-insensitive) * @returns Array of ISO 639-1 language codes that use the script * @example * getLanguagesByScript('Latn') // returns ['en', 'fr', 'de', ...] * getLanguagesByScript('Arab') // returns ['ar', 'fa', 'ur', ...] * getLanguagesByScript('invalid') // returns [] */ declare function getLanguagesByScript(scriptCode: ISO15924ScriptCode | string): ISO6391Code[]; /** * Checks if a given script code is valid (exists in the dataset) * @param scriptInput - ISO 15924 script code to check (case-insensitive) * @returns true if the script code exists in the dataset * @example * isValidScript('Latn') // returns true * isValidScript('Arab') // returns true * isValidScript('invalid') // returns false */ declare function isValidScript(scriptInput: string): boolean; /** * Checks if a given script is the default script for a language * @param languageCode - ISO 639-1 language code (case-insensitive) * @param scriptInput - ISO 15924 script code to check (case-insensitive) * @returns true if the script is the default for the language * @example * isScriptMatch('en', 'Latn') // returns true * isScriptMatch('ar', 'Arab') // returns true * isScriptMatch('en', 'Arab') // returns false */ declare function isScriptMatch(languageCode: ISO6391Code | string, scriptInput: ISO15924ScriptCode | string): boolean; export { type ISO15924ScriptCode, type ISO6391Code, type LanguageScriptDetail, type LanguageScriptMapData, SCRIPT_GROUPS, type ScriptGroups, getLanguagesByScript, getScriptByLanguageCode, isScriptMatch, isValidScript, languageScriptsMap };