taraskevizer 5.3.2 → 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 +72 -27
- package/dist/index.js +72 -27
- package/package.json +1 -4
package/dist/index.cjs
CHANGED
|
@@ -2004,7 +2004,6 @@ for (const word of gwords)
|
|
|
2004
2004
|
wordlist.push([RegExp(word.replace(/ґ/g, "г"), "g"), word]);
|
|
2005
2005
|
|
|
2006
2006
|
// src/tarask.ts
|
|
2007
|
-
var import_diff = require("diff");
|
|
2008
2007
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
2009
2008
|
var getLastLetter = (word, i) => {
|
|
2010
2009
|
for (let i2 = word.length - 1; i2 >= 0; i2--)
|
|
@@ -2097,13 +2096,62 @@ var restoreCase = (text, orig) => {
|
|
|
2097
2096
|
}
|
|
2098
2097
|
return text;
|
|
2099
2098
|
};
|
|
2100
|
-
var
|
|
2101
|
-
(
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
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
|
+
};
|
|
2107
2155
|
var replaceWithDict = (text, dict = []) => {
|
|
2108
2156
|
for (const [pattern, result] of dict)
|
|
2109
2157
|
text = text.replace(
|
|
@@ -2157,17 +2205,15 @@ var Taraskevizer = class {
|
|
|
2157
2205
|
}
|
|
2158
2206
|
convert(text) {
|
|
2159
2207
|
const wrapInColorOf = wrappers.ansiColors;
|
|
2208
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2160
2209
|
const noFixArr = [];
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2210
|
+
const { splitted, splittedOrig } = this.process(
|
|
2211
|
+
this.prepare(text, noFixArr, "<")
|
|
2212
|
+
);
|
|
2164
2213
|
if (this.nonHtml.ansiColors)
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
wrapInColorOf.fix
|
|
2169
|
-
);
|
|
2170
|
-
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))
|
|
2171
2217
|
text = replaceG(
|
|
2172
2218
|
text,
|
|
2173
2219
|
this.nonHtml.ansiColors ? this.nonHtml.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
|
|
@@ -2184,15 +2230,14 @@ var Taraskevizer = class {
|
|
|
2184
2230
|
}
|
|
2185
2231
|
convertToHtml(text) {
|
|
2186
2232
|
const wrapInTag = wrappers.html;
|
|
2233
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2187
2234
|
const noFixArr = [];
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
text = highlightChanges(
|
|
2191
|
-
this.process(text, origInTargetAlphabet),
|
|
2192
|
-
afterJoin(origInTargetAlphabet),
|
|
2193
|
-
wrapInTag.fix
|
|
2235
|
+
const { splitted, splittedOrig } = this.process(
|
|
2236
|
+
this.prepare(text, noFixArr, "<")
|
|
2194
2237
|
);
|
|
2195
|
-
|
|
2238
|
+
highlightDiff(splitted, splittedOrig, isCyrillic, wrapInTag.fix);
|
|
2239
|
+
text = join(splitted);
|
|
2240
|
+
if (isCyrillic)
|
|
2196
2241
|
text = replaceG(
|
|
2197
2242
|
text,
|
|
2198
2243
|
this.html.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
|
|
@@ -2235,9 +2280,9 @@ var Taraskevizer = class {
|
|
|
2235
2280
|
"\n"
|
|
2236
2281
|
);
|
|
2237
2282
|
}
|
|
2238
|
-
process(text
|
|
2283
|
+
process(text) {
|
|
2239
2284
|
const { abc, j } = this;
|
|
2240
|
-
const splittedOrig =
|
|
2285
|
+
const splittedOrig = convertAlphabet(text, abc).split(" ");
|
|
2241
2286
|
text = this.taraskevize(text.toLowerCase());
|
|
2242
2287
|
if (j && abc !== ALPHABET.LATIN_JI)
|
|
2243
2288
|
text = replaceIbyJ(text, j === REPLACE_J.ALWAYS);
|
|
@@ -2245,7 +2290,7 @@ var Taraskevizer = class {
|
|
|
2245
2290
|
let splitted = text.split(" ");
|
|
2246
2291
|
if (abc !== ALPHABET.ARABIC)
|
|
2247
2292
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2248
|
-
return
|
|
2293
|
+
return { splittedOrig, splitted };
|
|
2249
2294
|
}
|
|
2250
2295
|
taraskevize(text) {
|
|
2251
2296
|
text = replaceWithDict(text, wordlist);
|
package/dist/index.js
CHANGED
|
@@ -1973,7 +1973,6 @@ for (const word of gwords)
|
|
|
1973
1973
|
wordlist.push([RegExp(word.replace(/ґ/g, "г"), "g"), word]);
|
|
1974
1974
|
|
|
1975
1975
|
// src/tarask.ts
|
|
1976
|
-
import { diffChars } from "diff";
|
|
1977
1976
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
1978
1977
|
var getLastLetter = (word, i) => {
|
|
1979
1978
|
for (let i2 = word.length - 1; i2 >= 0; i2--)
|
|
@@ -2066,13 +2065,62 @@ var restoreCase = (text, orig) => {
|
|
|
2066
2065
|
}
|
|
2067
2066
|
return text;
|
|
2068
2067
|
};
|
|
2069
|
-
var
|
|
2070
|
-
(
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
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
|
+
};
|
|
2076
2124
|
var replaceWithDict = (text, dict = []) => {
|
|
2077
2125
|
for (const [pattern, result] of dict)
|
|
2078
2126
|
text = text.replace(
|
|
@@ -2126,17 +2174,15 @@ var Taraskevizer = class {
|
|
|
2126
2174
|
}
|
|
2127
2175
|
convert(text) {
|
|
2128
2176
|
const wrapInColorOf = wrappers.ansiColors;
|
|
2177
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2129
2178
|
const noFixArr = [];
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2179
|
+
const { splitted, splittedOrig } = this.process(
|
|
2180
|
+
this.prepare(text, noFixArr, "<")
|
|
2181
|
+
);
|
|
2133
2182
|
if (this.nonHtml.ansiColors)
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
wrapInColorOf.fix
|
|
2138
|
-
);
|
|
2139
|
-
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))
|
|
2140
2186
|
text = replaceG(
|
|
2141
2187
|
text,
|
|
2142
2188
|
this.nonHtml.ansiColors ? this.nonHtml.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
|
|
@@ -2153,15 +2199,14 @@ var Taraskevizer = class {
|
|
|
2153
2199
|
}
|
|
2154
2200
|
convertToHtml(text) {
|
|
2155
2201
|
const wrapInTag = wrappers.html;
|
|
2202
|
+
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2156
2203
|
const noFixArr = [];
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
text = highlightChanges(
|
|
2160
|
-
this.process(text, origInTargetAlphabet),
|
|
2161
|
-
afterJoin(origInTargetAlphabet),
|
|
2162
|
-
wrapInTag.fix
|
|
2204
|
+
const { splitted, splittedOrig } = this.process(
|
|
2205
|
+
this.prepare(text, noFixArr, "<")
|
|
2163
2206
|
);
|
|
2164
|
-
|
|
2207
|
+
highlightDiff(splitted, splittedOrig, isCyrillic, wrapInTag.fix);
|
|
2208
|
+
text = join(splitted);
|
|
2209
|
+
if (isCyrillic)
|
|
2165
2210
|
text = replaceG(
|
|
2166
2211
|
text,
|
|
2167
2212
|
this.html.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
|
|
@@ -2204,9 +2249,9 @@ var Taraskevizer = class {
|
|
|
2204
2249
|
"\n"
|
|
2205
2250
|
);
|
|
2206
2251
|
}
|
|
2207
|
-
process(text
|
|
2252
|
+
process(text) {
|
|
2208
2253
|
const { abc, j } = this;
|
|
2209
|
-
const splittedOrig =
|
|
2254
|
+
const splittedOrig = convertAlphabet(text, abc).split(" ");
|
|
2210
2255
|
text = this.taraskevize(text.toLowerCase());
|
|
2211
2256
|
if (j && abc !== ALPHABET.LATIN_JI)
|
|
2212
2257
|
text = replaceIbyJ(text, j === REPLACE_J.ALWAYS);
|
|
@@ -2214,7 +2259,7 @@ var Taraskevizer = class {
|
|
|
2214
2259
|
let splitted = text.split(" ");
|
|
2215
2260
|
if (abc !== ALPHABET.ARABIC)
|
|
2216
2261
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2217
|
-
return
|
|
2262
|
+
return { splittedOrig, splitted };
|
|
2218
2263
|
}
|
|
2219
2264
|
taraskevize(text) {
|
|
2220
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",
|