Files
info-target-mobile/constants/formatText.ts
Samandar Turgunboyev 22c1688781 register update
2026-03-18 17:56:26 +05:00

55 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const latinToCyrillicMap = [
["O'", "Ў"], ["o'", "ў"],
["G'", "Ғ"], ["g'", "ғ"],
["Sh", "Ш"], ["sh", "ш"],
["Ch", "Ч"], ["ch", "ч"],
["A", "А"], ["B", "Б"], ["D", "Д"], ["E", "Е"], ["F", "Ф"],
["G", "Г"], ["H", "Ҳ"], ["I", "И"], ["J", "Ж"], ["K", "К"],
["L", "Л"], ["M", "М"], ["N", "Н"], ["O", "О"], ["P", "П"],
["Q", "Қ"], ["R", "Р"], ["S", "С"], ["T", "Т"], ["U", "У"],
["V", "В"], ["X", "Х"], ["Y", "Й"], ["Z", "З"],
["a", "а"], ["b", "б"], ["d", "д"], ["e", "е"], ["f", "ф"],
["g", "г"], ["h", "ҳ"], ["i", "и"], ["j", "ж"], ["k", "к"],
["l", "л"], ["m", "м"], ["n", "н"], ["o", "о"], ["p", "п"],
["q", "қ"], ["r", "р"], ["s", "с"], ["t", "т"], ["u", "у"],
["v", "в"], ["x", "х"], ["y", "й"], ["z", "з"],
["'", ""] // apostrofni olib tashlaymiz
];
export function formatText(str: string | null) {
if (!str) return null;
let result = str;
for (let [latin, cyrillic] of latinToCyrillicMap) {
const regex = new RegExp(latin, "g");
result = result.replace(regex, cyrillic);
}
return result;
}
const cyrillicToLatinMap = [
["Ў", "O'"], ["ў", "o'"],
["Ғ", "G'"], ["ғ", "g'"],
["Ш", "Sh"], ["ш", "sh"],
["Ч", "Ch"], ["ч", "ch"],
["ё", "yo"], ["Ё", "YO"],
["А", "A"], ["Б", "B"], ["Д", "D"], ["Е", "E"], ["Ф", "F"],
["Г", "G"], ["Ҳ", "H"], ["И", "I"], ["Ж", "J"], ["К", "K"],
["Л", "L"], ["М", "M"], ["Н", "N"], ["О", "O"], ["П", "P"],
["Қ", "Q"], ["Р", "R"], ["С", "S"], ["Т", "T"], ["У", "U"],
["В", "V"], ["Х", "X"], ["Й", "Y"], ["З", "Z"],
["а", "a"], ["б", "b"], ["д", "d"], ["е", "e"], ["ф", "f"],
["г", "g"], ["ҳ", "h"], ["и", "i"], ["ж", "j"], ["к", "k"],
["л", "l"], ["м", "m"], ["н", "n"], ["о", "o"], ["п", "p"],
["қ", "q"], ["р", "r"], ["с", "s"], ["т", "t"], ["у", "u"],
["в", "v"], ["х", "x"], ["й", "y"], ["з", "z"],
];
export function formatTextToLatin(str: string | null) {
if (!str) return null;
let result = str;
for (let [cyrillic, latin] of cyrillicToLatinMap) {
const regex = new RegExp(cyrillic, "g");
result = result.replace(regex, latin);
}
return result;
}