File tree Expand file tree Collapse file tree 2 files changed +100
-1
lines changed
Expand file tree Collapse file tree 2 files changed +100
-1
lines changed Original file line number Diff line number Diff line change @@ -103,3 +103,98 @@ export const addPrefixForMobile = (number: string): string => {
103103 // If the phone number doesn't match the expected formats, return the original phone number
104104 return number ;
105105} ;
106+
107+ /**
108+ * Converts Greek text to Greeklish (Greek text written with Latin characters)
109+ * @param {string } text Greek text to be converted
110+ * @return {string } Converted Greeklish text
111+ */
112+ export const greeklish = ( text : string ) : string => {
113+ const letters : { [ key : string ] : string } = {
114+ Ά : "A" ,
115+ Α : "A" ,
116+ ά : "a" ,
117+ α : "a" ,
118+ Β : "B" ,
119+ β : "b" ,
120+ Γ : "G" ,
121+ γ : "g" ,
122+ Δ : "D" ,
123+ δ : "d" ,
124+ Έ : "E" ,
125+ Ε : "E" ,
126+ έ : "e" ,
127+ ε : "e" ,
128+ Ζ : "Z" ,
129+ ζ : "z" ,
130+ Ή : "H" ,
131+ Η : "H" ,
132+ ή : "h" ,
133+ η : "h" ,
134+ Θ : "Th" ,
135+ θ : "th" ,
136+ Ί : "I" ,
137+ Ι : "I" ,
138+ ί : "i" ,
139+ ι : "i" ,
140+ ΐ : "i" ,
141+ ϊ : "i" ,
142+ Κ : "K" ,
143+ κ : "k" ,
144+ Λ : "L" ,
145+ λ : "l" ,
146+ Μ : "M" ,
147+ μ : "m" ,
148+ Ν : "N" ,
149+ ν : "n" ,
150+ Ξ : "X" ,
151+ ξ : "x" ,
152+ Ό : "O" ,
153+ Ο : "O" ,
154+ ό : "o" ,
155+ ο : "o" ,
156+ Π : "P" ,
157+ π : "p" ,
158+ Ρ : "R" ,
159+ ρ : "r" ,
160+ Σ : "S" ,
161+ σ : "s" ,
162+ ς : "s" ,
163+ Τ : "T" ,
164+ τ : "t" ,
165+ Ύ : "Y" ,
166+ Υ : "Y" ,
167+ ύ : "y" ,
168+ υ : "y" ,
169+ ΰ : "y" ,
170+ ϋ : "y" ,
171+ Φ : "F" ,
172+ φ : "f" ,
173+ Χ : "Ch" ,
174+ χ : "ch" ,
175+ Ψ : "Ps" ,
176+ ψ : "ps" ,
177+ Ώ : "O" ,
178+ Ω : "O" ,
179+ ώ : "o" ,
180+ ω : "o" ,
181+ } ;
182+
183+ // Check if the text contains any Greek characters
184+ const regex = / [ Α - ώ ] / ;
185+ if ( ! regex . test ( text ) ) {
186+ return text ;
187+ }
188+
189+ let result = "" ;
190+
191+ for ( const character of text ) {
192+ if ( letters . hasOwnProperty ( character ) ) {
193+ result += letters [ character ] ;
194+ } else {
195+ result += character ;
196+ }
197+ }
198+
199+ return result ;
200+ } ;
You can’t perform that action at this time.
0 commit comments