taraskevizer 8.0.1 → 8.0.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/bin.js CHANGED
@@ -14,7 +14,7 @@ const printWithPrefix = (msg) => {
14
14
  process.argv.splice(0, 2);
15
15
  const checkForOptions = (options) => process.argv[0] && options.includes(process.argv[0].toLowerCase());
16
16
  if (checkForOptions(["-v", "--version"])) {
17
- printWithPrefix("8.0.1");
17
+ printWithPrefix("8.0.3");
18
18
  process.exit(0);
19
19
  }
20
20
  if (checkForOptions(["-h", "--help"])) {
package/dist/index.cjs CHANGED
@@ -2106,7 +2106,6 @@ var tarask = (text, pipeline, cfg = new TaraskConfig()) => {
2106
2106
  // src/steps/index.ts
2107
2107
  var steps_exports = {};
2108
2108
  __export(steps_exports, {
2109
- afterJoin: () => afterJoin,
2110
2109
  applyGHtml: () => applyGHtml,
2111
2110
  applyGNonHtml: () => applyGNonHtml,
2112
2111
  applyNoFix: () => applyNoFix,
@@ -2123,7 +2122,6 @@ __export(steps_exports, {
2123
2122
  replaceIbyJ: () => replaceIbyJ,
2124
2123
  resolveSpecialSyntax: () => resolveSpecialSyntax,
2125
2124
  restoreCaseStep: () => restoreCaseStep,
2126
- restoreParentheses: () => restoreParentheses,
2127
2125
  restoreWhitespaces: () => restoreWhitespaces,
2128
2126
  storeSplittedAbcConvertedOrig: () => storeSplittedAbcConvertedOrig,
2129
2127
  storeSplittedText: () => storeSplittedText,
@@ -2141,6 +2139,7 @@ __export(lib_exports, {
2141
2139
  dictFrom: () => dictFrom,
2142
2140
  highlightDiff: () => highlightDiff,
2143
2141
  htmlWrappers: () => htmlWrappers,
2142
+ mutatingStep: () => mutatingStep,
2144
2143
  replaceG: () => replaceG,
2145
2144
  replaceWithDict: () => replaceWithDict,
2146
2145
  restoreCase: () => restoreCase
@@ -2283,15 +2282,33 @@ var ansiColorWrappers = {
2283
2282
  variable: (content) => `\x1B[35m${content}\x1B[0m`
2284
2283
  };
2285
2284
 
2286
- // src/steps/convert-alphabet.ts
2287
- var convertAlphabet = (options) => {
2288
- const { lower, upper } = options.cfg.general.abc;
2289
- options.text = replaceWithDict(replaceWithDict(options.text, lower), upper);
2290
- };
2291
- var convertAlphabetLowerCase = (options) => {
2292
- options.text = replaceWithDict(options.text, options.cfg.general.abc.lower);
2285
+ // src/lib/mutating-step.ts
2286
+ var mutatingStep = (callback) => (options) => {
2287
+ options.text = callback(options);
2293
2288
  };
2294
2289
 
2290
+ // src/steps/convert-alphabet.ts
2291
+ var convertAlphabet = mutatingStep(
2292
+ ({
2293
+ text,
2294
+ cfg: {
2295
+ general: {
2296
+ abc: { upper, lower }
2297
+ }
2298
+ }
2299
+ }) => replaceWithDict(replaceWithDict(text, lower), upper)
2300
+ );
2301
+ var convertAlphabetLowerCase = mutatingStep(
2302
+ ({
2303
+ text,
2304
+ cfg: {
2305
+ general: {
2306
+ abc: { lower }
2307
+ }
2308
+ }
2309
+ }) => replaceWithDict(text, lower)
2310
+ );
2311
+
2295
2312
  // src/steps/highlight-diff.ts
2296
2313
  var highlightDiffStep = (highlight) => ({
2297
2314
  cfg: {
@@ -2329,9 +2346,9 @@ var replaceIbyJ = (options) => {
2329
2346
  };
2330
2347
 
2331
2348
  // src/steps/join-splitted.ts
2332
- var joinSplittedText = (options) => {
2333
- options.text = options.storage.textArr.join(" ");
2334
- };
2349
+ var joinSplittedText = mutatingStep(
2350
+ ({ storage: { textArr } }) => textArr.join(" ")
2351
+ );
2335
2352
 
2336
2353
  // src/steps/apply-g.ts
2337
2354
  var applyGHtml = (options) => {
@@ -2356,12 +2373,9 @@ var applyGNonHtml = (options) => {
2356
2373
  };
2357
2374
 
2358
2375
  // src/steps/apply-variations.ts
2359
- var applyVariableParts = (callback) => (options) => {
2360
- options.text = options.text.replace(
2361
- /\([^)]*?\)/g,
2362
- ($0) => callback($0.slice(1, -1).split("|"))
2363
- );
2364
- };
2376
+ var applyVariableParts = (callback) => mutatingStep(
2377
+ ({ text }) => text.replace(/\([^)]*?\)/g, ($0) => callback($0.slice(1, -1).split("|")))
2378
+ );
2365
2379
  var applyVariationsHtml = applyVariableParts((parts) => {
2366
2380
  const main = parts.shift();
2367
2381
  return `<tarL data-l='${parts}'>${main}</tarL>`;
@@ -2376,9 +2390,9 @@ var applyVariationsNonHtml = (options) => {
2376
2390
  };
2377
2391
 
2378
2392
  // src/steps/prepare.ts
2379
- var prepare = (options) => {
2380
- options.text = options.text.replace(/г'(?![еёіюя])/g, "ґ").replace(/ - /g, " — ").replace(new RegExp("(\\p{P}|\\p{S}|\\d+)", "gu"), " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40");
2381
- };
2393
+ var prepare = mutatingStep(
2394
+ ({ text }) => text.replace(/г'(?![еёіюя])/g, "ґ").replace(/ - /g, " — ").replace(new RegExp("(\\p{P}|\\p{S}|\\d+)", "gu"), " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40")
2395
+ );
2382
2396
 
2383
2397
  // src/steps/resolve-syntax.ts
2384
2398
  var NOFIX_CHAR = "  ";
@@ -2388,77 +2402,76 @@ var applyNoFix = (options) => {
2388
2402
  if (noFixArr.length)
2389
2403
  options.text = options.text.replace(NOFIX_REGEX, () => noFixArr.shift());
2390
2404
  };
2391
- var resolveSpecialSyntax = (leftAngleBracket) => (options) => {
2392
- const {
2405
+ var resolveSpecialSyntax = (leftAngleBracket) => mutatingStep(
2406
+ ({
2393
2407
  text,
2394
2408
  storage,
2395
2409
  cfg: {
2396
2410
  general: { doEscapeCapitalized, abc }
2397
2411
  }
2398
- } = options;
2399
- const noFixArr = storage.noFixArr = [];
2400
- const convertAlphavet = (abcOnlyText, abc2) => restoreCase(
2401
- replaceWithDict(abcOnlyText.toLowerCase(), abc2.lower).split(" "),
2402
- abcOnlyText.split(" ")
2403
- ).join(" ");
2404
- const escapeCapsIfNeeded = (text2) => doEscapeCapitalized ? text2.replace(
2405
- new RegExp("(?!<=\\p{Lu} )\\p{Lu}{2}[\\p{Lu} ]*(?!= \\p{Lu})", "gu"),
2406
- ($0) => {
2407
- noFixArr.push(convertAlphavet($0, abc));
2408
- return NOFIX_CHAR;
2409
- }
2410
- ) : text2;
2411
- const parts = text.split(/(?=[<>])/g);
2412
- if (parts.length === 1) {
2413
- options.text = escapeCapsIfNeeded(text);
2414
- return;
2415
- }
2416
- let result = text.startsWith("<") ? "" : escapeCapsIfNeeded(parts.shift());
2417
- let depth = 0;
2418
- let currentPart = "";
2419
- for (const part of parts) {
2420
- if (part.startsWith("<")) {
2421
- ++depth;
2422
- currentPart += part;
2423
- } else if (depth) {
2424
- --depth;
2425
- if (depth) {
2412
+ }) => {
2413
+ const noFixArr = storage.noFixArr = [];
2414
+ const convertAlphavet = (abcOnlyText, abc2) => restoreCase(
2415
+ replaceWithDict(abcOnlyText.toLowerCase(), abc2.lower).split(" "),
2416
+ abcOnlyText.split(" ")
2417
+ ).join(" ");
2418
+ const escapeCapsIfNeeded = (text2) => doEscapeCapitalized ? text2.replace(
2419
+ new RegExp("(?!<=\\p{Lu} )\\p{Lu}{2}[\\p{Lu} ]*(?!= \\p{Lu})", "gu"),
2420
+ ($0) => {
2421
+ noFixArr.push(convertAlphavet($0, abc));
2422
+ return NOFIX_CHAR;
2423
+ }
2424
+ ) : text2;
2425
+ const parts = text.split(/(?=[<>])/g);
2426
+ if (parts.length === 1)
2427
+ return escapeCapsIfNeeded(text);
2428
+ let result = text.startsWith("<") ? "" : escapeCapsIfNeeded(parts.shift());
2429
+ let depth = 0;
2430
+ let currentPart = "";
2431
+ for (const part of parts) {
2432
+ if (part.startsWith("<")) {
2433
+ ++depth;
2426
2434
  currentPart += part;
2427
- } else {
2428
- let char = "";
2429
- const isAbc = currentPart[1] === "*";
2430
- if (isAbc) {
2431
- char = currentPart[2];
2432
- currentPart = convertAlphavet(
2433
- currentPart.slice(char === "," || char === "." ? 3 : 2),
2434
- abc
2435
- );
2435
+ } else if (depth) {
2436
+ --depth;
2437
+ if (depth) {
2438
+ currentPart += part;
2436
2439
  } else {
2437
- char = currentPart[1];
2438
- currentPart = currentPart.slice(2);
2440
+ let char = "";
2441
+ const isAbc = currentPart[1] === "*";
2442
+ if (isAbc) {
2443
+ char = currentPart[2];
2444
+ currentPart = convertAlphavet(
2445
+ currentPart.slice(char === "," || char === "." ? 3 : 2),
2446
+ abc
2447
+ );
2448
+ } else {
2449
+ char = currentPart[1];
2450
+ currentPart = currentPart.slice(2);
2451
+ }
2452
+ let toAddToResult;
2453
+ switch (char) {
2454
+ case ".":
2455
+ toAddToResult = NOFIX_CHAR;
2456
+ noFixArr.push(currentPart);
2457
+ break;
2458
+ case ",":
2459
+ toAddToResult = leftAngleBracket + currentPart + ">";
2460
+ break;
2461
+ default:
2462
+ toAddToResult = leftAngleBracket + NOFIX_CHAR;
2463
+ noFixArr.push((isAbc ? "" : char) + currentPart + ">");
2464
+ }
2465
+ result += toAddToResult + escapeCapsIfNeeded(part.slice(1));
2466
+ currentPart = "";
2439
2467
  }
2440
- let toAddToResult;
2441
- switch (char) {
2442
- case ".":
2443
- toAddToResult = NOFIX_CHAR;
2444
- noFixArr.push(currentPart);
2445
- break;
2446
- case ",":
2447
- toAddToResult = leftAngleBracket + currentPart + ">";
2448
- break;
2449
- default:
2450
- toAddToResult = leftAngleBracket + NOFIX_CHAR;
2451
- noFixArr.push((isAbc ? "" : char) + currentPart + ">");
2452
- }
2453
- result += toAddToResult + escapeCapsIfNeeded(part.slice(1));
2454
- currentPart = "";
2468
+ } else {
2469
+ result += escapeCapsIfNeeded(part);
2455
2470
  }
2456
- } else {
2457
- result += escapeCapsIfNeeded(part);
2458
2471
  }
2472
+ return result + escapeCapsIfNeeded(currentPart);
2459
2473
  }
2460
- options.text = result + escapeCapsIfNeeded(currentPart);
2461
- };
2474
+ );
2462
2475
 
2463
2476
  // src/steps/restore-case.ts
2464
2477
  var restoreCaseStep = ({
@@ -2502,8 +2515,7 @@ var storeSplittedText = ({
2502
2515
 
2503
2516
  // src/steps/taraskevize.ts
2504
2517
  var wordlistPlusNoSoften = wordlist.concat(noSoften);
2505
- var taraskevize = (options) => {
2506
- let { text } = options;
2518
+ var taraskevize = mutatingStep(({ text }) => {
2507
2519
  text = replaceWithDict(text, wordlistPlusNoSoften);
2508
2520
  softening:
2509
2521
  do {
@@ -2513,42 +2525,39 @@ var taraskevize = (options) => {
2513
2525
  continue softening;
2514
2526
  break;
2515
2527
  } while (true);
2516
- options.text = replaceWithDict(text.replace(//g, ""), afterTarask);
2517
- };
2528
+ return replaceWithDict(
2529
+ text.replace(//g, "").replace(/не пра/g, "не&nbsp;пра"),
2530
+ afterTarask
2531
+ ).replace(/не&nbsp;пра/g, "не пра");
2532
+ });
2518
2533
 
2519
2534
  // src/steps/whitespaces.ts
2520
- var whitespacesToSpaces = (options) => {
2521
- const { storage } = options;
2522
- storage.spaces = [];
2523
- options.text = options.text.replace(/\s+/g, (match) => {
2524
- storage.spaces.push(match);
2525
- return " ";
2526
- });
2527
- };
2528
- var restoreWhitespaces = (options) => {
2529
- const { spaces } = options.storage;
2530
- spaces.reverse();
2531
- options.text = options.text.replace(/ /g, () => spaces.pop());
2532
- };
2535
+ var whitespacesToSpaces = mutatingStep(
2536
+ ({ text, storage }) => {
2537
+ storage.spaces = [];
2538
+ return text.replace(/\s+/g, (match) => {
2539
+ storage.spaces.push(match);
2540
+ return " ";
2541
+ });
2542
+ }
2543
+ );
2544
+ var restoreWhitespaces = mutatingStep(
2545
+ ({ text, storage: { spaces } }) => {
2546
+ spaces.reverse();
2547
+ return text.replace(/ /g, () => spaces.pop());
2548
+ }
2549
+ );
2533
2550
 
2534
2551
  // src/steps/trim.ts
2535
- var trim = (options) => {
2536
- options.text = ` ${options.text.trim()} `;
2537
- };
2552
+ var trim = mutatingStep(({ text }) => ` ${text.trim()} `);
2538
2553
 
2539
- // src/steps/other.ts
2540
- var restoreParentheses = (options) => {
2541
- options.text = options.text.replace(/&#40/g, "(");
2542
- };
2543
- var afterJoin = (options) => {
2544
- options.text = options.text.replace(/&nbsp;/g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d+|&#40) ", "gu"), "$1");
2545
- };
2546
- var finalize = (newLine) => (options) => {
2547
- options.text = options.text.replace(/\n/g, newLine).trim();
2548
- };
2549
- var toLowerCase = (options) => {
2550
- options.text = options.text.toLowerCase();
2551
- };
2554
+ // src/steps/finalize.ts
2555
+ var finalize = (newLine) => mutatingStep(
2556
+ ({ text }) => text.replace(/&#40/g, "(").replace(/&nbsp;/g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d+) ", "gu"), "$1").replace(/\n/g, newLine).trim()
2557
+ );
2558
+
2559
+ // src/steps/to-lower-case.ts
2560
+ var toLowerCase = mutatingStep(({ text }) => text.toLowerCase());
2552
2561
 
2553
2562
  // src/pipelines.ts
2554
2563
  var pipelines_exports = {};
@@ -2571,8 +2580,6 @@ var abcOnly = [
2571
2580
  convertAlphabet,
2572
2581
  restoreWhitespaces,
2573
2582
  applyNoFix,
2574
- restoreParentheses,
2575
- afterJoin,
2576
2583
  finalizeWithNewLine,
2577
2584
  ({ storage, cfg: { general } }) => {
2578
2585
  general.doEscapeCapitalized = storage.doEscapeCapitalized;
@@ -2593,8 +2600,6 @@ var createPipeline = (resolveSpecialSyntax2, applyG, applyVariations, finalize2,
2593
2600
  highlightDiffStep2,
2594
2601
  joinSplittedText,
2595
2602
  restoreWhitespaces,
2596
- restoreParentheses,
2597
- afterJoin,
2598
2603
  applyG,
2599
2604
  applyVariations,
2600
2605
  applyNoFix,
package/dist/index.d.ts CHANGED
@@ -175,7 +175,7 @@ declare class TaraskConfig {
175
175
  nonHtml: NonHtmlOptions;
176
176
  }
177
177
 
178
- type TaraskStep<Storage = {}> = (args: {
178
+ type TaraskStep<Storage extends object = {}> = (args: {
179
179
  text: string;
180
180
  storage: Storage;
181
181
  cfg: TaraskConfig;
@@ -185,8 +185,8 @@ type SplittedTextStorage = {
185
185
  origArr: readonly string[];
186
186
  };
187
187
 
188
- declare const convertAlphabet: TaraskStep;
189
- declare const convertAlphabetLowerCase: TaraskStep;
188
+ declare const convertAlphabet: TaraskStep<{}>;
189
+ declare const convertAlphabetLowerCase: TaraskStep<{}>;
190
190
 
191
191
  /**
192
192
  * Uses {@link highlightDiff}
@@ -228,7 +228,12 @@ declare const applyVariationsHtml: TaraskStep;
228
228
  */
229
229
  declare const applyVariationsNonHtml: TaraskStep;
230
230
 
231
- declare const prepare: TaraskStep;
231
+ /**
232
+ * Prepares the text for correct processing.
233
+ *
234
+ * Some changes should be reverted in the {@link finalize} step.
235
+ */
236
+ declare const prepare: TaraskStep<{}>;
232
237
 
233
238
  /**
234
239
  * Created in {@link resolveSpecialSyntax}.
@@ -260,7 +265,7 @@ declare const storeSplittedAbcConvertedOrig: TaraskStep<SplittedTextStorage>;
260
265
 
261
266
  declare const storeSplittedText: TaraskStep<SplittedTextStorage>;
262
267
 
263
- declare const taraskevize: TaraskStep;
268
+ declare const taraskevize: TaraskStep<{}>;
264
269
 
265
270
  /**
266
271
  * Created in {@link whitespacesToSpaces}.
@@ -283,12 +288,23 @@ declare const whitespacesToSpaces: TaraskStep<WhiteSpaceStorage>;
283
288
  */
284
289
  declare const restoreWhitespaces: TaraskStep<WhiteSpaceStorage>;
285
290
 
286
- declare const trim: TaraskStep;
291
+ declare const trim: TaraskStep<{}>;
287
292
 
288
- declare const restoreParentheses: TaraskStep;
289
- declare const afterJoin: TaraskStep;
293
+ /**
294
+ * @param newLine - The string to replace new lines with.
295
+ *
296
+ * Reverse the changes made in the {@link prepare} step
297
+ * and replace new lines with the passed string.
298
+ *
299
+ * Restores:
300
+ * `(` from `&#40`,
301
+ * ` ` from `&nbsp;`,
302
+ *
303
+ * Removes spaces around punctuation marks and digits.
304
+ */
290
305
  declare const finalize: (newLine: string) => TaraskStep;
291
- declare const toLowerCase: TaraskStep;
306
+
307
+ declare const toLowerCase: TaraskStep<{}>;
292
308
 
293
309
  /**
294
310
  * This module exports all the steps
@@ -305,9 +321,8 @@ declare const toLowerCase: TaraskStep;
305
321
 
306
322
  type index$1_SpecialSyntaxStorage = SpecialSyntaxStorage;
307
323
  type index$1_SplittedTextStorage = SplittedTextStorage;
308
- type index$1_TaraskStep<Storage = {}> = TaraskStep<Storage>;
324
+ type index$1_TaraskStep<Storage extends object = {}> = TaraskStep<Storage>;
309
325
  type index$1_WhiteSpaceStorage = WhiteSpaceStorage;
310
- declare const index$1_afterJoin: typeof afterJoin;
311
326
  declare const index$1_applyGHtml: typeof applyGHtml;
312
327
  declare const index$1_applyGNonHtml: typeof applyGNonHtml;
313
328
  declare const index$1_applyNoFix: typeof applyNoFix;
@@ -324,7 +339,6 @@ declare const index$1_prepare: typeof prepare;
324
339
  declare const index$1_replaceIbyJ: typeof replaceIbyJ;
325
340
  declare const index$1_resolveSpecialSyntax: typeof resolveSpecialSyntax;
326
341
  declare const index$1_restoreCaseStep: typeof restoreCaseStep;
327
- declare const index$1_restoreParentheses: typeof restoreParentheses;
328
342
  declare const index$1_restoreWhitespaces: typeof restoreWhitespaces;
329
343
  declare const index$1_storeSplittedAbcConvertedOrig: typeof storeSplittedAbcConvertedOrig;
330
344
  declare const index$1_storeSplittedText: typeof storeSplittedText;
@@ -333,7 +347,7 @@ declare const index$1_toLowerCase: typeof toLowerCase;
333
347
  declare const index$1_trim: typeof trim;
334
348
  declare const index$1_whitespacesToSpaces: typeof whitespacesToSpaces;
335
349
  declare namespace index$1 {
336
- export { type index$1_SpecialSyntaxStorage as SpecialSyntaxStorage, type index$1_SplittedTextStorage as SplittedTextStorage, type index$1_TaraskStep as TaraskStep, type index$1_WhiteSpaceStorage as WhiteSpaceStorage, index$1_afterJoin as afterJoin, index$1_applyGHtml as applyGHtml, index$1_applyGNonHtml as applyGNonHtml, index$1_applyNoFix as applyNoFix, index$1_applyVariableParts as applyVariableParts, index$1_applyVariationsHtml as applyVariationsHtml, index$1_applyVariationsNonHtml as applyVariationsNonHtml, index$1_convertAlphabet as convertAlphabet, index$1_convertAlphabetLowerCase as convertAlphabetLowerCase, index$1_finalize as finalize, index$1_highlightDiffStep as highlightDiffStep, index$1_highlightDiffStepNonHtml as highlightDiffStepNonHtml, index$1_joinSplittedText as joinSplittedText, index$1_prepare as prepare, index$1_replaceIbyJ as replaceIbyJ, index$1_resolveSpecialSyntax as resolveSpecialSyntax, index$1_restoreCaseStep as restoreCaseStep, index$1_restoreParentheses as restoreParentheses, index$1_restoreWhitespaces as restoreWhitespaces, index$1_storeSplittedAbcConvertedOrig as storeSplittedAbcConvertedOrig, index$1_storeSplittedText as storeSplittedText, index$1_taraskevize as taraskevize, index$1_toLowerCase as toLowerCase, index$1_trim as trim, index$1_whitespacesToSpaces as whitespacesToSpaces };
350
+ export { type index$1_SpecialSyntaxStorage as SpecialSyntaxStorage, type index$1_SplittedTextStorage as SplittedTextStorage, type index$1_TaraskStep as TaraskStep, type index$1_WhiteSpaceStorage as WhiteSpaceStorage, index$1_applyGHtml as applyGHtml, index$1_applyGNonHtml as applyGNonHtml, index$1_applyNoFix as applyNoFix, index$1_applyVariableParts as applyVariableParts, index$1_applyVariationsHtml as applyVariationsHtml, index$1_applyVariationsNonHtml as applyVariationsNonHtml, index$1_convertAlphabet as convertAlphabet, index$1_convertAlphabetLowerCase as convertAlphabetLowerCase, index$1_finalize as finalize, index$1_highlightDiffStep as highlightDiffStep, index$1_highlightDiffStepNonHtml as highlightDiffStepNonHtml, index$1_joinSplittedText as joinSplittedText, index$1_prepare as prepare, index$1_replaceIbyJ as replaceIbyJ, index$1_resolveSpecialSyntax as resolveSpecialSyntax, index$1_restoreCaseStep as restoreCaseStep, index$1_restoreWhitespaces as restoreWhitespaces, index$1_storeSplittedAbcConvertedOrig as storeSplittedAbcConvertedOrig, index$1_storeSplittedText as storeSplittedText, index$1_taraskevize as taraskevize, index$1_toLowerCase as toLowerCase, index$1_trim as trim, index$1_whitespacesToSpaces as whitespacesToSpaces };
337
351
  }
338
352
 
339
353
  /**
@@ -407,6 +421,14 @@ declare const ansiColorWrappers: {
407
421
  variable: (content: string) => string;
408
422
  };
409
423
 
424
+ /**
425
+ * An abstraction for a step that always changes the text.
426
+ *
427
+ * > Not recommended to use if
428
+ * a step doesn't ALWAYS change the text.
429
+ */
430
+ declare const mutatingStep: <T extends object = {}>(callback: (...args: Parameters<TaraskStep<T>>) => string) => TaraskStep<T>;
431
+
410
432
  /**
411
433
  * Collection of functions that help to work with dictionaries.
412
434
  */
@@ -424,11 +446,12 @@ declare const index_ansiColorWrappers: typeof ansiColorWrappers;
424
446
  declare const index_dictFrom: typeof dictFrom;
425
447
  declare const index_highlightDiff: typeof highlightDiff;
426
448
  declare const index_htmlWrappers: typeof htmlWrappers;
449
+ declare const index_mutatingStep: typeof mutatingStep;
427
450
  declare const index_replaceG: typeof replaceG;
428
451
  declare const index_replaceWithDict: typeof replaceWithDict;
429
452
  declare const index_restoreCase: typeof restoreCase;
430
453
  declare namespace index {
431
- export { type index_ExtendedDict as ExtendedDict, index_afterTarask as afterTarask, index_ansiColorWrappers as ansiColorWrappers, index_dictFrom as dictFrom, index_highlightDiff as highlightDiff, index_htmlWrappers as htmlWrappers, index_replaceG as replaceG, index_replaceWithDict as replaceWithDict, index_restoreCase as restoreCase };
454
+ export { type index_ExtendedDict as ExtendedDict, index_afterTarask as afterTarask, index_ansiColorWrappers as ansiColorWrappers, index_dictFrom as dictFrom, index_highlightDiff as highlightDiff, index_htmlWrappers as htmlWrappers, index_mutatingStep as mutatingStep, index_replaceG as replaceG, index_replaceWithDict as replaceWithDict, index_restoreCase as restoreCase };
432
455
  }
433
456
 
434
457
  export { type HtmlOptions, type NonHtmlOptions, REPLACE_J, TaraskConfig, type TaraskOptions, VARIATION, index$3 as dicts, index as lib, pipelines, index$1 as steps, tarask };
package/dist/index.js CHANGED
@@ -2079,7 +2079,6 @@ var tarask = (text, pipeline, cfg = new TaraskConfig()) => {
2079
2079
  // src/steps/index.ts
2080
2080
  var steps_exports = {};
2081
2081
  __export(steps_exports, {
2082
- afterJoin: () => afterJoin,
2083
2082
  applyGHtml: () => applyGHtml,
2084
2083
  applyGNonHtml: () => applyGNonHtml,
2085
2084
  applyNoFix: () => applyNoFix,
@@ -2096,7 +2095,6 @@ __export(steps_exports, {
2096
2095
  replaceIbyJ: () => replaceIbyJ,
2097
2096
  resolveSpecialSyntax: () => resolveSpecialSyntax,
2098
2097
  restoreCaseStep: () => restoreCaseStep,
2099
- restoreParentheses: () => restoreParentheses,
2100
2098
  restoreWhitespaces: () => restoreWhitespaces,
2101
2099
  storeSplittedAbcConvertedOrig: () => storeSplittedAbcConvertedOrig,
2102
2100
  storeSplittedText: () => storeSplittedText,
@@ -2114,6 +2112,7 @@ __export(lib_exports, {
2114
2112
  dictFrom: () => dictFrom,
2115
2113
  highlightDiff: () => highlightDiff,
2116
2114
  htmlWrappers: () => htmlWrappers,
2115
+ mutatingStep: () => mutatingStep,
2117
2116
  replaceG: () => replaceG,
2118
2117
  replaceWithDict: () => replaceWithDict,
2119
2118
  restoreCase: () => restoreCase
@@ -2256,15 +2255,33 @@ var ansiColorWrappers = {
2256
2255
  variable: (content) => `\x1B[35m${content}\x1B[0m`
2257
2256
  };
2258
2257
 
2259
- // src/steps/convert-alphabet.ts
2260
- var convertAlphabet = (options) => {
2261
- const { lower, upper } = options.cfg.general.abc;
2262
- options.text = replaceWithDict(replaceWithDict(options.text, lower), upper);
2263
- };
2264
- var convertAlphabetLowerCase = (options) => {
2265
- options.text = replaceWithDict(options.text, options.cfg.general.abc.lower);
2258
+ // src/lib/mutating-step.ts
2259
+ var mutatingStep = (callback) => (options) => {
2260
+ options.text = callback(options);
2266
2261
  };
2267
2262
 
2263
+ // src/steps/convert-alphabet.ts
2264
+ var convertAlphabet = mutatingStep(
2265
+ ({
2266
+ text,
2267
+ cfg: {
2268
+ general: {
2269
+ abc: { upper, lower }
2270
+ }
2271
+ }
2272
+ }) => replaceWithDict(replaceWithDict(text, lower), upper)
2273
+ );
2274
+ var convertAlphabetLowerCase = mutatingStep(
2275
+ ({
2276
+ text,
2277
+ cfg: {
2278
+ general: {
2279
+ abc: { lower }
2280
+ }
2281
+ }
2282
+ }) => replaceWithDict(text, lower)
2283
+ );
2284
+
2268
2285
  // src/steps/highlight-diff.ts
2269
2286
  var highlightDiffStep = (highlight) => ({
2270
2287
  cfg: {
@@ -2302,9 +2319,9 @@ var replaceIbyJ = (options) => {
2302
2319
  };
2303
2320
 
2304
2321
  // src/steps/join-splitted.ts
2305
- var joinSplittedText = (options) => {
2306
- options.text = options.storage.textArr.join(" ");
2307
- };
2322
+ var joinSplittedText = mutatingStep(
2323
+ ({ storage: { textArr } }) => textArr.join(" ")
2324
+ );
2308
2325
 
2309
2326
  // src/steps/apply-g.ts
2310
2327
  var applyGHtml = (options) => {
@@ -2329,12 +2346,9 @@ var applyGNonHtml = (options) => {
2329
2346
  };
2330
2347
 
2331
2348
  // src/steps/apply-variations.ts
2332
- var applyVariableParts = (callback) => (options) => {
2333
- options.text = options.text.replace(
2334
- /\([^)]*?\)/g,
2335
- ($0) => callback($0.slice(1, -1).split("|"))
2336
- );
2337
- };
2349
+ var applyVariableParts = (callback) => mutatingStep(
2350
+ ({ text }) => text.replace(/\([^)]*?\)/g, ($0) => callback($0.slice(1, -1).split("|")))
2351
+ );
2338
2352
  var applyVariationsHtml = applyVariableParts((parts) => {
2339
2353
  const main = parts.shift();
2340
2354
  return `<tarL data-l='${parts}'>${main}</tarL>`;
@@ -2349,9 +2363,9 @@ var applyVariationsNonHtml = (options) => {
2349
2363
  };
2350
2364
 
2351
2365
  // src/steps/prepare.ts
2352
- var prepare = (options) => {
2353
- options.text = options.text.replace(/г'(?![еёіюя])/g, "ґ").replace(/ - /g, " — ").replace(new RegExp("(\\p{P}|\\p{S}|\\d+)", "gu"), " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40");
2354
- };
2366
+ var prepare = mutatingStep(
2367
+ ({ text }) => text.replace(/г'(?![еёіюя])/g, "ґ").replace(/ - /g, " — ").replace(new RegExp("(\\p{P}|\\p{S}|\\d+)", "gu"), " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40")
2368
+ );
2355
2369
 
2356
2370
  // src/steps/resolve-syntax.ts
2357
2371
  var NOFIX_CHAR = "  ";
@@ -2361,77 +2375,76 @@ var applyNoFix = (options) => {
2361
2375
  if (noFixArr.length)
2362
2376
  options.text = options.text.replace(NOFIX_REGEX, () => noFixArr.shift());
2363
2377
  };
2364
- var resolveSpecialSyntax = (leftAngleBracket) => (options) => {
2365
- const {
2378
+ var resolveSpecialSyntax = (leftAngleBracket) => mutatingStep(
2379
+ ({
2366
2380
  text,
2367
2381
  storage,
2368
2382
  cfg: {
2369
2383
  general: { doEscapeCapitalized, abc }
2370
2384
  }
2371
- } = options;
2372
- const noFixArr = storage.noFixArr = [];
2373
- const convertAlphavet = (abcOnlyText, abc2) => restoreCase(
2374
- replaceWithDict(abcOnlyText.toLowerCase(), abc2.lower).split(" "),
2375
- abcOnlyText.split(" ")
2376
- ).join(" ");
2377
- const escapeCapsIfNeeded = (text2) => doEscapeCapitalized ? text2.replace(
2378
- new RegExp("(?!<=\\p{Lu} )\\p{Lu}{2}[\\p{Lu} ]*(?!= \\p{Lu})", "gu"),
2379
- ($0) => {
2380
- noFixArr.push(convertAlphavet($0, abc));
2381
- return NOFIX_CHAR;
2382
- }
2383
- ) : text2;
2384
- const parts = text.split(/(?=[<>])/g);
2385
- if (parts.length === 1) {
2386
- options.text = escapeCapsIfNeeded(text);
2387
- return;
2388
- }
2389
- let result = text.startsWith("<") ? "" : escapeCapsIfNeeded(parts.shift());
2390
- let depth = 0;
2391
- let currentPart = "";
2392
- for (const part of parts) {
2393
- if (part.startsWith("<")) {
2394
- ++depth;
2395
- currentPart += part;
2396
- } else if (depth) {
2397
- --depth;
2398
- if (depth) {
2385
+ }) => {
2386
+ const noFixArr = storage.noFixArr = [];
2387
+ const convertAlphavet = (abcOnlyText, abc2) => restoreCase(
2388
+ replaceWithDict(abcOnlyText.toLowerCase(), abc2.lower).split(" "),
2389
+ abcOnlyText.split(" ")
2390
+ ).join(" ");
2391
+ const escapeCapsIfNeeded = (text2) => doEscapeCapitalized ? text2.replace(
2392
+ new RegExp("(?!<=\\p{Lu} )\\p{Lu}{2}[\\p{Lu} ]*(?!= \\p{Lu})", "gu"),
2393
+ ($0) => {
2394
+ noFixArr.push(convertAlphavet($0, abc));
2395
+ return NOFIX_CHAR;
2396
+ }
2397
+ ) : text2;
2398
+ const parts = text.split(/(?=[<>])/g);
2399
+ if (parts.length === 1)
2400
+ return escapeCapsIfNeeded(text);
2401
+ let result = text.startsWith("<") ? "" : escapeCapsIfNeeded(parts.shift());
2402
+ let depth = 0;
2403
+ let currentPart = "";
2404
+ for (const part of parts) {
2405
+ if (part.startsWith("<")) {
2406
+ ++depth;
2399
2407
  currentPart += part;
2400
- } else {
2401
- let char = "";
2402
- const isAbc = currentPart[1] === "*";
2403
- if (isAbc) {
2404
- char = currentPart[2];
2405
- currentPart = convertAlphavet(
2406
- currentPart.slice(char === "," || char === "." ? 3 : 2),
2407
- abc
2408
- );
2408
+ } else if (depth) {
2409
+ --depth;
2410
+ if (depth) {
2411
+ currentPart += part;
2409
2412
  } else {
2410
- char = currentPart[1];
2411
- currentPart = currentPart.slice(2);
2413
+ let char = "";
2414
+ const isAbc = currentPart[1] === "*";
2415
+ if (isAbc) {
2416
+ char = currentPart[2];
2417
+ currentPart = convertAlphavet(
2418
+ currentPart.slice(char === "," || char === "." ? 3 : 2),
2419
+ abc
2420
+ );
2421
+ } else {
2422
+ char = currentPart[1];
2423
+ currentPart = currentPart.slice(2);
2424
+ }
2425
+ let toAddToResult;
2426
+ switch (char) {
2427
+ case ".":
2428
+ toAddToResult = NOFIX_CHAR;
2429
+ noFixArr.push(currentPart);
2430
+ break;
2431
+ case ",":
2432
+ toAddToResult = leftAngleBracket + currentPart + ">";
2433
+ break;
2434
+ default:
2435
+ toAddToResult = leftAngleBracket + NOFIX_CHAR;
2436
+ noFixArr.push((isAbc ? "" : char) + currentPart + ">");
2437
+ }
2438
+ result += toAddToResult + escapeCapsIfNeeded(part.slice(1));
2439
+ currentPart = "";
2412
2440
  }
2413
- let toAddToResult;
2414
- switch (char) {
2415
- case ".":
2416
- toAddToResult = NOFIX_CHAR;
2417
- noFixArr.push(currentPart);
2418
- break;
2419
- case ",":
2420
- toAddToResult = leftAngleBracket + currentPart + ">";
2421
- break;
2422
- default:
2423
- toAddToResult = leftAngleBracket + NOFIX_CHAR;
2424
- noFixArr.push((isAbc ? "" : char) + currentPart + ">");
2425
- }
2426
- result += toAddToResult + escapeCapsIfNeeded(part.slice(1));
2427
- currentPart = "";
2441
+ } else {
2442
+ result += escapeCapsIfNeeded(part);
2428
2443
  }
2429
- } else {
2430
- result += escapeCapsIfNeeded(part);
2431
2444
  }
2445
+ return result + escapeCapsIfNeeded(currentPart);
2432
2446
  }
2433
- options.text = result + escapeCapsIfNeeded(currentPart);
2434
- };
2447
+ );
2435
2448
 
2436
2449
  // src/steps/restore-case.ts
2437
2450
  var restoreCaseStep = ({
@@ -2475,8 +2488,7 @@ var storeSplittedText = ({
2475
2488
 
2476
2489
  // src/steps/taraskevize.ts
2477
2490
  var wordlistPlusNoSoften = wordlist.concat(noSoften);
2478
- var taraskevize = (options) => {
2479
- let { text } = options;
2491
+ var taraskevize = mutatingStep(({ text }) => {
2480
2492
  text = replaceWithDict(text, wordlistPlusNoSoften);
2481
2493
  softening:
2482
2494
  do {
@@ -2486,42 +2498,39 @@ var taraskevize = (options) => {
2486
2498
  continue softening;
2487
2499
  break;
2488
2500
  } while (true);
2489
- options.text = replaceWithDict(text.replace(//g, ""), afterTarask);
2490
- };
2501
+ return replaceWithDict(
2502
+ text.replace(//g, "").replace(/не пра/g, "не&nbsp;пра"),
2503
+ afterTarask
2504
+ ).replace(/не&nbsp;пра/g, "не пра");
2505
+ });
2491
2506
 
2492
2507
  // src/steps/whitespaces.ts
2493
- var whitespacesToSpaces = (options) => {
2494
- const { storage } = options;
2495
- storage.spaces = [];
2496
- options.text = options.text.replace(/\s+/g, (match) => {
2497
- storage.spaces.push(match);
2498
- return " ";
2499
- });
2500
- };
2501
- var restoreWhitespaces = (options) => {
2502
- const { spaces } = options.storage;
2503
- spaces.reverse();
2504
- options.text = options.text.replace(/ /g, () => spaces.pop());
2505
- };
2508
+ var whitespacesToSpaces = mutatingStep(
2509
+ ({ text, storage }) => {
2510
+ storage.spaces = [];
2511
+ return text.replace(/\s+/g, (match) => {
2512
+ storage.spaces.push(match);
2513
+ return " ";
2514
+ });
2515
+ }
2516
+ );
2517
+ var restoreWhitespaces = mutatingStep(
2518
+ ({ text, storage: { spaces } }) => {
2519
+ spaces.reverse();
2520
+ return text.replace(/ /g, () => spaces.pop());
2521
+ }
2522
+ );
2506
2523
 
2507
2524
  // src/steps/trim.ts
2508
- var trim = (options) => {
2509
- options.text = ` ${options.text.trim()} `;
2510
- };
2525
+ var trim = mutatingStep(({ text }) => ` ${text.trim()} `);
2511
2526
 
2512
- // src/steps/other.ts
2513
- var restoreParentheses = (options) => {
2514
- options.text = options.text.replace(/&#40/g, "(");
2515
- };
2516
- var afterJoin = (options) => {
2517
- options.text = options.text.replace(/&nbsp;/g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d+|&#40) ", "gu"), "$1");
2518
- };
2519
- var finalize = (newLine) => (options) => {
2520
- options.text = options.text.replace(/\n/g, newLine).trim();
2521
- };
2522
- var toLowerCase = (options) => {
2523
- options.text = options.text.toLowerCase();
2524
- };
2527
+ // src/steps/finalize.ts
2528
+ var finalize = (newLine) => mutatingStep(
2529
+ ({ text }) => text.replace(/&#40/g, "(").replace(/&nbsp;/g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d+) ", "gu"), "$1").replace(/\n/g, newLine).trim()
2530
+ );
2531
+
2532
+ // src/steps/to-lower-case.ts
2533
+ var toLowerCase = mutatingStep(({ text }) => text.toLowerCase());
2525
2534
 
2526
2535
  // src/pipelines.ts
2527
2536
  var pipelines_exports = {};
@@ -2544,8 +2553,6 @@ var abcOnly = [
2544
2553
  convertAlphabet,
2545
2554
  restoreWhitespaces,
2546
2555
  applyNoFix,
2547
- restoreParentheses,
2548
- afterJoin,
2549
2556
  finalizeWithNewLine,
2550
2557
  ({ storage, cfg: { general } }) => {
2551
2558
  general.doEscapeCapitalized = storage.doEscapeCapitalized;
@@ -2566,8 +2573,6 @@ var createPipeline = (resolveSpecialSyntax2, applyG, applyVariations, finalize2,
2566
2573
  highlightDiffStep2,
2567
2574
  joinSplittedText,
2568
2575
  restoreWhitespaces,
2569
- restoreParentheses,
2570
- afterJoin,
2571
2576
  applyG,
2572
2577
  applyVariations,
2573
2578
  applyNoFix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taraskevizer",
3
- "version": "8.0.1",
3
+ "version": "8.0.3",
4
4
  "author": "GooseOb",
5
5
  "repository": {
6
6
  "type": "git",