taraskevizer 9.2.3 → 9.3.0

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.
Files changed (54) hide show
  1. package/dist/bin.js +3 -3
  2. package/dist/dict/alphabets/arabic.d.ts +1 -1
  3. package/dist/dict/alphabets/arabic.js +55 -52
  4. package/dist/dict/alphabets/cyrillic.d.ts +2 -2
  5. package/dist/dict/alphabets/cyrillic.js +3 -2
  6. package/dist/dict/alphabets/latin.d.ts +4 -4
  7. package/dist/dict/alphabets/latin.js +109 -112
  8. package/dist/dict/alphabets/types.d.ts +3 -3
  9. package/dist/dict/iawords.d.ts +1 -1
  10. package/dist/dict/iawords.js +3 -3
  11. package/dist/dict/lib.d.ts +5 -9
  12. package/dist/dict/lib.js +7 -15
  13. package/dist/dict/phonetic.d.ts +1 -1
  14. package/dist/dict/phonetic.js +5 -4
  15. package/dist/dict/softening.d.ts +2 -2
  16. package/dist/dict/softening.js +13 -13
  17. package/dist/dict/types.d.ts +6 -8
  18. package/dist/dict/wordlist.d.ts +1 -2
  19. package/dist/dict/wordlist.js +1414 -1413
  20. package/dist/lib/after-tarask.d.ts +1 -2
  21. package/dist/lib/after-tarask.js +3 -2
  22. package/dist/lib/debug.d.ts +3 -0
  23. package/dist/lib/debug.js +16 -0
  24. package/dist/lib/index.d.ts +1 -2
  25. package/dist/lib/index.js +1 -2
  26. package/dist/lib/mutating-step.d.ts +4 -4
  27. package/dist/lib/mutating-step.js +2 -2
  28. package/dist/lib/replace-g.js +1 -1
  29. package/dist/lib/soften.js +3 -4
  30. package/dist/lib/types.d.ts +5 -0
  31. package/dist/pipelines.d.ts +1 -1
  32. package/dist/steps/apply-g.js +5 -9
  33. package/dist/steps/apply-variations.d.ts +1 -1
  34. package/dist/steps/convert-alphabet.d.ts +2 -2
  35. package/dist/steps/convert-alphabet.js +7 -3
  36. package/dist/steps/finalize.d.ts +3 -3
  37. package/dist/steps/i-to-j.js +3 -3
  38. package/dist/steps/iotacize-ji.d.ts +1 -1
  39. package/dist/steps/iotacize-ji.js +8 -7
  40. package/dist/steps/phonetize.d.ts +1 -1
  41. package/dist/steps/phonetize.js +2 -3
  42. package/dist/steps/prepare.d.ts +1 -1
  43. package/dist/steps/resolve-syntax.js +5 -5
  44. package/dist/steps/store-splitted-abc-converted-orig.js +2 -2
  45. package/dist/steps/taraskevize.d.ts +1 -1
  46. package/dist/steps/taraskevize.js +2 -2
  47. package/dist/steps/to-lower-case.d.ts +1 -1
  48. package/dist/steps/types.d.ts +1 -1
  49. package/dist/tarask.js +3 -3
  50. package/package.json +10 -5
  51. package/dist/lib/replace-with-dict.d.ts +0 -2
  52. package/dist/lib/replace-with-dict.js +0 -7
  53. package/dist/lib/tools.debug.d.ts +0 -3
  54. package/dist/lib/tools.debug.js +0 -17
@@ -1,2 +1 @@
1
- import type { Dict } from '../dict/types';
2
- export declare const endZSoftenAndNiaBiaz: Dict;
1
+ export declare const endZSoftenAndNiaBiaz: import("../dict").CallableDict;
@@ -1,4 +1,5 @@
1
- export const endZSoftenAndNiaBiaz = [
1
+ import { callableDict } from '../dict/lib.js';
2
+ export const endZSoftenAndNiaBiaz = callableDict([
2
3
  // / не (?=
3
4
  // {зычны}*{сымбаль}{націск}
4
5
  // |{зычны}*{галосны}{зычны}*{канец слова}
@@ -19,4 +20,4 @@ export const endZSoftenAndNiaBiaz = [
19
20
 
20
21
  [/ б[ея]з(?= і\S*[ая]ў|ну )/g, ' бязь'],
21
22
  [/ (?:пра|цера)?з(?= і\S*[ая]ў|ну )/g, '$&ь'],
22
- ];
23
+ ]);
@@ -0,0 +1,3 @@
1
+ import type { CallableDict } from '../dict/types';
2
+ export declare const dict: (dict: CallableDict, regex: RegExp) => CallableDict;
3
+ export declare const log: (...msgs: unknown[]) => unknown;
@@ -0,0 +1,16 @@
1
+ const prefix = '[debug]';
2
+ export const dict = (dict, regex) => {
3
+ const fn = (text) => fn.value.reduce((acc, item) => {
4
+ if (regex.test(text)) {
5
+ console.log(prefix, 'replaceWithDict:', item);
6
+ process.exit(1);
7
+ }
8
+ return acc.replace(item[0], item[1]);
9
+ }, text);
10
+ fn.value = dict.value;
11
+ return fn;
12
+ };
13
+ export const log = (...msgs) => {
14
+ console.log(prefix, ...msgs);
15
+ return msgs[0];
16
+ };
@@ -1,9 +1,8 @@
1
1
  export * from './after-tarask';
2
2
  export * from './highlight-diff';
3
3
  export * from './replace-g';
4
- export * from './replace-with-dict';
5
4
  export * from './restore-case';
6
5
  export * from './mutating-step';
7
6
  export * from './soften';
8
- export { dictFrom, copyDict } from './../dict/lib';
7
+ export { callableDict as dict, copyDict } from './../dict/lib';
9
8
  export type * from './types';
package/dist/lib/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  export * from './after-tarask.js';
2
2
  export * from './highlight-diff.js';
3
3
  export * from './replace-g.js';
4
- export * from './replace-with-dict.js';
5
4
  export * from './restore-case.js';
6
5
  export * from './mutating-step.js';
7
6
  export * from './soften.js';
8
- export { dictFrom, copyDict } from './../dict/lib.js';
7
+ export { callableDict as dict, copyDict } from './../dict/lib.js';
@@ -12,10 +12,10 @@ import type { TaraskStep } from '../steps/types';
12
12
  * ({ text, storage: { wrapText } }) => wrapText(text.trim())
13
13
  * );
14
14
  * // is equivalent to
15
- * const trimStep: TaraskStep<TextWrapperStorage> = (options) => {
16
- * options.text = options.storage.wrapText(
17
- * options.text.trim()
15
+ * const trimStep: TaraskStep<TextWrapperStorage> = (ctx) => {
16
+ * ctx.text = options.storage.wrapText(
17
+ * ctx.text.trim()
18
18
  * );
19
19
  * };
20
20
  */
21
- export declare const mutatingStep: <T extends object = {}>(callback: (...args: Parameters<TaraskStep<T>>) => string) => TaraskStep<T>;
21
+ export declare const mutatingStep: <T extends object = object>(callback: (...args: Parameters<TaraskStep<T>>) => string) => TaraskStep<T>;
@@ -1,4 +1,4 @@
1
1
 
2
- export const mutatingStep = (callback) => (options) => {
3
- options.text = callback(options);
2
+ export const mutatingStep = (callback) => (ctx) => {
3
+ ctx.text = callback(ctx);
4
4
  };
@@ -1,3 +1,3 @@
1
1
  export const replaceG = (replacer) => (text) => text.replace(/[Ґґ]/g,
2
- // @ts-ignore
2
+ // @ts-expect-error TS can't infer the type of replacer
3
3
  replacer);
@@ -1,9 +1,8 @@
1
1
  import { noSoften, softeners } from '../dict/softening.js';
2
- import { replaceWithDict } from './replace-with-dict.js';
3
2
  export const soften = (text) => {
4
- text = replaceWithDict(text, noSoften);
3
+ text = noSoften(text);
5
4
  do {
6
- text = replaceWithDict(text, softeners);
7
- } while (softeners.some(([pattern]) => pattern.test(text)));
5
+ text = softeners(text);
6
+ } while (softeners.value.some(({ 0: pattern }) => pattern.test(text)));
8
7
  return text.replace(/\ue0ff/g, '');
9
8
  };
@@ -2,3 +2,8 @@ export type ExtendedDict = readonly (readonly [
2
2
  RegExp,
3
3
  string | ((...substrings: string[]) => string)
4
4
  ])[];
5
+ declare global {
6
+ interface String {
7
+ replace(...args: ExtendedDict[number]): string;
8
+ }
9
+ }
@@ -39,7 +39,7 @@ export declare const abc: (TaraskStep<import("./steps").SpecialSyntaxStorage> |
39
39
  *
40
40
  * Used by {@link tar} and {@link phonetic}.
41
41
  *
42
- * @param subPipeline - Steps used instead of [{@link subPipeline.taraskevize}].
42
+ * @param subPipeline - Steps used instead of [{@link steps.taraskevize}].
43
43
  */
44
44
  export declare const _createPipeline: (subPipeline: Pipeline) => (TaraskStep<import("./steps").SplittedTextStorage> | TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage> | TaraskStep<import("./steps").TrimStorage>)[];
45
45
  /**
@@ -1,12 +1,8 @@
1
1
  import { replaceG } from '../lib/index.js';
2
2
  import { alphabets, gobj } from '../dict/index.js';
3
- export const applyG = (options) => {
4
- const { abc, g, wrapperDict } = options.cfg;
5
- const colorize = wrapperDict?.letterH;
6
- if (abc === alphabets.cyrillic && (colorize || !g))
7
- options.text = replaceG(colorize
8
- ? g
9
- ? colorize('$&')
10
- : ($0) => colorize(gobj[$0])
11
- : ($0) => gobj[$0])(options.text);
3
+ export const applyG = (ctx) => {
4
+ const { abc, g, wrapperDict } = ctx.cfg;
5
+ const wrap = wrapperDict?.letterH;
6
+ if (abc === alphabets.cyrillic && (wrap || !g))
7
+ ctx.text = replaceG(wrap ? (g ? wrap('$&') : ($0) => wrap(gobj[$0])) : ($0) => gobj[$0])(ctx.text);
12
8
  };
@@ -1 +1 @@
1
- export declare const applyVariations: import("./types").TaraskStep<{}>;
1
+ export declare const applyVariations: import("./types").TaraskStep<object>;
@@ -1,2 +1,2 @@
1
- export declare const convertAlphabet: import("./types").TaraskStep<{}>;
2
- export declare const convertAlphabetLowerCase: import("./types").TaraskStep<{}>;
1
+ export declare const convertAlphabet: import("./types").TaraskStep<object>;
2
+ export declare const convertAlphabetLowerCase: import("./types").TaraskStep<object>;
@@ -1,3 +1,7 @@
1
- import { mutatingStep, replaceWithDict } from '../lib/index.js';
2
- export const convertAlphabet = mutatingStep(({ text, cfg: { abc: { upper, lower }, }, }) => replaceWithDict(replaceWithDict(text, lower), upper));
3
- export const convertAlphabetLowerCase = mutatingStep(({ text, cfg: { abc: { lower }, }, }) => replaceWithDict(text, lower));
1
+ import { mutatingStep } from '../lib/index.js';
2
+ import * as debug from '../lib/debug.js';
3
+ export const convertAlphabet = mutatingStep(({ text, cfg: { abc: { upper, lower }, }, }) => {
4
+ text = lower(text);
5
+ return upper ? debug.dict(upper, /K/)(text) : text;
6
+ });
7
+ export const convertAlphabetLowerCase = mutatingStep(({ text, cfg: { abc: { lower }, }, }) => lower(text));
@@ -1,6 +1,4 @@
1
1
  /**
2
- * @param newLine - The string to replace new lines with.
3
- *
4
2
  * Reverse the changes made in the {@link prepare} step
5
3
  * and replace new lines with the passed string.
6
4
  *
@@ -8,6 +6,8 @@
8
6
  * `(` from `&#40`,
9
7
  * ` ` from `&nbsp;`,
10
8
  *
9
+ * Replaces new lines with the `newLine` config value.
10
+ *
11
11
  * Removes spaces around punctuation marks and digits.
12
12
  */
13
- export declare const finalize: import("./types").TaraskStep<{}>;
13
+ export declare const finalize: import("./types").TaraskStep<object>;
@@ -1,9 +1,9 @@
1
1
  import { alphabets } from '../dict/index.js';
2
2
  const toJ = (shortU) => 'й ' + (shortU ? 'у' : '');
3
- export const replaceIbyJ = (options) => {
4
- const { abc, j } = options.cfg;
3
+ export const replaceIbyJ = (ctx) => {
4
+ const { abc, j } = ctx.cfg;
5
5
  if (j !== 'never' && abc !== alphabets.latinJi)
6
- options.text = options.text.replace(/(?<=[аеёіоуыэюя] )і (ў?)/g, j === 'always'
6
+ ctx.text = ctx.text.replace(/(?<=[аеёіоуыэюя] )і (ў?)/g, j === 'always'
7
7
  ? (_$0, $1) => toJ($1)
8
8
  : ($0, $1) => (Math.random() >= 0.5 ? toJ($1) : $0));
9
9
  };
@@ -1 +1 @@
1
- export declare const iotacizeJi: import("./types").TaraskStep<{}>;
1
+ export declare const iotacizeJi: import("./types").TaraskStep<object>;
@@ -1,9 +1,10 @@
1
1
  import { iwords } from '../dict/index.js';
2
- import { dictFrom, mutatingStep, replaceWithDict } from '../lib/index.js';
3
- const iDict = dictFrom.raw([
4
- [/([аеёіоуыэюя\u0301] ў/, '$1й у'],
5
- [/([аеёіоуыэюя\u0301] )і /, '$1й '],
6
- [/([аеёіоуыэюя\u0301] ?)і/, '$1йі'],
7
- [` і(?=${iwords})`, ' йі'],
2
+ import { regexG } from '../dict/lib.js';
3
+ import { dict, mutatingStep } from '../lib/index.js';
4
+ const iDict = dict([
5
+ [/([аеёіоуыэюя\u0301] )і ў/g, '$1й у'],
6
+ [/([аеёіоуыэюя\u0301] )і /g, '$1й '],
7
+ [/([аеёіоуыэюя\u0301] ?)і/g, '$1йі'],
8
+ [regexG(` і(?=${iwords})`), ' йі'],
8
9
  ]);
9
- export const iotacizeJi = mutatingStep(({ text }) => replaceWithDict(text, iDict));
10
+ export const iotacizeJi = mutatingStep(({ text }) => iDict(text));
@@ -1 +1 @@
1
- export declare const phonetize: import("./types").TaraskStep<{}>;
1
+ export declare const phonetize: import("./types").TaraskStep<object>;
@@ -1,4 +1,3 @@
1
1
  import { iaWords, phonetic } from '../dict/index.js';
2
- import { endZSoftenAndNiaBiaz, mutatingStep, replaceWithDict, soften, } from '../lib/index.js';
3
- const dict = iaWords.concat(phonetic);
4
- export const phonetize = mutatingStep(({ text }) => replaceWithDict(replaceWithDict(soften(text), dict), endZSoftenAndNiaBiaz));
2
+ import { endZSoftenAndNiaBiaz, mutatingStep, soften } from '../lib/index.js';
3
+ export const phonetize = mutatingStep(({ text }) => endZSoftenAndNiaBiaz(phonetic(iaWords(soften(text)))));
@@ -3,4 +3,4 @@
3
3
  *
4
4
  * Some changes should be reverted in the {@link finalize} step.
5
5
  */
6
- export declare const prepare: import("./types").TaraskStep<{}>;
6
+ export declare const prepare: import("./types").TaraskStep<object>;
@@ -1,18 +1,18 @@
1
- import { restoreCase, replaceWithDict, mutatingStep } from '../lib/index.js';
1
+ import { restoreCase, mutatingStep } from '../lib/index.js';
2
2
  const NOFIX_CHAR = ' \ue0fe ';
3
3
  const NOFIX_REGEX = new RegExp(NOFIX_CHAR, 'g');
4
4
 
5
- export const applyNoFix = (options) => {
6
- const { noFixArr } = options.storage;
5
+ export const applyNoFix = (ctx) => {
6
+ const { noFixArr } = ctx.storage;
7
7
  if (noFixArr.length) {
8
8
  noFixArr.reverse();
9
- options.text = options.text.replace(NOFIX_REGEX, () => noFixArr.pop());
9
+ ctx.text = ctx.text.replace(NOFIX_REGEX, () => noFixArr.pop());
10
10
  }
11
11
  };
12
12
 
13
13
  export const resolveSpecialSyntax = mutatingStep(({ text, storage, cfg: { doEscapeCapitalized, abc, leftAngleBracket } }) => {
14
14
  const noFixArr = (storage.noFixArr = []);
15
- const convertAlphavet = (abcOnlyText, abc) => restoreCase(replaceWithDict(abcOnlyText.toLowerCase(), abc.lower).split(' '), abcOnlyText.split(' ')).join(' ');
15
+ const convertAlphavet = (abcOnlyText, abc) => restoreCase(abc.lower(abcOnlyText.toLowerCase()).split(' '), abcOnlyText.split(' ')).join(' ');
16
16
  const escapeCapsIfNeeded = (text) => doEscapeCapitalized
17
17
  ? text.replace(/(?!<=\p{Lu} )\p{Lu}{2}[\p{Lu} ]*(?!= \p{Lu})/gu, ($0) => {
18
18
  noFixArr.push(convertAlphavet($0, abc));
@@ -1,4 +1,4 @@
1
- import { replaceWithDict } from '../lib/index.js';
2
1
  export const storeSplittedAbcConvertedOrig = ({ cfg: { abc: { lower, upper }, }, text, storage, }) => {
3
- storage.origArr = replaceWithDict(replaceWithDict(text, lower), upper).split(' ');
2
+ text = lower(text);
3
+ storage.origArr = (upper ? upper(text) : text).split(' ');
4
4
  };
@@ -1 +1 @@
1
- export declare const taraskevize: import("./types").TaraskStep<{}>;
1
+ export declare const taraskevize: import("./types").TaraskStep<object>;
@@ -1,3 +1,3 @@
1
1
  import { wordlist } from '../dict/index.js';
2
- import { endZSoftenAndNiaBiaz, mutatingStep, replaceWithDict, soften, } from '../lib/index.js';
3
- export const taraskevize = mutatingStep(({ text }) => replaceWithDict(soften(replaceWithDict(text, wordlist)), endZSoftenAndNiaBiaz));
2
+ import { endZSoftenAndNiaBiaz, mutatingStep, soften } from '../lib/index.js';
3
+ export const taraskevize = mutatingStep(({ text }) => endZSoftenAndNiaBiaz(soften(wordlist(text))));
@@ -1 +1 @@
1
- export declare const toLowerCase: import("./types").TaraskStep<{}>;
1
+ export declare const toLowerCase: import("./types").TaraskStep<object>;
@@ -1,5 +1,5 @@
1
1
  import type { TaraskConfig } from '../config';
2
- export type TaraskStep<Storage extends object = {}> = (args: {
2
+ export type TaraskStep<Storage extends object = object> = (context: {
3
3
  text: string;
4
4
  storage: Storage;
5
5
  cfg: TaraskConfig;
package/dist/tarask.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { TaraskConfig } from './config.js';
2
2
 
3
3
  export const tarask = (text, pipeline, cfg = new TaraskConfig()) => {
4
- const options = { text, cfg, storage: {} };
4
+ const ctx = { text, cfg, storage: {} };
5
5
  for (const step of pipeline)
6
- step(options);
7
- return options.text;
6
+ step(ctx);
7
+ return ctx.text;
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taraskevizer",
3
- "version": "9.2.3",
3
+ "version": "9.3.0",
4
4
  "author": "GooseOb",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,12 +10,16 @@
10
10
  "module": "dist/index.js",
11
11
  "devDependencies": {
12
12
  "@digitak/esrun": "^3.2.26",
13
- "@types/node": "^20.16.11",
14
- "bun-types": "^1.1.30",
13
+ "@eslint/js": "^9.13.0",
14
+ "@types/node": "^20.16.12",
15
+ "bun-types": "^1.1.31",
16
+ "eslint": "^9.13.0",
17
+ "globals": "^15.11.0",
15
18
  "husky": "^9.1.6",
16
19
  "prettier": "^3.3.3",
17
- "typedoc": "^0.26.9",
18
- "typescript": "^5.6.3"
20
+ "typedoc": "^0.26.10",
21
+ "typescript": "^5.6.3",
22
+ "typescript-eslint": "^8.11.0"
19
23
  },
20
24
  "bin": {
21
25
  "tarask": "dist/bin.js"
@@ -38,6 +42,7 @@
38
42
  "scripts": {
39
43
  "build": "bun ./build.ts",
40
44
  "prettier": "prettier --write .",
45
+ "lint": "eslint .",
41
46
  "dev": "esrun --watch=src/*,test/* --send-code-mode=temporaryFile test",
42
47
  "dev:bun": "bun test --watch",
43
48
  "test": "esrun --send-code-mode=temporaryFile test",
@@ -1,2 +0,0 @@
1
- import type { ExtendedDict } from './types';
2
- export declare const replaceWithDict: (text: string, dict?: ExtendedDict) => string;
@@ -1,7 +0,0 @@
1
- export const replaceWithDict = (text, dict = []) => {
2
- for (const [pattern, result] of dict)
3
- text = text.replace(pattern,
4
- //@ts-ignore
5
- result);
6
- return text;
7
- };
@@ -1,3 +0,0 @@
1
- import type { ExtendedDict } from './types';
2
- export declare const replaceWithDict: (text: string, dict: ExtendedDict, regex: RegExp) => string;
3
- export declare const log: (...msgs: any[]) => any;
@@ -1,17 +0,0 @@
1
- export const replaceWithDict = (text, dict, regex) => {
2
- for (const item of dict) {
3
- const [pattern, result] = item;
4
- text = text.replace(pattern,
5
- //@ts-ignore
6
- result);
7
- if (regex.test(text)) {
8
- log('replaceWithDict:', item);
9
- process.exit(1);
10
- }
11
- }
12
- return text;
13
- };
14
- export const log = (...msgs) => {
15
- console.log('[debug]', ...msgs);
16
- return msgs[0];
17
- };