taraskevizer 5.3.1 → 5.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +76 -30
- package/dist/index.js +76 -30
- package/package.json +1 -4
package/dist/index.cjs
CHANGED
|
@@ -51,6 +51,7 @@ var iwords = toOneLine(`біс
|
|
|
51
51
|
л(іст| )
|
|
52
52
|
лістас
|
|
53
53
|
льк
|
|
54
|
+
м
|
|
54
55
|
мант
|
|
55
56
|
мась?ц
|
|
56
57
|
мбры[кч]
|
|
@@ -67,7 +68,7 @@ var iwords = toOneLine(`біс
|
|
|
67
68
|
нфікс
|
|
68
69
|
нфімум
|
|
69
70
|
ншась?ц
|
|
70
|
-
нш(а[ейя]?|ась?ц|ую|ы(
|
|
71
|
+
нш(а[ейя]?|ась?ц|ую|ы(мі?|х|я)?)
|
|
71
72
|
псілан
|
|
72
73
|
р([аыу]|а[мхйў]|амі|)
|
|
73
74
|
рад
|
|
@@ -216,14 +217,14 @@ var rawLatinLettersJi = [
|
|
|
216
217
|
[`І(?=${iwords})`, "Ji"],
|
|
217
218
|
[`І(?=${iwords.toUpperCase()})`, "JI"],
|
|
218
219
|
...common.lower[0],
|
|
219
|
-
[/(?<=[eoua
|
|
220
|
+
[/(?<=[eouaаеёіоуўыэюяʼАЕЁІОУЎЫЭЮЯЬ] *)і/, "ji"],
|
|
220
221
|
...common.lower[1]
|
|
221
222
|
];
|
|
222
223
|
var rawLatinLettersUpperCaseJi = [
|
|
223
224
|
...common.upper[0],
|
|
224
225
|
[new RegExp("(?<=[eoua] *)І(?=[ \\p{P}\\d]*\\p{Lu}?\\p{Ll})", "u"), "Ji"],
|
|
225
226
|
...common.upper[1],
|
|
226
|
-
[/(?<=[AOEU
|
|
227
|
+
[/(?<=[AOEUАЕЁІОУЎЫЭЮЯ][( ]*)І/, "JI"],
|
|
227
228
|
...common.upper[2]
|
|
228
229
|
];
|
|
229
230
|
|
|
@@ -2003,7 +2004,6 @@ for (const word of gwords)
|
|
|
2003
2004
|
wordlist.push([RegExp(word.replace(/ґ/g, "г"), "g"), word]);
|
|
2004
2005
|
|
|
2005
2006
|
// src/tarask.ts
|
|
2006
|
-
var import_diff = require("diff");
|
|
2007
2007
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
2008
2008
|
var getLastLetter = (word, i) => {
|
|
2009
2009
|
for (let i2 = word.length - 1; i2 >= 0; i2--)
|
|
@@ -2096,13 +2096,62 @@ var restoreCase = (text, orig) => {
|
|
|
2096
2096
|
}
|
|
2097
2097
|
return text;
|
|
2098
2098
|
};
|
|
2099
|
-
var
|
|
2100
|
-
(
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2099
|
+
var highlightDiff = (text, orig, isCyrillic, highlight) => {
|
|
2100
|
+
for (let i = 0; i < text.length; i++) {
|
|
2101
|
+
const word = text[i];
|
|
2102
|
+
const oWord = orig[i];
|
|
2103
|
+
if (oWord === word)
|
|
2104
|
+
continue;
|
|
2105
|
+
const wordH = isCyrillic ? replaceG(word, ($0) => gobj[$0]) : word;
|
|
2106
|
+
if (oWord === wordH)
|
|
2107
|
+
continue;
|
|
2108
|
+
if (!/\(/.test(word)) {
|
|
2109
|
+
if (word.length === oWord.length) {
|
|
2110
|
+
const wordLetters = word.split("");
|
|
2111
|
+
for (let j = 0; j < wordLetters.length; j++) {
|
|
2112
|
+
if (wordH[j] !== oWord[j])
|
|
2113
|
+
wordLetters[j] = highlight(wordLetters[j]);
|
|
2114
|
+
}
|
|
2115
|
+
text[i] = wordLetters.join("");
|
|
2116
|
+
continue;
|
|
2117
|
+
}
|
|
2118
|
+
if (isCyrillic) {
|
|
2119
|
+
const word1 = word.replace(/ь/g, "");
|
|
2120
|
+
switch (oWord) {
|
|
2121
|
+
case word1:
|
|
2122
|
+
text[i] = word.replace(/ь/g, highlight("ь"));
|
|
2123
|
+
continue;
|
|
2124
|
+
case word1 + "ь":
|
|
2125
|
+
text[i] = word.slice(0, -1).replace(/ь/g, highlight("ь")) + "ь";
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
const oWordEnd = oWord.length - 1;
|
|
2131
|
+
let fromStart = 0;
|
|
2132
|
+
let fromWordEnd = word.length - 1;
|
|
2133
|
+
let fromOWordEnd = oWordEnd;
|
|
2134
|
+
while (wordH[fromStart] === oWord[fromStart])
|
|
2135
|
+
++fromStart;
|
|
2136
|
+
while (wordH[fromWordEnd] === oWord[fromOWordEnd]) {
|
|
2137
|
+
--fromWordEnd;
|
|
2138
|
+
--fromOWordEnd;
|
|
2139
|
+
}
|
|
2140
|
+
if (oWord.length < word.length) {
|
|
2141
|
+
if (fromOWordEnd === oWordEnd) {
|
|
2142
|
+
text[i] = highlight(word);
|
|
2143
|
+
continue;
|
|
2144
|
+
}
|
|
2145
|
+
if (fromWordEnd < 0)
|
|
2146
|
+
fromWordEnd = 0;
|
|
2147
|
+
}
|
|
2148
|
+
if (fromStart === fromWordEnd + 1) {
|
|
2149
|
+
--fromStart;
|
|
2150
|
+
++fromWordEnd;
|
|
2151
|
+
}
|
|
2152
|
+
text[i] = word.slice(0, fromStart) + highlight(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
|
|
2153
|
+
}
|
|
2154
|
+
};
|
|
2106
2155
|
var replaceWithDict = (text, dict = []) => {
|
|
2107
2156
|
for (const [pattern, result] of dict)
|
|
2108
2157
|
text = text.replace(
|
|
@@ -2156,17 +2205,15 @@ var Taraskevizer = class {
|
|
|
2156
2205
|
}
|
|
2157
2206
|
convert(text) {
|
|
2158
2207
|
const wrapInColorOf = wrappers.ansiColors;
|
|
2208
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2159
2209
|
const noFixArr = [];
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2210
|
+
const { splitted, splittedOrig } = this.process(
|
|
2211
|
+
this.prepare(text, noFixArr, "<")
|
|
2212
|
+
);
|
|
2163
2213
|
if (this.nonHtml.ansiColors)
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
wrapInColorOf.fix
|
|
2168
|
-
);
|
|
2169
|
-
if (this.abc === ALPHABET.CYRILLIC && (this.nonHtml.h || this.nonHtml.ansiColors))
|
|
2214
|
+
highlightDiff(splitted, splittedOrig, isCyrillic, wrapInColorOf.fix);
|
|
2215
|
+
text = join(splitted);
|
|
2216
|
+
if (isCyrillic && (this.nonHtml.h || this.nonHtml.ansiColors))
|
|
2170
2217
|
text = replaceG(
|
|
2171
2218
|
text,
|
|
2172
2219
|
this.nonHtml.ansiColors ? this.nonHtml.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
|
|
@@ -2183,15 +2230,14 @@ var Taraskevizer = class {
|
|
|
2183
2230
|
}
|
|
2184
2231
|
convertToHtml(text) {
|
|
2185
2232
|
const wrapInTag = wrappers.html;
|
|
2233
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2186
2234
|
const noFixArr = [];
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
text = highlightChanges(
|
|
2190
|
-
this.process(text, origInTargetAlphabet),
|
|
2191
|
-
afterJoin(origInTargetAlphabet),
|
|
2192
|
-
wrapInTag.fix
|
|
2235
|
+
const { splitted, splittedOrig } = this.process(
|
|
2236
|
+
this.prepare(text, noFixArr, "<")
|
|
2193
2237
|
);
|
|
2194
|
-
|
|
2238
|
+
highlightDiff(splitted, splittedOrig, isCyrillic, wrapInTag.fix);
|
|
2239
|
+
text = join(splitted);
|
|
2240
|
+
if (isCyrillic)
|
|
2195
2241
|
text = replaceG(
|
|
2196
2242
|
text,
|
|
2197
2243
|
this.html.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
|
|
@@ -2234,9 +2280,9 @@ var Taraskevizer = class {
|
|
|
2234
2280
|
"\n"
|
|
2235
2281
|
);
|
|
2236
2282
|
}
|
|
2237
|
-
process(text
|
|
2283
|
+
process(text) {
|
|
2238
2284
|
const { abc, j } = this;
|
|
2239
|
-
const splittedOrig =
|
|
2285
|
+
const splittedOrig = convertAlphabet(text, abc).split(" ");
|
|
2240
2286
|
text = this.taraskevize(text.toLowerCase());
|
|
2241
2287
|
if (j && abc !== ALPHABET.LATIN_JI)
|
|
2242
2288
|
text = replaceIbyJ(text, j === REPLACE_J.ALWAYS);
|
|
@@ -2244,7 +2290,7 @@ var Taraskevizer = class {
|
|
|
2244
2290
|
let splitted = text.split(" ");
|
|
2245
2291
|
if (abc !== ALPHABET.ARABIC)
|
|
2246
2292
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2247
|
-
return
|
|
2293
|
+
return { splittedOrig, splitted };
|
|
2248
2294
|
}
|
|
2249
2295
|
taraskevize(text) {
|
|
2250
2296
|
text = replaceWithDict(text, wordlist);
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var iwords = toOneLine(`біс
|
|
|
20
20
|
л(іст| )
|
|
21
21
|
лістас
|
|
22
22
|
льк
|
|
23
|
+
м
|
|
23
24
|
мант
|
|
24
25
|
мась?ц
|
|
25
26
|
мбры[кч]
|
|
@@ -36,7 +37,7 @@ var iwords = toOneLine(`біс
|
|
|
36
37
|
нфікс
|
|
37
38
|
нфімум
|
|
38
39
|
ншась?ц
|
|
39
|
-
нш(а[ейя]?|ась?ц|ую|ы(
|
|
40
|
+
нш(а[ейя]?|ась?ц|ую|ы(мі?|х|я)?)
|
|
40
41
|
псілан
|
|
41
42
|
р([аыу]|а[мхйў]|амі|)
|
|
42
43
|
рад
|
|
@@ -185,14 +186,14 @@ var rawLatinLettersJi = [
|
|
|
185
186
|
[`І(?=${iwords})`, "Ji"],
|
|
186
187
|
[`І(?=${iwords.toUpperCase()})`, "JI"],
|
|
187
188
|
...common.lower[0],
|
|
188
|
-
[/(?<=[eoua
|
|
189
|
+
[/(?<=[eouaаеёіоуўыэюяʼАЕЁІОУЎЫЭЮЯЬ] *)і/, "ji"],
|
|
189
190
|
...common.lower[1]
|
|
190
191
|
];
|
|
191
192
|
var rawLatinLettersUpperCaseJi = [
|
|
192
193
|
...common.upper[0],
|
|
193
194
|
[new RegExp("(?<=[eoua] *)І(?=[ \\p{P}\\d]*\\p{Lu}?\\p{Ll})", "u"), "Ji"],
|
|
194
195
|
...common.upper[1],
|
|
195
|
-
[/(?<=[AOEU
|
|
196
|
+
[/(?<=[AOEUАЕЁІОУЎЫЭЮЯ][( ]*)І/, "JI"],
|
|
196
197
|
...common.upper[2]
|
|
197
198
|
];
|
|
198
199
|
|
|
@@ -1972,7 +1973,6 @@ for (const word of gwords)
|
|
|
1972
1973
|
wordlist.push([RegExp(word.replace(/ґ/g, "г"), "g"), word]);
|
|
1973
1974
|
|
|
1974
1975
|
// src/tarask.ts
|
|
1975
|
-
import { diffChars } from "diff";
|
|
1976
1976
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
1977
1977
|
var getLastLetter = (word, i) => {
|
|
1978
1978
|
for (let i2 = word.length - 1; i2 >= 0; i2--)
|
|
@@ -2065,13 +2065,62 @@ var restoreCase = (text, orig) => {
|
|
|
2065
2065
|
}
|
|
2066
2066
|
return text;
|
|
2067
2067
|
};
|
|
2068
|
-
var
|
|
2069
|
-
(
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2068
|
+
var highlightDiff = (text, orig, isCyrillic, highlight) => {
|
|
2069
|
+
for (let i = 0; i < text.length; i++) {
|
|
2070
|
+
const word = text[i];
|
|
2071
|
+
const oWord = orig[i];
|
|
2072
|
+
if (oWord === word)
|
|
2073
|
+
continue;
|
|
2074
|
+
const wordH = isCyrillic ? replaceG(word, ($0) => gobj[$0]) : word;
|
|
2075
|
+
if (oWord === wordH)
|
|
2076
|
+
continue;
|
|
2077
|
+
if (!/\(/.test(word)) {
|
|
2078
|
+
if (word.length === oWord.length) {
|
|
2079
|
+
const wordLetters = word.split("");
|
|
2080
|
+
for (let j = 0; j < wordLetters.length; j++) {
|
|
2081
|
+
if (wordH[j] !== oWord[j])
|
|
2082
|
+
wordLetters[j] = highlight(wordLetters[j]);
|
|
2083
|
+
}
|
|
2084
|
+
text[i] = wordLetters.join("");
|
|
2085
|
+
continue;
|
|
2086
|
+
}
|
|
2087
|
+
if (isCyrillic) {
|
|
2088
|
+
const word1 = word.replace(/ь/g, "");
|
|
2089
|
+
switch (oWord) {
|
|
2090
|
+
case word1:
|
|
2091
|
+
text[i] = word.replace(/ь/g, highlight("ь"));
|
|
2092
|
+
continue;
|
|
2093
|
+
case word1 + "ь":
|
|
2094
|
+
text[i] = word.slice(0, -1).replace(/ь/g, highlight("ь")) + "ь";
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
const oWordEnd = oWord.length - 1;
|
|
2100
|
+
let fromStart = 0;
|
|
2101
|
+
let fromWordEnd = word.length - 1;
|
|
2102
|
+
let fromOWordEnd = oWordEnd;
|
|
2103
|
+
while (wordH[fromStart] === oWord[fromStart])
|
|
2104
|
+
++fromStart;
|
|
2105
|
+
while (wordH[fromWordEnd] === oWord[fromOWordEnd]) {
|
|
2106
|
+
--fromWordEnd;
|
|
2107
|
+
--fromOWordEnd;
|
|
2108
|
+
}
|
|
2109
|
+
if (oWord.length < word.length) {
|
|
2110
|
+
if (fromOWordEnd === oWordEnd) {
|
|
2111
|
+
text[i] = highlight(word);
|
|
2112
|
+
continue;
|
|
2113
|
+
}
|
|
2114
|
+
if (fromWordEnd < 0)
|
|
2115
|
+
fromWordEnd = 0;
|
|
2116
|
+
}
|
|
2117
|
+
if (fromStart === fromWordEnd + 1) {
|
|
2118
|
+
--fromStart;
|
|
2119
|
+
++fromWordEnd;
|
|
2120
|
+
}
|
|
2121
|
+
text[i] = word.slice(0, fromStart) + highlight(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2075
2124
|
var replaceWithDict = (text, dict = []) => {
|
|
2076
2125
|
for (const [pattern, result] of dict)
|
|
2077
2126
|
text = text.replace(
|
|
@@ -2125,17 +2174,15 @@ var Taraskevizer = class {
|
|
|
2125
2174
|
}
|
|
2126
2175
|
convert(text) {
|
|
2127
2176
|
const wrapInColorOf = wrappers.ansiColors;
|
|
2177
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2128
2178
|
const noFixArr = [];
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2179
|
+
const { splitted, splittedOrig } = this.process(
|
|
2180
|
+
this.prepare(text, noFixArr, "<")
|
|
2181
|
+
);
|
|
2132
2182
|
if (this.nonHtml.ansiColors)
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
wrapInColorOf.fix
|
|
2137
|
-
);
|
|
2138
|
-
if (this.abc === ALPHABET.CYRILLIC && (this.nonHtml.h || this.nonHtml.ansiColors))
|
|
2183
|
+
highlightDiff(splitted, splittedOrig, isCyrillic, wrapInColorOf.fix);
|
|
2184
|
+
text = join(splitted);
|
|
2185
|
+
if (isCyrillic && (this.nonHtml.h || this.nonHtml.ansiColors))
|
|
2139
2186
|
text = replaceG(
|
|
2140
2187
|
text,
|
|
2141
2188
|
this.nonHtml.ansiColors ? this.nonHtml.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
|
|
@@ -2152,15 +2199,14 @@ var Taraskevizer = class {
|
|
|
2152
2199
|
}
|
|
2153
2200
|
convertToHtml(text) {
|
|
2154
2201
|
const wrapInTag = wrappers.html;
|
|
2202
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2155
2203
|
const noFixArr = [];
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
text = highlightChanges(
|
|
2159
|
-
this.process(text, origInTargetAlphabet),
|
|
2160
|
-
afterJoin(origInTargetAlphabet),
|
|
2161
|
-
wrapInTag.fix
|
|
2204
|
+
const { splitted, splittedOrig } = this.process(
|
|
2205
|
+
this.prepare(text, noFixArr, "<")
|
|
2162
2206
|
);
|
|
2163
|
-
|
|
2207
|
+
highlightDiff(splitted, splittedOrig, isCyrillic, wrapInTag.fix);
|
|
2208
|
+
text = join(splitted);
|
|
2209
|
+
if (isCyrillic)
|
|
2164
2210
|
text = replaceG(
|
|
2165
2211
|
text,
|
|
2166
2212
|
this.html.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
|
|
@@ -2203,9 +2249,9 @@ var Taraskevizer = class {
|
|
|
2203
2249
|
"\n"
|
|
2204
2250
|
);
|
|
2205
2251
|
}
|
|
2206
|
-
process(text
|
|
2252
|
+
process(text) {
|
|
2207
2253
|
const { abc, j } = this;
|
|
2208
|
-
const splittedOrig =
|
|
2254
|
+
const splittedOrig = convertAlphabet(text, abc).split(" ");
|
|
2209
2255
|
text = this.taraskevize(text.toLowerCase());
|
|
2210
2256
|
if (j && abc !== ALPHABET.LATIN_JI)
|
|
2211
2257
|
text = replaceIbyJ(text, j === REPLACE_J.ALWAYS);
|
|
@@ -2213,7 +2259,7 @@ var Taraskevizer = class {
|
|
|
2213
2259
|
let splitted = text.split(" ");
|
|
2214
2260
|
if (abc !== ALPHABET.ARABIC)
|
|
2215
2261
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2216
|
-
return
|
|
2262
|
+
return { splittedOrig, splitted };
|
|
2217
2263
|
}
|
|
2218
2264
|
taraskevize(text) {
|
|
2219
2265
|
text = replaceWithDict(text, wordlist);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taraskevizer",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.3",
|
|
4
4
|
"author": "GooseOb",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
},
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/index.js",
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"diff": "^5.2.0"
|
|
13
|
-
},
|
|
14
11
|
"devDependencies": {
|
|
15
12
|
"@digitak/esrun": "^3.2.26",
|
|
16
13
|
"@types/diff": "^5.2.0",
|