Skip to content

Commit

Permalink
Add prettier to development dependancies and make everithing prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
measles committed Sep 8, 2024
1 parent 1631c98 commit d2f2980
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
run: npx prettier . --check

- name: Run unit tests
run: npx jest
run: npx jest
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
>>> Cyr2Lat.convert_classic("Але лёс склаўся так, што хрусць - і папалам!")
'Ale los skłaŭsia tak, szto chruść - i papałam!'
```

Асноўныя параметры працы бібліятэкі:
- Ніякага выпраўлення памылак.
- Са зменаў правапісу толькі яўна пазначаецца транзітыўная мяккасць зычных, астатняе пры канвертацыі захоўваецца роўна з тымі ж асаблівасцямі правапісу і памылкамі, якія былі да канвертацыі.
- Кірылічныя сімвалы, якім адпавядае некалькі лацінскіх сімвалаў пры трансляцыі вялікіх літар маюць вялікай толькі першую літару ў пары (Chleb, Jan), што можа быць праблемай у выпадках, калі гэта не слова з вялікай літары ці абрэвіятура, а проста нешта напісанае КАПСАМ. Бо атрымаецца ChLEB, JaN.

- Ніякага выпраўлення памылак.
- Са зменаў правапісу толькі яўна пазначаецца транзітыўная мяккасць зычных, астатняе пры канвертацыі захоўваецца роўна з тымі ж асаблівасцямі правапісу і памылкамі, якія былі да канвертацыі.
- Кірылічныя сімвалы, якім адпавядае некалькі лацінскіх сімвалаў пры трансляцыі вялікіх літар маюць вялікай толькі першую літару ў пары (Chleb, Jan), што можа быць праблемай у выпадках, калі гэта не слова з вялікай літары ці абрэвіятура, а проста нешта напісанае КАПСАМ. Бо атрымаецца ChLEB, JaN.

## Анлайн канвертар

У якасці ўзору ўжывання бібліятэкі ці анлайн канвертара створанага на яе аснове магу прапанаваць паглядзець на сайт [latynkatar.org](https://latynkatar.org). Зыходнікі даступныя [тут](https://github.com/measles/latynkatar_site).

## Ліцэнзія

Copyright Andrej Zacharevicz, 2023

[![LGPL v3.0](https://www.gnu.org/graphics/lgplv3-with-text-154x68.png)](https://github.com/measles/latynkatar/blob/main/LICENSE) ад [GNU](https://www.gnu.org/licenses/lgpl-3.0.html)
[![LGPL v3.0](https://www.gnu.org/graphics/lgplv3-with-text-154x68.png)](https://github.com/measles/latynkatar/blob/main/LICENSE) ад [GNU](https://www.gnu.org/licenses/lgpl-3.0.html)
2 changes: 1 addition & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-export-default-from"]
}
}
4 changes: 2 additions & 2 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"transform": {
"^.+\\.jsx?$": "babel-jest"
"^.+\\.jsx?$": "babel-jest"
}
}
}
378 changes: 335 additions & 43 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/measles/latynkatar.js#readme",
"devDependencies": {
"jest-cli": "^29.7.0"
"jest-cli": "^29.7.0",
"prettier": "3.3.3"
}
}
134 changes: 73 additions & 61 deletions src/latynkatar.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
const pravilyKanvertacyi = {
"а": "a",
"э": "e",
"ы": "y",
"у": "u",
"ў": "ŭ",
"б": "b",
"в": "v",
"г": "h",
"ґ": "g",
"д": "d",
"ж": "ž",
"й": "j",
"к": "k",
"м": "m",
"о": "o",
"п": "p",
"р": "r",
"т": "t",
"ф": "f",
"ч": "č",
"ш": "š",
"х": "ch",
}
а: "a",
э: "e",
ы: "y",
у: "u",
ў: "ŭ",
б: "b",
в: "v",
г: "h",
ґ: "g",
д: "d",
ж: "ž",
й: "j",
к: "k",
м: "m",
о: "o",
п: "p",
р: "r",
т: "t",
ф: "f",
ч: "č",
ш: "š",
х: "ch",
};

const jotavanyjaLitary = {
"е": "e",
"ё": "o",
"і": "",
"ю": "u",
"я": "a",
}
е: "e",
ё: "o",
і: "",
ю: "u",
я: "a",
};

const zycznyjaZTranzitam = [
"б",
Expand All @@ -50,9 +50,9 @@ const zycznyjaZTranzitam = [
"ц",
"ч",
"ш",
]
];

const halosnyja = ["а", "е", "ё", "і", "у", "ы", "э", "ю", "я"]
const halosnyja = ["а", "е", "ё", "і", "у", "ы", "э", "ю", "я"];

class CurrentLetter {
constructor(current) {
Expand All @@ -61,7 +61,7 @@ class CurrentLetter {
this.isUpper = true;

if (this.lower == this.letter) {
this.isUpper = false
this.isUpper = false;
}
}
}
Expand All @@ -75,34 +75,38 @@ function convert_l(nextLetter, nextNextLetter) {
nextNextLetter = nextNextLetter ? nextNextLetter.toLowerCase() : undefined;

let convertedLetter = "";
switch (true){
switch (true) {
// Калі наступнай ідзе ётаваная літара ці мяккі знак
case (nextLetter && (nextLetter in jotavanyjaLitary || nextLetter == "ь")):
case nextLetter && (nextLetter in jotavanyjaLitary || nextLetter == "ь"):
convertedLetter = "l";
break;
// Калі наступная зычная літара мяккая і не г, к, х
case ((nextLetter && zycznyjaZTranzitam.find((litara) => litara == nextLetter)) &&
(nextNextLetter && (nextNextLetter in jotavanyjaLitary || nextNextLetter == "ь"))):
case nextLetter &&
zycznyjaZTranzitam.find((litara) => litara == nextLetter) &&
nextNextLetter &&
(nextNextLetter in jotavanyjaLitary || nextNextLetter == "ь"):
convertedLetter = "l";
break;
// Ва ўсіх астатніх выпадках
default:
convertedLetter = "ł";
}
return convertedLetter
return convertedLetter;
}

function convertJotavanyja(currentLetter, previousLetter) {
previousLetter = previousLetter ? previousLetter.toLowerCase() : previousLetter;
previousLetter = previousLetter
? previousLetter.toLowerCase()
: previousLetter;
let baseLetter = "";
let secondLetter = "";

if (
(!previousLetter ||
halosnyja.find((letter) => letter == previousLetter) ||
!previousLetter.match(/[а-я]/i) ||
previousLetter == "'" ||
previousLetter == "ь") &&
halosnyja.find((letter) => letter == previousLetter) ||
!previousLetter.match(/[а-я]/i) ||
previousLetter == "'" ||
previousLetter == "ь") &&
currentLetter != "і"
) {
baseLetter = "j";
Expand All @@ -119,48 +123,56 @@ function convertJotavanyja(currentLetter, previousLetter) {
return baseLetter + secondLetter;
}

function convertCyrToLat(inputText, classic=true) {
if (typeof inputText != "string"){
throw new TypeError(`Struing expected, but instead got ${toString(inputText)} with type ${typeof inputText}`);
function convertCyrToLat(inputText, classic = true) {
if (typeof inputText != "string") {
throw new TypeError(
`Struing expected, but instead got ${toString(inputText)} with type ${typeof inputText}`,
);
}

if (typeof classic != "boolean") {
throw new TypeError("Classic should be set to some boolean value, instead was", typeof classic)
throw new TypeError(
"Classic should be set to some boolean value, instead was",
typeof classic,
);
}

let convertedText = "";

for (let i = 0; i < inputText.length; i++){
for (let i = 0; i < inputText.length; i++) {
let convertedLetter;
const currentLetter = new CurrentLetter(inputText[i]);

let previousLetter;
if (i > 0){
previousLetter = inputText[i - 1]
if (i > 0) {
previousLetter = inputText[i - 1];
}

let nextLetter, nextNextLetter;
if (i < inputText.length - 1){
nextLetter = inputText[i + 1]
if (i < inputText.length - 1) {
nextLetter = inputText[i + 1];
}

if (i < inputText.length - 2){
nextNextLetter = inputText[i + 2]
if (i < inputText.length - 2) {
nextNextLetter = inputText[i + 2];
}

switch(true){
case (currentLetter.lower in pravilyKanvertacyi):
convertedLetter = pravilyKanvertacyi[currentLetter.lower]
switch (true) {
case currentLetter.lower in pravilyKanvertacyi:
convertedLetter = pravilyKanvertacyi[currentLetter.lower];
break;
case (currentLetter.lower == "л"):
case currentLetter.lower == "л":
convertedLetter = convert_l(nextLetter, nextNextLetter);
break;
// Не маюць літар-адпаведнікаў у лацінцы
case (currentLetter.lower == "ь" || currentLetter.letter == "'"):
case currentLetter.lower == "ь" || currentLetter.letter == "'":
convertedLetter = "";
break;
case (currentLetter.lower in jotavanyjaLitary):
convertedLetter = convertJotavanyja(currentLetter.lower, previousLetter);
case currentLetter.lower in jotavanyjaLitary:
convertedLetter = convertJotavanyja(
currentLetter.lower,
previousLetter,
);
break;
default:
convertedLetter = currentLetter.letter;
Expand All @@ -172,6 +184,6 @@ function convertCyrToLat(inputText, classic=true) {
convertedText = convertedText + convertedLetter;
}
return convertedText;
};
}

export default convertCyrToLat;
26 changes: 17 additions & 9 deletions tests/latynkatar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,49 @@ Załatymi ahniami!

describe("Тэсты на галосныя", () => {
test("Ю", () => {
expect(convertCyrToLat("ЮрліВец лЮбіЦь лІю п'ю")).toBe("JurliViec lUbiĆ lIju pju")
expect(convertCyrToLat("ЮрліВец лЮбіЦь лІю п'ю")).toBe(
"JurliViec lUbiĆ lIju pju",
);
});

test("Я", () => {
expect(convertCyrToLat("Яз'яваЗЯпазЬяВА")).toBe("JazjavaZIapaźjaVA")
expect(convertCyrToLat("Яз'яваЗЯпазЬяВА")).toBe("JazjavaZIapaźjaVA");
});
});

describe("Тэсты на зычныя", () => {
test("Л", () => {
expect(convertCyrToLat("ЛаЭлЯЛуЛіЛюЛЁлЕлЬ лЛя Лсі")).toBe("ŁaElAŁuLiLuLOlEl lLa Lsi")
expect(convertCyrToLat("ЛаЭлЯЛуЛіЛюЛЁлЕлЬ лЛя Лсі")).toBe(
"ŁaElAŁuLiLuLOlEl lLa Lsi",
);
});

test("Х", () => {
expect(convertCyrToLat("ХаХу ХЫВАХххххх Хіх")).toBe("ChaChu ChYVAChchchchchch Chich")
expect(convertCyrToLat("ХаХу ХЫВАХххххх Хіх")).toBe(
"ChaChu ChYVAChchchchchch Chich",
);
});

test("Ш", () => {
expect(convertCyrToLat("ШашуШышшшшшшш")).toBe("ŠašuŠyššššššš")
expect(convertCyrToLat("ШашуШышшшшшшш")).toBe("ŠašuŠyššššššš");
});

test("Ч", () => {
expect(convertCyrToLat("чАЧыЧУ")).toBe("čAČyČU")
expect(convertCyrToLat("чАЧыЧУ")).toBe("čAČyČU");
});

test("Ж", () => {
expect(convertCyrToLat("жУрАвІнЫЖэЖЫ")).toBe("žUrAvInYŽeŽY")
expect(convertCyrToLat("жУрАвІнЫЖэЖЫ")).toBe("žUrAvInYŽeŽY");
});

test("В", () => {
expect(convertCyrToLat("войт і Ваявода")).toBe("vojt i Vajavoda")
expect(convertCyrToLat("войт і Ваявода")).toBe("vojt i Vajavoda");
});

test("мяккасць", () => {
expect(convertCyrToLat("снег смех поспех святы")).toBe("śnieh śmiech pośpiech śviaty")
expect(convertCyrToLat("снег смех поспех святы")).toBe(
"śnieh śmiech pośpiech śviaty",
);
});
});

Expand Down

0 comments on commit d2f2980

Please sign in to comment.