taraskevizer 5.2.6 → 5.3.1
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 +29 -69
- package/dist/index.js +29 -69
- package/package.json +13 -9
package/dist/index.cjs
CHANGED
|
@@ -2003,6 +2003,7 @@ for (const word of gwords)
|
|
|
2003
2003
|
wordlist.push([RegExp(word.replace(/ґ/g, "г"), "g"), word]);
|
|
2004
2004
|
|
|
2005
2005
|
// src/tarask.ts
|
|
2006
|
+
var import_diff = require("diff");
|
|
2006
2007
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
2007
2008
|
var getLastLetter = (word, i) => {
|
|
2008
2009
|
for (let i2 = word.length - 1; i2 >= 0; i2--)
|
|
@@ -2062,7 +2063,8 @@ var afterTarask = [
|
|
|
2062
2063
|
]
|
|
2063
2064
|
];
|
|
2064
2065
|
var applyNoFix = (arr2, text) => arr2.length ? text.replace(NOFIX_REGEX, () => arr2.shift()) : text;
|
|
2065
|
-
var
|
|
2066
|
+
var afterJoin = (text) => text.replace(/ /g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d|() ", "gu"), "$1");
|
|
2067
|
+
var join = (textArr) => afterJoin(textArr.join(" "));
|
|
2066
2068
|
var finalize = (text, newLine) => text.replace(/ \t /g, " ").replace(/ \n /g, newLine).trim();
|
|
2067
2069
|
var replaceG = (text, replacer) => text.replace(
|
|
2068
2070
|
G_REGEX,
|
|
@@ -2094,58 +2096,13 @@ var restoreCase = (text, orig) => {
|
|
|
2094
2096
|
}
|
|
2095
2097
|
return text;
|
|
2096
2098
|
};
|
|
2097
|
-
var highlightChanges = (text, orig,
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
if (oWord === wordH)
|
|
2105
|
-
continue;
|
|
2106
|
-
if (!/\(/.test(word)) {
|
|
2107
|
-
if (word.length === oWord.length) {
|
|
2108
|
-
const wordLetters = word.split("");
|
|
2109
|
-
for (let j = 0; j < wordLetters.length; j++) {
|
|
2110
|
-
if (wordH[j] !== oWord[j])
|
|
2111
|
-
wordLetters[j] = highlight(wordLetters[j]);
|
|
2112
|
-
}
|
|
2113
|
-
text[i] = wordLetters.join("");
|
|
2114
|
-
continue;
|
|
2115
|
-
}
|
|
2116
|
-
if (isCyrillic) {
|
|
2117
|
-
const word1 = word.replace(/ь/g, "");
|
|
2118
|
-
switch (oWord) {
|
|
2119
|
-
case word1:
|
|
2120
|
-
text[i] = word.replace(/ь/g, highlight("ь"));
|
|
2121
|
-
continue;
|
|
2122
|
-
case word1 + "ь":
|
|
2123
|
-
text[i] = word.slice(0, -1).replace(/ь/g, highlight("ь")) + "ь";
|
|
2124
|
-
continue;
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
const oWordEnd = oWord.length - 1;
|
|
2129
|
-
let fromStart = 0;
|
|
2130
|
-
let fromWordEnd = word.length - 1;
|
|
2131
|
-
let fromOWordEnd = oWordEnd;
|
|
2132
|
-
while (wordH[fromStart] === oWord[fromStart])
|
|
2133
|
-
++fromStart;
|
|
2134
|
-
while (wordH[fromWordEnd] === oWord[fromOWordEnd]) {
|
|
2135
|
-
--fromWordEnd;
|
|
2136
|
-
--fromOWordEnd;
|
|
2137
|
-
}
|
|
2138
|
-
if (oWord.length < word.length) {
|
|
2139
|
-
if (fromOWordEnd === oWordEnd) {
|
|
2140
|
-
text[i] = highlight(word);
|
|
2141
|
-
continue;
|
|
2142
|
-
}
|
|
2143
|
-
if (fromWordEnd < 0)
|
|
2144
|
-
fromWordEnd = 0;
|
|
2145
|
-
}
|
|
2146
|
-
text[i] = word.slice(0, fromStart) + highlight(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
|
|
2147
|
-
}
|
|
2148
|
-
};
|
|
2099
|
+
var highlightChanges = (text, orig, highlight) => (0, import_diff.diffChars)(orig, text).reduce(
|
|
2100
|
+
(acc, diff) => acc + (diff.removed ? "�" : diff.added ? highlight(diff.value) : diff.value),
|
|
2101
|
+
""
|
|
2102
|
+
).replace(
|
|
2103
|
+
/([^<>\x1b])�([^<>\x1b])/g,
|
|
2104
|
+
($0, $1, $2) => highlight($1 + $2)
|
|
2105
|
+
).replace(/�/g, "");
|
|
2149
2106
|
var replaceWithDict = (text, dict = []) => {
|
|
2150
2107
|
for (const [pattern, result] of dict)
|
|
2151
2108
|
text = text.replace(
|
|
@@ -2199,15 +2156,17 @@ var Taraskevizer = class {
|
|
|
2199
2156
|
}
|
|
2200
2157
|
convert(text) {
|
|
2201
2158
|
const wrapInColorOf = wrappers.ansiColors;
|
|
2202
|
-
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2203
2159
|
const noFixArr = [];
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
);
|
|
2160
|
+
text = this.prepare(text, noFixArr, "<");
|
|
2161
|
+
const origInTargetAlphabet = convertAlphabet(text, this.abc);
|
|
2162
|
+
text = this.process(text, origInTargetAlphabet);
|
|
2207
2163
|
if (this.nonHtml.ansiColors)
|
|
2208
|
-
highlightChanges(
|
|
2209
|
-
|
|
2210
|
-
|
|
2164
|
+
text = highlightChanges(
|
|
2165
|
+
text,
|
|
2166
|
+
afterJoin(origInTargetAlphabet),
|
|
2167
|
+
wrapInColorOf.fix
|
|
2168
|
+
);
|
|
2169
|
+
if (this.abc === ALPHABET.CYRILLIC && (this.nonHtml.h || this.nonHtml.ansiColors))
|
|
2211
2170
|
text = replaceG(
|
|
2212
2171
|
text,
|
|
2213
2172
|
this.nonHtml.ansiColors ? this.nonHtml.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
|
|
@@ -2224,14 +2183,15 @@ var Taraskevizer = class {
|
|
|
2224
2183
|
}
|
|
2225
2184
|
convertToHtml(text) {
|
|
2226
2185
|
const wrapInTag = wrappers.html;
|
|
2227
|
-
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2228
2186
|
const noFixArr = [];
|
|
2229
|
-
|
|
2230
|
-
|
|
2187
|
+
text = this.prepare(text, noFixArr, "<");
|
|
2188
|
+
const origInTargetAlphabet = convertAlphabet(text, this.abc);
|
|
2189
|
+
text = highlightChanges(
|
|
2190
|
+
this.process(text, origInTargetAlphabet),
|
|
2191
|
+
afterJoin(origInTargetAlphabet),
|
|
2192
|
+
wrapInTag.fix
|
|
2231
2193
|
);
|
|
2232
|
-
|
|
2233
|
-
text = join(splitted);
|
|
2234
|
-
if (isCyrillic)
|
|
2194
|
+
if (this.abc === ALPHABET.CYRILLIC)
|
|
2235
2195
|
text = replaceG(
|
|
2236
2196
|
text,
|
|
2237
2197
|
this.html.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
|
|
@@ -2274,9 +2234,9 @@ var Taraskevizer = class {
|
|
|
2274
2234
|
"\n"
|
|
2275
2235
|
);
|
|
2276
2236
|
}
|
|
2277
|
-
process(text) {
|
|
2237
|
+
process(text, textInTargetAlphabet) {
|
|
2278
2238
|
const { abc, j } = this;
|
|
2279
|
-
const splittedOrig =
|
|
2239
|
+
const splittedOrig = textInTargetAlphabet.split(" ");
|
|
2280
2240
|
text = this.taraskevize(text.toLowerCase());
|
|
2281
2241
|
if (j && abc !== ALPHABET.LATIN_JI)
|
|
2282
2242
|
text = replaceIbyJ(text, j === REPLACE_J.ALWAYS);
|
|
@@ -2284,7 +2244,7 @@ var Taraskevizer = class {
|
|
|
2284
2244
|
let splitted = text.split(" ");
|
|
2285
2245
|
if (abc !== ALPHABET.ARABIC)
|
|
2286
2246
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2287
|
-
return
|
|
2247
|
+
return join(splitted);
|
|
2288
2248
|
}
|
|
2289
2249
|
taraskevize(text) {
|
|
2290
2250
|
text = replaceWithDict(text, wordlist);
|
package/dist/index.js
CHANGED
|
@@ -1972,6 +1972,7 @@ for (const word of gwords)
|
|
|
1972
1972
|
wordlist.push([RegExp(word.replace(/ґ/g, "г"), "g"), word]);
|
|
1973
1973
|
|
|
1974
1974
|
// src/tarask.ts
|
|
1975
|
+
import { diffChars } from "diff";
|
|
1975
1976
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
1976
1977
|
var getLastLetter = (word, i) => {
|
|
1977
1978
|
for (let i2 = word.length - 1; i2 >= 0; i2--)
|
|
@@ -2031,7 +2032,8 @@ var afterTarask = [
|
|
|
2031
2032
|
]
|
|
2032
2033
|
];
|
|
2033
2034
|
var applyNoFix = (arr2, text) => arr2.length ? text.replace(NOFIX_REGEX, () => arr2.shift()) : text;
|
|
2034
|
-
var
|
|
2035
|
+
var afterJoin = (text) => text.replace(/ /g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d|() ", "gu"), "$1");
|
|
2036
|
+
var join = (textArr) => afterJoin(textArr.join(" "));
|
|
2035
2037
|
var finalize = (text, newLine) => text.replace(/ \t /g, " ").replace(/ \n /g, newLine).trim();
|
|
2036
2038
|
var replaceG = (text, replacer) => text.replace(
|
|
2037
2039
|
G_REGEX,
|
|
@@ -2063,58 +2065,13 @@ var restoreCase = (text, orig) => {
|
|
|
2063
2065
|
}
|
|
2064
2066
|
return text;
|
|
2065
2067
|
};
|
|
2066
|
-
var highlightChanges = (text, orig,
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
if (oWord === wordH)
|
|
2074
|
-
continue;
|
|
2075
|
-
if (!/\(/.test(word)) {
|
|
2076
|
-
if (word.length === oWord.length) {
|
|
2077
|
-
const wordLetters = word.split("");
|
|
2078
|
-
for (let j = 0; j < wordLetters.length; j++) {
|
|
2079
|
-
if (wordH[j] !== oWord[j])
|
|
2080
|
-
wordLetters[j] = highlight(wordLetters[j]);
|
|
2081
|
-
}
|
|
2082
|
-
text[i] = wordLetters.join("");
|
|
2083
|
-
continue;
|
|
2084
|
-
}
|
|
2085
|
-
if (isCyrillic) {
|
|
2086
|
-
const word1 = word.replace(/ь/g, "");
|
|
2087
|
-
switch (oWord) {
|
|
2088
|
-
case word1:
|
|
2089
|
-
text[i] = word.replace(/ь/g, highlight("ь"));
|
|
2090
|
-
continue;
|
|
2091
|
-
case word1 + "ь":
|
|
2092
|
-
text[i] = word.slice(0, -1).replace(/ь/g, highlight("ь")) + "ь";
|
|
2093
|
-
continue;
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
const oWordEnd = oWord.length - 1;
|
|
2098
|
-
let fromStart = 0;
|
|
2099
|
-
let fromWordEnd = word.length - 1;
|
|
2100
|
-
let fromOWordEnd = oWordEnd;
|
|
2101
|
-
while (wordH[fromStart] === oWord[fromStart])
|
|
2102
|
-
++fromStart;
|
|
2103
|
-
while (wordH[fromWordEnd] === oWord[fromOWordEnd]) {
|
|
2104
|
-
--fromWordEnd;
|
|
2105
|
-
--fromOWordEnd;
|
|
2106
|
-
}
|
|
2107
|
-
if (oWord.length < word.length) {
|
|
2108
|
-
if (fromOWordEnd === oWordEnd) {
|
|
2109
|
-
text[i] = highlight(word);
|
|
2110
|
-
continue;
|
|
2111
|
-
}
|
|
2112
|
-
if (fromWordEnd < 0)
|
|
2113
|
-
fromWordEnd = 0;
|
|
2114
|
-
}
|
|
2115
|
-
text[i] = word.slice(0, fromStart) + highlight(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
|
|
2116
|
-
}
|
|
2117
|
-
};
|
|
2068
|
+
var highlightChanges = (text, orig, highlight) => diffChars(orig, text).reduce(
|
|
2069
|
+
(acc, diff) => acc + (diff.removed ? "�" : diff.added ? highlight(diff.value) : diff.value),
|
|
2070
|
+
""
|
|
2071
|
+
).replace(
|
|
2072
|
+
/([^<>\x1b])�([^<>\x1b])/g,
|
|
2073
|
+
($0, $1, $2) => highlight($1 + $2)
|
|
2074
|
+
).replace(/�/g, "");
|
|
2118
2075
|
var replaceWithDict = (text, dict = []) => {
|
|
2119
2076
|
for (const [pattern, result] of dict)
|
|
2120
2077
|
text = text.replace(
|
|
@@ -2168,15 +2125,17 @@ var Taraskevizer = class {
|
|
|
2168
2125
|
}
|
|
2169
2126
|
convert(text) {
|
|
2170
2127
|
const wrapInColorOf = wrappers.ansiColors;
|
|
2171
|
-
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2172
2128
|
const noFixArr = [];
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
);
|
|
2129
|
+
text = this.prepare(text, noFixArr, "<");
|
|
2130
|
+
const origInTargetAlphabet = convertAlphabet(text, this.abc);
|
|
2131
|
+
text = this.process(text, origInTargetAlphabet);
|
|
2176
2132
|
if (this.nonHtml.ansiColors)
|
|
2177
|
-
highlightChanges(
|
|
2178
|
-
|
|
2179
|
-
|
|
2133
|
+
text = highlightChanges(
|
|
2134
|
+
text,
|
|
2135
|
+
afterJoin(origInTargetAlphabet),
|
|
2136
|
+
wrapInColorOf.fix
|
|
2137
|
+
);
|
|
2138
|
+
if (this.abc === ALPHABET.CYRILLIC && (this.nonHtml.h || this.nonHtml.ansiColors))
|
|
2180
2139
|
text = replaceG(
|
|
2181
2140
|
text,
|
|
2182
2141
|
this.nonHtml.ansiColors ? this.nonHtml.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
|
|
@@ -2193,14 +2152,15 @@ var Taraskevizer = class {
|
|
|
2193
2152
|
}
|
|
2194
2153
|
convertToHtml(text) {
|
|
2195
2154
|
const wrapInTag = wrappers.html;
|
|
2196
|
-
const isCyrillic = this.abc === ALPHABET.CYRILLIC;
|
|
2197
2155
|
const noFixArr = [];
|
|
2198
|
-
|
|
2199
|
-
|
|
2156
|
+
text = this.prepare(text, noFixArr, "<");
|
|
2157
|
+
const origInTargetAlphabet = convertAlphabet(text, this.abc);
|
|
2158
|
+
text = highlightChanges(
|
|
2159
|
+
this.process(text, origInTargetAlphabet),
|
|
2160
|
+
afterJoin(origInTargetAlphabet),
|
|
2161
|
+
wrapInTag.fix
|
|
2200
2162
|
);
|
|
2201
|
-
|
|
2202
|
-
text = join(splitted);
|
|
2203
|
-
if (isCyrillic)
|
|
2163
|
+
if (this.abc === ALPHABET.CYRILLIC)
|
|
2204
2164
|
text = replaceG(
|
|
2205
2165
|
text,
|
|
2206
2166
|
this.html.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
|
|
@@ -2243,9 +2203,9 @@ var Taraskevizer = class {
|
|
|
2243
2203
|
"\n"
|
|
2244
2204
|
);
|
|
2245
2205
|
}
|
|
2246
|
-
process(text) {
|
|
2206
|
+
process(text, textInTargetAlphabet) {
|
|
2247
2207
|
const { abc, j } = this;
|
|
2248
|
-
const splittedOrig =
|
|
2208
|
+
const splittedOrig = textInTargetAlphabet.split(" ");
|
|
2249
2209
|
text = this.taraskevize(text.toLowerCase());
|
|
2250
2210
|
if (j && abc !== ALPHABET.LATIN_JI)
|
|
2251
2211
|
text = replaceIbyJ(text, j === REPLACE_J.ALWAYS);
|
|
@@ -2253,7 +2213,7 @@ var Taraskevizer = class {
|
|
|
2253
2213
|
let splitted = text.split(" ");
|
|
2254
2214
|
if (abc !== ALPHABET.ARABIC)
|
|
2255
2215
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2256
|
-
return
|
|
2216
|
+
return join(splitted);
|
|
2257
2217
|
}
|
|
2258
2218
|
taraskevize(text) {
|
|
2259
2219
|
text = replaceWithDict(text, wordlist);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taraskevizer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"author": "GooseOb",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,14 +8,18 @@
|
|
|
8
8
|
},
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/index.js",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"diff": "^5.2.0"
|
|
13
|
+
},
|
|
11
14
|
"devDependencies": {
|
|
12
|
-
"@digitak/esrun": "^3.2.
|
|
13
|
-
"@types/
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"@digitak/esrun": "^3.2.26",
|
|
16
|
+
"@types/diff": "^5.2.0",
|
|
17
|
+
"@types/node": "^20.12.7",
|
|
18
|
+
"bun-types": "^1.1.4",
|
|
19
|
+
"husky": "^9.0.11",
|
|
20
|
+
"prettier": "^3.2.5",
|
|
21
|
+
"tsup": "^8.0.2",
|
|
22
|
+
"typescript": "^5.4.5"
|
|
19
23
|
},
|
|
20
24
|
"bin": {
|
|
21
25
|
"tarask": "dist/bin.js"
|
|
@@ -46,7 +50,7 @@
|
|
|
46
50
|
"dev-bun": "bun test --watch",
|
|
47
51
|
"test": "esrun --send-code-mode=temporaryFile test",
|
|
48
52
|
"test-cli": "bun run build && esrun --send-code-mode=temporaryFile test",
|
|
49
|
-
"prepare": "husky
|
|
53
|
+
"prepare": "husky",
|
|
50
54
|
"typecheck": "tsc --project src/tsconfig.json"
|
|
51
55
|
},
|
|
52
56
|
"type": "module",
|