Skip to content

Commit

Permalink
fix the translit func
Browse files Browse the repository at this point in the history
  • Loading branch information
khashashin committed May 26, 2024
1 parent 4a683b0 commit 61096e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions __tests__/translit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ describe('apply', () => {
const expected = 'q̇egina Q̇egina q̇egina Q̇egina q̇Egina Q̇Egina q̇Egina Q̇Egina Q̇EGINA Q̇egina';
expect(apply(text)).toBe(expected);
});
it('should transliterate a text correctly', () => {
const text = "еара еАра еарА еАрА ЕАра ЕАрА ЕАРА Еара";
const expected = 'yeara yeAra yearA yeArA YEAra YEArA YEARA Yeara';
expect(apply(text)).toBe(expected);
});

it('should replace standalone Cyrillic "а" with "ə"', () => {
expect(apply('дӏахь а доьгӏна')).toBe('djaẋ ə döġna');
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@ce/transliteration",
"version": "0.2.5",
"version": "0.2.6",
"exports": "./translit.ts"
}
4 changes: 2 additions & 2 deletions translit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ export function applyToWord(word: string): string {
}
} else if (key === 'е' || key === 'Е') {
if (i === 0) {
match = key === 'е' ? 'ye' : 'Ye'; // 'е' at the start of the word
match = key === 'е' ? 'ye' : (nextLetter && nextLetter.toUpperCase() === nextLetter ? 'YE' : 'Ye'); // 'е' at the start of the word
} else if (i > 0) {
const preConsonant = i > 1 ? word.substring(i - 2, i).toLowerCase() : '';
if ((preLetter === 'ъ') && (i < 2 || preConsonant !== 'къ')) {
// 'е' following 'ъ' that does not follow 'къ'
match = key === 'е' ? 'ye' : (nextLetter.toUpperCase() === nextLetter ? 'YE' : 'Ye');
match = key === 'е' ? 'ye' : (nextLetter && nextLetter.toUpperCase() === nextLetter ? 'YE' : 'Ye');
} else {
match = translitMap[key]; // Regular transliteration for 'е'
}
Expand Down

0 comments on commit 61096e2

Please sign in to comment.