taraskevizer 1.4.1 → 1.4.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 +14 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2084,7 +2084,13 @@ for (const word of gwords)
|
|
|
2084
2084
|
wordlist.push([word, RegExp(word.replace(/ґ/g, "г"), "g")]);
|
|
2085
2085
|
|
|
2086
2086
|
// src/tarask.ts
|
|
2087
|
+
var isObject = (arg) => typeof arg === "object";
|
|
2087
2088
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
2089
|
+
var getLastLetter = (word) => {
|
|
2090
|
+
for (let i = word.length - 1; i > 0; i--)
|
|
2091
|
+
if (/\p{L}/u.test(word[i]))
|
|
2092
|
+
return word[i];
|
|
2093
|
+
};
|
|
2088
2094
|
var NOFIX_CHAR = " ";
|
|
2089
2095
|
var NOFIX_REGEX = new RegExp(NOFIX_CHAR, "g");
|
|
2090
2096
|
var OPTIONAL_WORDS_REGEX = /\(.*?\)/g;
|
|
@@ -2126,13 +2132,15 @@ var tagApplications = {
|
|
|
2126
2132
|
};
|
|
2127
2133
|
var taraskSync = (text, options) => {
|
|
2128
2134
|
const { abc = 0, j = 0, html = false, nonHtml = false } = options || {};
|
|
2129
|
-
|
|
2135
|
+
const isHtmlObject = isObject(html);
|
|
2136
|
+
const isNonHtmlObject = isObject(nonHtml);
|
|
2137
|
+
if (isNonHtmlObject) {
|
|
2130
2138
|
nonHtml.variations || (nonHtml.variations = 0);
|
|
2131
2139
|
}
|
|
2132
2140
|
const apply = html ? tagApplications.html : tagApplications.nonHtml;
|
|
2133
2141
|
const noFix = [];
|
|
2134
2142
|
const LEFT_ANGLE_BRACKET = html ? "<" : "<";
|
|
2135
|
-
text = ` ${text.trim()} `.replace(/<([,.]?)((?:.|\s)*?)>/g, ($0, $1, $2) => {
|
|
2143
|
+
text = ` ${text.trim()} `.replace(/�/g, "").replace(/<([,.]?)((?:.|\s)*?)>/g, ($0, $1, $2) => {
|
|
2136
2144
|
if ($1 === ",")
|
|
2137
2145
|
return LEFT_ANGLE_BRACKET + $2 + ">";
|
|
2138
2146
|
noFix[noFix.length] = $1 === "." ? $2 : $0;
|
|
@@ -2152,17 +2160,17 @@ var taraskSync = (text, options) => {
|
|
|
2152
2160
|
splitted = text.split(" ");
|
|
2153
2161
|
if (abc !== ALPHABET.ARABIC)
|
|
2154
2162
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2155
|
-
const nodeColors =
|
|
2163
|
+
const nodeColors = isNonHtmlObject && nonHtml.nodeColors;
|
|
2156
2164
|
if (html || nodeColors)
|
|
2157
2165
|
splitted = toTags(splitted, splittedOrig, abc, apply.F);
|
|
2158
2166
|
text = splitted.join(" ").replace(/ /g, " ").replace(/ (\p{P}|\p{S}|\d|() /gu, "$1");
|
|
2159
2167
|
let gReplacer;
|
|
2160
2168
|
if (html) {
|
|
2161
2169
|
text = replaceWithDict(text, additionalReplacements[abc]);
|
|
2162
|
-
if (abc === ALPHABET.CYRILLIC) {
|
|
2170
|
+
if (isHtmlObject && abc === ALPHABET.CYRILLIC) {
|
|
2163
2171
|
gReplacer = html.g ? apply.H("$&") : ($0) => apply.H(gobj[$0]);
|
|
2164
2172
|
}
|
|
2165
|
-
} else if (
|
|
2173
|
+
} else if (isNonHtmlObject && abc === ALPHABET.CYRILLIC) {
|
|
2166
2174
|
if (nonHtml.nodeColors) {
|
|
2167
2175
|
gReplacer = nonHtml.h ? ($0) => apply.H(gobj[$0]) : apply.H("$&");
|
|
2168
2176
|
} else if (nonHtml.h) {
|
|
@@ -2201,11 +2209,6 @@ function restoreCase(text, orig) {
|
|
|
2201
2209
|
}
|
|
2202
2210
|
return text;
|
|
2203
2211
|
}
|
|
2204
|
-
var getLastLetter = (word) => {
|
|
2205
|
-
for (let i = word.length - 1; i > 1; i--)
|
|
2206
|
-
if (/\p{L}/u.test(word[i]))
|
|
2207
|
-
return word[i];
|
|
2208
|
-
};
|
|
2209
2212
|
function toTags(text, orig, abc, applyF) {
|
|
2210
2213
|
for (let i = 0; i < text.length; i++) {
|
|
2211
2214
|
const word = text[i];
|
|
@@ -2297,7 +2300,7 @@ var finalizer = {
|
|
|
2297
2300
|
return `<tarL data-l='${options}'>${main}</tarL>`;
|
|
2298
2301
|
}).replace(/ \n /g, "<br>"),
|
|
2299
2302
|
nonHtml(text, options) {
|
|
2300
|
-
if (options && options.variations !== VARIATION.ALL) {
|
|
2303
|
+
if (isObject(options) && options.variations !== VARIATION.ALL) {
|
|
2301
2304
|
const WORD_INDEX = options.variations;
|
|
2302
2305
|
const replacer = ($0) => $0.slice(1, -1).split("|")[WORD_INDEX];
|
|
2303
2306
|
text = text.replace(
|
package/dist/index.d.ts
CHANGED
|
@@ -17,11 +17,11 @@ type TaraskOptionsStrict = {
|
|
|
17
17
|
abc: Alphabet;
|
|
18
18
|
j: J$1;
|
|
19
19
|
} & ({
|
|
20
|
-
html: HtmlOptions;
|
|
20
|
+
html: true | HtmlOptions;
|
|
21
21
|
nonHtml: false;
|
|
22
22
|
} | {
|
|
23
23
|
html: false;
|
|
24
|
-
nonHtml: NonHtmlOptions;
|
|
24
|
+
nonHtml: true | NonHtmlOptions;
|
|
25
25
|
});
|
|
26
26
|
type TaraskOptions = DeepPartial<TaraskOptionsStrict>;
|
|
27
27
|
type Tarask = (text: string, options?: TaraskOptions) => string;
|
package/dist/index.js
CHANGED
|
@@ -2054,7 +2054,13 @@ for (const word of gwords)
|
|
|
2054
2054
|
wordlist.push([word, RegExp(word.replace(/ґ/g, "г"), "g")]);
|
|
2055
2055
|
|
|
2056
2056
|
// src/tarask.ts
|
|
2057
|
+
var isObject = (arg) => typeof arg === "object";
|
|
2057
2058
|
var isUpperCase = (str) => str === str.toUpperCase();
|
|
2059
|
+
var getLastLetter = (word) => {
|
|
2060
|
+
for (let i = word.length - 1; i > 0; i--)
|
|
2061
|
+
if (/\p{L}/u.test(word[i]))
|
|
2062
|
+
return word[i];
|
|
2063
|
+
};
|
|
2058
2064
|
var NOFIX_CHAR = " ";
|
|
2059
2065
|
var NOFIX_REGEX = new RegExp(NOFIX_CHAR, "g");
|
|
2060
2066
|
var OPTIONAL_WORDS_REGEX = /\(.*?\)/g;
|
|
@@ -2096,13 +2102,15 @@ var tagApplications = {
|
|
|
2096
2102
|
};
|
|
2097
2103
|
var taraskSync = (text, options) => {
|
|
2098
2104
|
const { abc = 0, j = 0, html = false, nonHtml = false } = options || {};
|
|
2099
|
-
|
|
2105
|
+
const isHtmlObject = isObject(html);
|
|
2106
|
+
const isNonHtmlObject = isObject(nonHtml);
|
|
2107
|
+
if (isNonHtmlObject) {
|
|
2100
2108
|
nonHtml.variations || (nonHtml.variations = 0);
|
|
2101
2109
|
}
|
|
2102
2110
|
const apply = html ? tagApplications.html : tagApplications.nonHtml;
|
|
2103
2111
|
const noFix = [];
|
|
2104
2112
|
const LEFT_ANGLE_BRACKET = html ? "<" : "<";
|
|
2105
|
-
text = ` ${text.trim()} `.replace(/<([,.]?)((?:.|\s)*?)>/g, ($0, $1, $2) => {
|
|
2113
|
+
text = ` ${text.trim()} `.replace(/�/g, "").replace(/<([,.]?)((?:.|\s)*?)>/g, ($0, $1, $2) => {
|
|
2106
2114
|
if ($1 === ",")
|
|
2107
2115
|
return LEFT_ANGLE_BRACKET + $2 + ">";
|
|
2108
2116
|
noFix[noFix.length] = $1 === "." ? $2 : $0;
|
|
@@ -2122,17 +2130,17 @@ var taraskSync = (text, options) => {
|
|
|
2122
2130
|
splitted = text.split(" ");
|
|
2123
2131
|
if (abc !== ALPHABET.ARABIC)
|
|
2124
2132
|
splitted = restoreCase(splitted, splittedOrig);
|
|
2125
|
-
const nodeColors =
|
|
2133
|
+
const nodeColors = isNonHtmlObject && nonHtml.nodeColors;
|
|
2126
2134
|
if (html || nodeColors)
|
|
2127
2135
|
splitted = toTags(splitted, splittedOrig, abc, apply.F);
|
|
2128
2136
|
text = splitted.join(" ").replace(/ /g, " ").replace(/ (\p{P}|\p{S}|\d|() /gu, "$1");
|
|
2129
2137
|
let gReplacer;
|
|
2130
2138
|
if (html) {
|
|
2131
2139
|
text = replaceWithDict(text, additionalReplacements[abc]);
|
|
2132
|
-
if (abc === ALPHABET.CYRILLIC) {
|
|
2140
|
+
if (isHtmlObject && abc === ALPHABET.CYRILLIC) {
|
|
2133
2141
|
gReplacer = html.g ? apply.H("$&") : ($0) => apply.H(gobj[$0]);
|
|
2134
2142
|
}
|
|
2135
|
-
} else if (
|
|
2143
|
+
} else if (isNonHtmlObject && abc === ALPHABET.CYRILLIC) {
|
|
2136
2144
|
if (nonHtml.nodeColors) {
|
|
2137
2145
|
gReplacer = nonHtml.h ? ($0) => apply.H(gobj[$0]) : apply.H("$&");
|
|
2138
2146
|
} else if (nonHtml.h) {
|
|
@@ -2171,11 +2179,6 @@ function restoreCase(text, orig) {
|
|
|
2171
2179
|
}
|
|
2172
2180
|
return text;
|
|
2173
2181
|
}
|
|
2174
|
-
var getLastLetter = (word) => {
|
|
2175
|
-
for (let i = word.length - 1; i > 1; i--)
|
|
2176
|
-
if (/\p{L}/u.test(word[i]))
|
|
2177
|
-
return word[i];
|
|
2178
|
-
};
|
|
2179
2182
|
function toTags(text, orig, abc, applyF) {
|
|
2180
2183
|
for (let i = 0; i < text.length; i++) {
|
|
2181
2184
|
const word = text[i];
|
|
@@ -2267,7 +2270,7 @@ var finalizer = {
|
|
|
2267
2270
|
return `<tarL data-l='${options}'>${main}</tarL>`;
|
|
2268
2271
|
}).replace(/ \n /g, "<br>"),
|
|
2269
2272
|
nonHtml(text, options) {
|
|
2270
|
-
if (options && options.variations !== VARIATION.ALL) {
|
|
2273
|
+
if (isObject(options) && options.variations !== VARIATION.ALL) {
|
|
2271
2274
|
const WORD_INDEX = options.variations;
|
|
2272
2275
|
const replacer = ($0) => $0.slice(1, -1).split("|")[WORD_INDEX];
|
|
2273
2276
|
text = text.replace(
|