taraskevizer 8.0.7 → 8.0.9
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/README.md +5 -4
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +126 -173
- package/dist/config.d.ts +14 -0
- package/dist/config.js +35 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.js +10 -0
- package/dist/dict/alphabets/arabic.d.ts +3 -0
- package/dist/dict/alphabets/arabic.js +62 -0
- package/dist/dict/alphabets/cyrillic.d.ts +4 -0
- package/dist/dict/alphabets/cyrillic.js +4 -0
- package/dist/dict/alphabets/index.d.ts +4 -0
- package/dist/dict/alphabets/index.js +3 -0
- package/dist/dict/alphabets/latin.d.ts +8 -0
- package/dist/dict/alphabets/latin.js +141 -0
- package/dist/dict/alphabets/types.d.ts +11 -0
- package/dist/dict/alphabets/types.js +1 -0
- package/dist/dict/gobj.d.ts +6 -0
- package/dist/dict/gobj.js +6 -0
- package/dist/dict/index.d.ts +5 -0
- package/dist/dict/index.js +4 -0
- package/dist/dict/iwords.d.ts +4 -0
- package/dist/dict/iwords.js +61 -0
- package/dist/dict/lib.d.ts +12 -0
- package/dist/dict/lib.js +17 -0
- package/dist/dict/softening.d.ts +2 -0
- package/dist/dict/softening.js +21 -0
- package/dist/dict/types.d.ts +15 -0
- package/dist/dict/types.js +1 -0
- package/dist/dict/wordlist.d.ts +2 -0
- package/dist/dict/wordlist.js +1657 -0
- package/dist/index.d.ts +8 -457
- package/dist/index.js +7 -2579
- package/dist/lib/after-tarask.d.ts +2 -0
- package/dist/lib/after-tarask.js +9 -0
- package/dist/lib/highlight-diff.d.ts +1 -0
- package/dist/lib/highlight-diff.js +62 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/index.js +8 -0
- package/dist/lib/mutating-step.d.ts +8 -0
- package/dist/lib/mutating-step.js +4 -0
- package/dist/lib/replace-g.d.ts +1 -0
- package/dist/lib/replace-g.js +3 -0
- package/dist/lib/replace-with-dict.d.ts +2 -0
- package/dist/lib/replace-with-dict.js +7 -0
- package/dist/lib/restore-case.d.ts +1 -0
- package/dist/lib/restore-case.js +33 -0
- package/dist/lib/types.d.ts +4 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/wrappers.d.ts +8 -0
- package/dist/lib/wrappers.js +8 -0
- package/dist/pipelines.d.ts +48 -0
- package/dist/pipelines.js +47 -0
- package/dist/steps/apply-g.d.ts +3 -0
- package/dist/steps/apply-g.js +18 -0
- package/dist/steps/apply-variations.d.ts +24 -0
- package/dist/steps/apply-variations.js +18 -0
- package/dist/steps/convert-alphabet.d.ts +2 -0
- package/dist/steps/convert-alphabet.js +3 -0
- package/dist/steps/finalize.d.ts +14 -0
- package/dist/steps/finalize.js +8 -0
- package/dist/steps/highlight-diff.d.ts +9 -0
- package/dist/steps/highlight-diff.js +11 -0
- package/dist/steps/i-to-j.d.ts +2 -0
- package/dist/steps/i-to-j.js +10 -0
- package/dist/steps/index.d.ts +29 -0
- package/dist/steps/index.js +17 -0
- package/dist/steps/join-splitted.d.ts +2 -0
- package/dist/steps/join-splitted.js +2 -0
- package/dist/steps/prepare.d.ts +6 -0
- package/dist/steps/prepare.js +8 -0
- package/dist/steps/resolve-syntax.d.ts +24 -0
- package/dist/steps/resolve-syntax.js +73 -0
- package/dist/steps/restore-case.d.ts +2 -0
- package/dist/steps/restore-case.js +12 -0
- package/dist/steps/store-splitted-abc-converted-orig.d.ts +2 -0
- package/dist/steps/store-splitted-abc-converted-orig.js +4 -0
- package/dist/steps/store-splitted-text.d.ts +2 -0
- package/dist/steps/store-splitted-text.js +3 -0
- package/dist/steps/taraskevize.d.ts +1 -0
- package/dist/steps/taraskevize.js +14 -0
- package/dist/steps/to-lower-case.d.ts +1 -0
- package/dist/steps/to-lower-case.js +2 -0
- package/dist/steps/trim.d.ts +1 -0
- package/dist/steps/trim.js +2 -0
- package/dist/steps/types.d.ts +10 -0
- package/dist/steps/types.js +1 -0
- package/dist/steps/whitespaces.d.ts +20 -0
- package/dist/steps/whitespaces.js +14 -0
- package/dist/tarask.d.ts +10 -0
- package/dist/tarask.js +8 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.js +1 -0
- package/package.json +50 -54
- package/dist/index.cjs +0 -2588
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const iaReplacer = ($0, $1, $2) => $2.match(/[аеёіоуыэюя]/g)?.length === 1 ? $1 + 'я' + $2 : $0;
|
|
2
|
+
export const afterTarask = [
|
|
3
|
+
[/( б)е(зь? \S+)/g, iaReplacer],
|
|
4
|
+
[/( н)е( \S+)/g, iaReplacer],
|
|
5
|
+
[
|
|
6
|
+
/( (?:б[ея]|пра|цера)?з) і(\S*)/g,
|
|
7
|
+
($0, $1, $2) => (/([ая]ў|ну)$/.test($2) ? $1 + 'ь і' + $2 : $0),
|
|
8
|
+
],
|
|
9
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const highlightDiff: (text: string[], orig: readonly string[], isCyrillic: boolean, highlight: (content: string) => string) => void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { replaceG } from './replace-g';
|
|
2
|
+
import { gobj } from '../dict';
|
|
3
|
+
export const highlightDiff = (text, orig, isCyrillic, highlight) => {
|
|
4
|
+
const replaceGByOpposite = replaceG(($0) => gobj[$0]);
|
|
5
|
+
for (let i = 0; i < text.length; i++) {
|
|
6
|
+
const word = text[i];
|
|
7
|
+
const oWord = orig[i];
|
|
8
|
+
if (oWord === word)
|
|
9
|
+
continue;
|
|
10
|
+
const wordH = isCyrillic ? replaceGByOpposite(word) : word;
|
|
11
|
+
if (oWord === wordH)
|
|
12
|
+
continue;
|
|
13
|
+
if (!/\(/.test(word)) {
|
|
14
|
+
if (word.length === oWord.length) {
|
|
15
|
+
const wordLetters = word.split('');
|
|
16
|
+
for (let j = 0; j < wordLetters.length; j++) {
|
|
17
|
+
if (wordH[j] !== oWord[j])
|
|
18
|
+
wordLetters[j] = highlight(wordLetters[j]);
|
|
19
|
+
}
|
|
20
|
+
text[i] = wordLetters.join('');
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (isCyrillic) {
|
|
24
|
+
const word1 = word.replace(/ь/g, '');
|
|
25
|
+
switch (oWord) {
|
|
26
|
+
case word1:
|
|
27
|
+
text[i] = word.replace(/ь/g, highlight('ь'));
|
|
28
|
+
continue;
|
|
29
|
+
case word1 + 'ь':
|
|
30
|
+
text[i] = word.slice(0, -1).replace(/ь/g, highlight('ь')) + 'ь';
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const oWordEnd = oWord.length - 1;
|
|
36
|
+
let fromStart = 0;
|
|
37
|
+
let fromWordEnd = word.length - 1;
|
|
38
|
+
let fromOWordEnd = oWordEnd;
|
|
39
|
+
while (wordH[fromStart] === oWord[fromStart])
|
|
40
|
+
++fromStart;
|
|
41
|
+
while (wordH[fromWordEnd] === oWord[fromOWordEnd]) {
|
|
42
|
+
--fromWordEnd;
|
|
43
|
+
--fromOWordEnd;
|
|
44
|
+
}
|
|
45
|
+
if (oWord.length < word.length) {
|
|
46
|
+
if (fromOWordEnd === oWordEnd) {
|
|
47
|
+
text[i] = highlight(word);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (fromWordEnd < 0)
|
|
51
|
+
fromWordEnd = 0;
|
|
52
|
+
}
|
|
53
|
+
if (fromStart === fromWordEnd + 1) {
|
|
54
|
+
--fromStart;
|
|
55
|
+
++fromWordEnd;
|
|
56
|
+
}
|
|
57
|
+
text[i] =
|
|
58
|
+
word.slice(0, fromStart) +
|
|
59
|
+
highlight(word.slice(fromStart, fromWordEnd + 1)) +
|
|
60
|
+
word.slice(fromWordEnd + 1);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './after-tarask';
|
|
2
|
+
export * from './highlight-diff';
|
|
3
|
+
export * from './replace-g';
|
|
4
|
+
export * from './replace-with-dict';
|
|
5
|
+
export * from './restore-case';
|
|
6
|
+
export * from './wrappers';
|
|
7
|
+
export * from './mutating-step';
|
|
8
|
+
export { dictFrom } from './../dict/lib';
|
|
9
|
+
export type * from './types';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './after-tarask';
|
|
2
|
+
export * from './highlight-diff';
|
|
3
|
+
export * from './replace-g';
|
|
4
|
+
export * from './replace-with-dict';
|
|
5
|
+
export * from './restore-case';
|
|
6
|
+
export * from './wrappers';
|
|
7
|
+
export * from './mutating-step';
|
|
8
|
+
export { dictFrom } from './../dict/lib';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TaraskStep } from '../steps/types';
|
|
2
|
+
/**
|
|
3
|
+
* An abstraction for a step that always changes the text.
|
|
4
|
+
*
|
|
5
|
+
* > Not recommended to use if
|
|
6
|
+
* a step doesn't ALWAYS change the text.
|
|
7
|
+
*/
|
|
8
|
+
export declare const mutatingStep: <T extends object = {}>(callback: (...args: Parameters<TaraskStep<T>>) => string) => TaraskStep<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const replaceG: (replacer: string | ((g: 'Ґ' | 'ґ') => string)) => (text: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const restoreCase: (text: string[], orig: readonly string[]) => string[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const isUpperCase = (str) => str === str.toUpperCase();
|
|
2
|
+
const getLastLetter = (word, i) => {
|
|
3
|
+
const result = /\p{L}(?=[^\p{L}]*$)/u.exec(word);
|
|
4
|
+
if (result)
|
|
5
|
+
return result[0];
|
|
6
|
+
throw new Error(`the last letter of the word "${word}" not found. index: ${i}`);
|
|
7
|
+
};
|
|
8
|
+
export const restoreCase = (text, orig) => {
|
|
9
|
+
for (let i = 0; i < text.length; i++) {
|
|
10
|
+
const word = text[i];
|
|
11
|
+
const oWord = orig[i];
|
|
12
|
+
if (word === oWord)
|
|
13
|
+
continue;
|
|
14
|
+
if (word === oWord.toLowerCase()) {
|
|
15
|
+
text[i] = oWord;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (!oWord[0] || !isUpperCase(oWord[0]))
|
|
19
|
+
continue;
|
|
20
|
+
if (word === 'зь') {
|
|
21
|
+
text[i] = isUpperCase(orig[i + 1]) ? 'ЗЬ' : 'Зь';
|
|
22
|
+
}
|
|
23
|
+
else if (isUpperCase(getLastLetter(oWord, i))) {
|
|
24
|
+
text[i] = word.toUpperCase();
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
text[i] = word.startsWith('(')
|
|
28
|
+
? word.replace(/[^)]*?(?=\))/, ($0) => $0.replace(/[(|]./g, ($0) => $0.toUpperCase()))
|
|
29
|
+
: word[0].toUpperCase() + word.slice(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return text;
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const htmlWrappers: {
|
|
2
|
+
fix: (content: string) => `<tarF>${string}</tarF>`;
|
|
3
|
+
letterH: (content: string) => `<tarH>${string}</tarH>`;
|
|
4
|
+
};
|
|
5
|
+
export declare const ansiColorWrappers: {
|
|
6
|
+
fix: (content: string) => string;
|
|
7
|
+
variable: (content: string) => string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const htmlWrappers = {
|
|
2
|
+
fix: (content) => `<tarF>${content}</tarF>`,
|
|
3
|
+
letterH: (content) => `<tarH>${content}</tarH>`,
|
|
4
|
+
};
|
|
5
|
+
export const ansiColorWrappers = {
|
|
6
|
+
fix: (content) => `\x1b[32m${content}\x1b[0m`,
|
|
7
|
+
variable: (content) => `\x1b[35m${content}\x1b[0m`,
|
|
8
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pipeline in Taraskevizer is basically
|
|
3
|
+
* an array of steps of type {@link steps.TaraskStep}.
|
|
4
|
+
*
|
|
5
|
+
* You can use pre-made pipelines from this module or create your own.
|
|
6
|
+
*
|
|
7
|
+
* If you want to create a pipeline based on a pre-made one
|
|
8
|
+
* and do it more safely, it's recommended to use
|
|
9
|
+
* `.map` if you need replacing only or
|
|
10
|
+
* `.flatMap` if you also need to add or remove steps.
|
|
11
|
+
*
|
|
12
|
+
* This way you will depend less on the
|
|
13
|
+
* internal structure of the pre-made pipeline.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import { type TaraskStep } from './steps';
|
|
18
|
+
/**
|
|
19
|
+
* Storage for the pipeline {@link abcOnly}.
|
|
20
|
+
*/
|
|
21
|
+
type AbcOnlyStorage = {
|
|
22
|
+
doEscapeCapitalized: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Pipeline for changing only the alphabet.
|
|
26
|
+
*
|
|
27
|
+
* The property `cfg.general.doEscapeCapitalized` is set to `false` during the pipeline execution.
|
|
28
|
+
*
|
|
29
|
+
* To see the full list of steps, check the source code.
|
|
30
|
+
*/
|
|
31
|
+
export declare const abcOnly: (TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage> | (({ storage, cfg: { general } }: {
|
|
32
|
+
text: string;
|
|
33
|
+
storage: AbcOnlyStorage;
|
|
34
|
+
cfg: import("./config").TaraskConfig;
|
|
35
|
+
}) => void))[];
|
|
36
|
+
/**
|
|
37
|
+
* Pipeline for taraskevizing into plain text.
|
|
38
|
+
*
|
|
39
|
+
* To see the full list of steps, check the source code.
|
|
40
|
+
*/
|
|
41
|
+
export declare const plainText: (TaraskStep<import("./steps").SplittedTextStorage> | TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage>)[];
|
|
42
|
+
/**
|
|
43
|
+
* Pipeline for taraskevizing into HTML.
|
|
44
|
+
*
|
|
45
|
+
* To see the full list of steps, check the source code.
|
|
46
|
+
*/
|
|
47
|
+
export declare const html: (TaraskStep<import("./steps").SplittedTextStorage> | TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage>)[];
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
import { applyVariationsHtml, applyVariationsNonHtml, applyGHtml, applyGNonHtml, highlightDiffStep, highlightDiffStepNonHtml, applyNoFix, convertAlphabet, convertAlphabetLowerCase, joinSplittedText, prepare, replaceIbyJ, resolveSpecialSyntax, restoreCaseStep, restoreWhitespaces, storeSplittedAbcConvertedOrig, storeSplittedText, taraskevize, whitespacesToSpaces, trim, finalize, toLowerCase, } from './steps';
|
|
3
|
+
import { htmlWrappers } from './lib/wrappers';
|
|
4
|
+
const resolveSpecialSyntaxWithLAB = resolveSpecialSyntax('<');
|
|
5
|
+
const finalizeWithNewLine = finalize('\n');
|
|
6
|
+
|
|
7
|
+
export const abcOnly = [
|
|
8
|
+
(({ storage, cfg: { general } }) => {
|
|
9
|
+
storage.doEscapeCapitalized = general.doEscapeCapitalized;
|
|
10
|
+
general.doEscapeCapitalized = false;
|
|
11
|
+
}),
|
|
12
|
+
trim,
|
|
13
|
+
resolveSpecialSyntaxWithLAB,
|
|
14
|
+
prepare,
|
|
15
|
+
whitespacesToSpaces,
|
|
16
|
+
convertAlphabet,
|
|
17
|
+
restoreWhitespaces,
|
|
18
|
+
applyNoFix,
|
|
19
|
+
finalizeWithNewLine,
|
|
20
|
+
(({ storage, cfg: { general } }) => {
|
|
21
|
+
general.doEscapeCapitalized = storage.doEscapeCapitalized;
|
|
22
|
+
}),
|
|
23
|
+
];
|
|
24
|
+
const createPipeline = (resolveSpecialSyntax, applyG, applyVariations, finalize, highlightDiffStep) => [
|
|
25
|
+
trim,
|
|
26
|
+
resolveSpecialSyntax,
|
|
27
|
+
prepare,
|
|
28
|
+
whitespacesToSpaces,
|
|
29
|
+
storeSplittedAbcConvertedOrig,
|
|
30
|
+
toLowerCase,
|
|
31
|
+
taraskevize,
|
|
32
|
+
replaceIbyJ,
|
|
33
|
+
convertAlphabetLowerCase,
|
|
34
|
+
storeSplittedText,
|
|
35
|
+
restoreCaseStep,
|
|
36
|
+
highlightDiffStep,
|
|
37
|
+
joinSplittedText,
|
|
38
|
+
restoreWhitespaces,
|
|
39
|
+
applyG,
|
|
40
|
+
applyVariations,
|
|
41
|
+
applyNoFix,
|
|
42
|
+
finalize,
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
export const plainText = createPipeline(resolveSpecialSyntaxWithLAB, applyGNonHtml, applyVariationsNonHtml, finalizeWithNewLine, highlightDiffStepNonHtml);
|
|
46
|
+
|
|
47
|
+
export const html = createPipeline(resolveSpecialSyntax('<'), applyGHtml, applyVariationsHtml, finalize('<br>'), highlightDiffStep(htmlWrappers.fix));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { replaceG, ansiColorWrappers, htmlWrappers } from '../lib';
|
|
2
|
+
import { alphabets } from '../dict';
|
|
3
|
+
import { gobj } from '../dict';
|
|
4
|
+
export const applyGHtml = (options) => {
|
|
5
|
+
const colorize = htmlWrappers.letterH;
|
|
6
|
+
if (options.cfg.general.abc === alphabets.cyrillic)
|
|
7
|
+
options.text = replaceG(options.cfg.html.g ? colorize('$&') : ($0) => colorize(gobj[$0]))(options.text);
|
|
8
|
+
};
|
|
9
|
+
export const applyGNonHtml = (options) => {
|
|
10
|
+
const colorize = ansiColorWrappers.variable;
|
|
11
|
+
const { cfg: { general: { abc }, nonHtml: { h, ansiColors }, }, } = options;
|
|
12
|
+
if (abc === alphabets.cyrillic && (h || ansiColors))
|
|
13
|
+
options.text = replaceG(ansiColors
|
|
14
|
+
? h
|
|
15
|
+
? ($0) => colorize(gobj[$0])
|
|
16
|
+
: colorize('$&')
|
|
17
|
+
: ($0) => gobj[$0])(options.text);
|
|
18
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TaraskStep } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @param callback - A function that takes an
|
|
4
|
+
* array of variable parts and returns a string.
|
|
5
|
+
*
|
|
6
|
+
* The step replaces strings like `"(a|b|c)"`
|
|
7
|
+
* with the result of the callback.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link applyVariationsHtml}
|
|
10
|
+
* @see {@link applyVariationsNonHtml}
|
|
11
|
+
*/
|
|
12
|
+
export declare const applyVariableParts: (callback: (arr: string[]) => string) => TaraskStep;
|
|
13
|
+
/**
|
|
14
|
+
* Uses {@link applyVariableParts}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* applyVariationsHtml({text: "a(b|c)d"});
|
|
18
|
+
* // {text: "a<tarL data-l='c'>b</tarL>d"}
|
|
19
|
+
*/
|
|
20
|
+
export declare const applyVariationsHtml: TaraskStep;
|
|
21
|
+
/**
|
|
22
|
+
* Uses {@link applyVariableParts}
|
|
23
|
+
*/
|
|
24
|
+
export declare const applyVariationsNonHtml: TaraskStep;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ansiColorWrappers, mutatingStep } from '../lib';
|
|
2
|
+
import { VARIATION } from '../constants';
|
|
3
|
+
|
|
4
|
+
export const applyVariableParts = (callback) => mutatingStep(({ text }) => text.replace(/\([^)]*?\)/g, ($0) => callback($0.slice(1, -1).split('|'))));
|
|
5
|
+
|
|
6
|
+
export const applyVariationsHtml = applyVariableParts((parts) => {
|
|
7
|
+
const main = parts.shift();
|
|
8
|
+
return `<tarL data-l='${parts}'>${main}</tarL>`;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const applyVariationsNonHtml = (options) => {
|
|
12
|
+
const partIndex = options.cfg.nonHtml.variations;
|
|
13
|
+
const colorize = ansiColorWrappers.variable;
|
|
14
|
+
if (partIndex !== VARIATION.ALL)
|
|
15
|
+
applyVariableParts(options.cfg.nonHtml.ansiColors
|
|
16
|
+
? (parts) => colorize(parts[partIndex])
|
|
17
|
+
: (parts) => parts[partIndex])(options);
|
|
18
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { mutatingStep, replaceWithDict } from '../lib';
|
|
2
|
+
export const convertAlphabet = mutatingStep(({ text, cfg: { general: { abc: { upper, lower }, }, }, }) => replaceWithDict(replaceWithDict(text, lower), upper));
|
|
3
|
+
export const convertAlphabetLowerCase = mutatingStep(({ text, cfg: { general: { abc: { lower }, }, }, }) => replaceWithDict(text, lower));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TaraskStep } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @param newLine - The string to replace new lines with.
|
|
4
|
+
*
|
|
5
|
+
* Reverse the changes made in the {@link prepare} step
|
|
6
|
+
* and replace new lines with the passed string.
|
|
7
|
+
*
|
|
8
|
+
* Restores:
|
|
9
|
+
* `(` from `(`,
|
|
10
|
+
* ` ` from ` `,
|
|
11
|
+
*
|
|
12
|
+
* Removes spaces around punctuation marks and digits.
|
|
13
|
+
*/
|
|
14
|
+
export declare const finalize: (newLine: string) => TaraskStep;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TaraskStep, SplittedTextStorage } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Uses {@link highlightDiff}
|
|
4
|
+
*/
|
|
5
|
+
export declare const highlightDiffStep: (highlight: (content: string) => string) => TaraskStep<SplittedTextStorage>;
|
|
6
|
+
/**
|
|
7
|
+
* Uses {@link highlightDiff}
|
|
8
|
+
*/
|
|
9
|
+
export declare const highlightDiffStepNonHtml: TaraskStep<SplittedTextStorage>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { highlightDiff, ansiColorWrappers } from '../lib';
|
|
2
|
+
import { alphabets } from '../dict';
|
|
3
|
+
|
|
4
|
+
export const highlightDiffStep = (highlight) => ({ cfg: { general: { abc }, }, storage: { textArr, origArr }, }) => {
|
|
5
|
+
highlightDiff(textArr, origArr, abc === alphabets.cyrillic, highlight);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const highlightDiffStepNonHtml = ({ cfg: { general: { abc }, nonHtml: { ansiColors }, }, storage: { textArr, origArr }, }) => {
|
|
9
|
+
if (ansiColors)
|
|
10
|
+
highlightDiff(textArr, origArr, abc === alphabets.cyrillic, ansiColorWrappers.fix);
|
|
11
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { alphabets } from '../dict';
|
|
2
|
+
import { REPLACE_J } from '../constants';
|
|
3
|
+
const toJ = (shortU) => 'й ' + (shortU ? 'у' : '');
|
|
4
|
+
export const replaceIbyJ = (options) => {
|
|
5
|
+
const { abc, j } = options.cfg.general;
|
|
6
|
+
if (j && abc !== alphabets.latinJi)
|
|
7
|
+
options.text = options.text.replace(/(?<=[аеёіоуыэюя] )і (ў?)/g, j === REPLACE_J.ALWAYS
|
|
8
|
+
? ($0, $1) => toJ($1)
|
|
9
|
+
: ($0, $1) => (Math.random() >= 0.5 ? toJ($1) : $0));
|
|
10
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module exports all the steps
|
|
3
|
+
* that are used in builtin pipelines.
|
|
4
|
+
*
|
|
5
|
+
* A step implements the {@link TaraskStep} type.
|
|
6
|
+
*
|
|
7
|
+
* Some steps are configurable, they take
|
|
8
|
+
* additional arguments and return a {@link TaraskStep},
|
|
9
|
+
* for example {@link resolveSpecialSyntax}.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
export * from './convert-alphabet';
|
|
14
|
+
export * from './highlight-diff';
|
|
15
|
+
export * from './i-to-j';
|
|
16
|
+
export * from './join-splitted';
|
|
17
|
+
export * from './apply-g';
|
|
18
|
+
export * from './apply-variations';
|
|
19
|
+
export * from './prepare';
|
|
20
|
+
export * from './resolve-syntax';
|
|
21
|
+
export * from './restore-case';
|
|
22
|
+
export * from './store-splitted-abc-converted-orig';
|
|
23
|
+
export * from './store-splitted-text';
|
|
24
|
+
export * from './taraskevize';
|
|
25
|
+
export * from './whitespaces';
|
|
26
|
+
export * from './trim';
|
|
27
|
+
export * from './finalize';
|
|
28
|
+
export * from './to-lower-case';
|
|
29
|
+
export type * from './types';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
export * from './convert-alphabet';
|
|
3
|
+
export * from './highlight-diff';
|
|
4
|
+
export * from './i-to-j';
|
|
5
|
+
export * from './join-splitted';
|
|
6
|
+
export * from './apply-g';
|
|
7
|
+
export * from './apply-variations';
|
|
8
|
+
export * from './prepare';
|
|
9
|
+
export * from './resolve-syntax';
|
|
10
|
+
export * from './restore-case';
|
|
11
|
+
export * from './store-splitted-abc-converted-orig';
|
|
12
|
+
export * from './store-splitted-text';
|
|
13
|
+
export * from './taraskevize';
|
|
14
|
+
export * from './whitespaces';
|
|
15
|
+
export * from './trim';
|
|
16
|
+
export * from './finalize';
|
|
17
|
+
export * from './to-lower-case';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TaraskStep } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Created in {@link resolveSpecialSyntax}.
|
|
4
|
+
*
|
|
5
|
+
* Emptied in {@link applyNoFix}.
|
|
6
|
+
*/
|
|
7
|
+
export type SpecialSyntaxStorage = {
|
|
8
|
+
noFixArr: string[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Brings parts from {@link SpecialSyntaxStorage} back to the text.
|
|
12
|
+
*
|
|
13
|
+
* Empties {@link SpecialSyntaxStorage.noFixArr}.
|
|
14
|
+
*/
|
|
15
|
+
export declare const applyNoFix: TaraskStep<SpecialSyntaxStorage>;
|
|
16
|
+
/**
|
|
17
|
+
* Captures noFix parts and stores them in {@link SpecialSyntaxStorage.noFixArr}.
|
|
18
|
+
* Places a special character `" \ue0fe "` in their place.
|
|
19
|
+
*
|
|
20
|
+
* Use {@link applyNoFix} to bring the parts back to the text.
|
|
21
|
+
*
|
|
22
|
+
* Creates storage: {@link SpecialSyntaxStorage}.
|
|
23
|
+
*/
|
|
24
|
+
export declare const resolveSpecialSyntax: (leftAngleBracket: string) => TaraskStep<SpecialSyntaxStorage>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { restoreCase, replaceWithDict, mutatingStep } from '../lib';
|
|
2
|
+
const NOFIX_CHAR = ' \ue0fe ';
|
|
3
|
+
const NOFIX_REGEX = new RegExp(NOFIX_CHAR, 'g');
|
|
4
|
+
|
|
5
|
+
export const applyNoFix = (options) => {
|
|
6
|
+
const { noFixArr } = options.storage;
|
|
7
|
+
if (noFixArr.length) {
|
|
8
|
+
noFixArr.reverse();
|
|
9
|
+
options.text = options.text.replace(NOFIX_REGEX, () => noFixArr.pop());
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const resolveSpecialSyntax = (leftAngleBracket) => mutatingStep(({ text, storage, cfg: { general: { doEscapeCapitalized, abc }, }, }) => {
|
|
14
|
+
const noFixArr = (storage.noFixArr = []);
|
|
15
|
+
const convertAlphavet = (abcOnlyText, abc) => restoreCase(replaceWithDict(abcOnlyText.toLowerCase(), abc.lower).split(' '), abcOnlyText.split(' ')).join(' ');
|
|
16
|
+
const escapeCapsIfNeeded = (text) => doEscapeCapitalized
|
|
17
|
+
? text.replace(/(?!<=\p{Lu} )\p{Lu}{2}[\p{Lu} ]*(?!= \p{Lu})/gu, ($0) => {
|
|
18
|
+
noFixArr.push(convertAlphavet($0, abc));
|
|
19
|
+
return NOFIX_CHAR;
|
|
20
|
+
})
|
|
21
|
+
: text;
|
|
22
|
+
const parts = text.split(/(?=[<>])/g);
|
|
23
|
+
if (parts.length === 1)
|
|
24
|
+
return escapeCapsIfNeeded(text);
|
|
25
|
+
let result = text.startsWith('<')
|
|
26
|
+
? ''
|
|
27
|
+
: escapeCapsIfNeeded(parts.shift());
|
|
28
|
+
let depth = 0;
|
|
29
|
+
let currentPart = '';
|
|
30
|
+
for (const part of parts) {
|
|
31
|
+
if (part.startsWith('<')) {
|
|
32
|
+
++depth;
|
|
33
|
+
currentPart += part;
|
|
34
|
+
}
|
|
35
|
+
else if (depth) {
|
|
36
|
+
--depth;
|
|
37
|
+
if (depth) {
|
|
38
|
+
currentPart += part;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
let char = '';
|
|
42
|
+
const isAbc = currentPart[1] === '*';
|
|
43
|
+
if (isAbc) {
|
|
44
|
+
char = currentPart[2];
|
|
45
|
+
currentPart = convertAlphavet(currentPart.slice(char === ',' || char === '.' ? 3 : 2), abc);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
char = currentPart[1];
|
|
49
|
+
currentPart = currentPart.slice(2);
|
|
50
|
+
}
|
|
51
|
+
let toAddToResult;
|
|
52
|
+
switch (char) {
|
|
53
|
+
case '.':
|
|
54
|
+
toAddToResult = NOFIX_CHAR;
|
|
55
|
+
noFixArr.push(currentPart);
|
|
56
|
+
break;
|
|
57
|
+
case ',':
|
|
58
|
+
toAddToResult = leftAngleBracket + currentPart + '>';
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
toAddToResult = leftAngleBracket + NOFIX_CHAR;
|
|
62
|
+
noFixArr.push((isAbc ? '' : char) + currentPart + '>');
|
|
63
|
+
}
|
|
64
|
+
result += toAddToResult + escapeCapsIfNeeded(part.slice(1));
|
|
65
|
+
currentPart = '';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
result += escapeCapsIfNeeded(part);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result + escapeCapsIfNeeded(currentPart);
|
|
73
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { restoreCase } from '../lib';
|
|
2
|
+
export const restoreCaseStep = ({ cfg: { general: { abc }, }, storage: { textArr, origArr }, }) => {
|
|
3
|
+
if (abc.upper) {
|
|
4
|
+
restoreCase(textArr, origArr);
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
for (let i = 0; i < textArr.length; i++) {
|
|
8
|
+
if (origArr[i] !== origArr[i].toLowerCase())
|
|
9
|
+
textArr[i] = origArr[i];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|