taraskevizer 9.2.4 → 9.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.
Files changed (47) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/dict/alphabets/arabic.d.ts +1 -1
  3. package/dist/dict/alphabets/arabic.js +56 -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 +110 -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 +4 -3
  11. package/dist/dict/lib.d.ts +7 -19
  12. package/dist/dict/lib.js +5 -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 +14 -13
  17. package/dist/dict/types.d.ts +5 -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 +2 -2
  25. package/dist/lib/index.js +2 -2
  26. package/dist/lib/mutating-step.d.ts +4 -4
  27. package/dist/lib/mutating-step.js +2 -2
  28. package/dist/lib/re.d.ts +2 -0
  29. package/dist/lib/re.js +2 -0
  30. package/dist/lib/soften.js +3 -4
  31. package/dist/pipelines.d.ts +1 -1
  32. package/dist/steps/apply-g.js +5 -9
  33. package/dist/steps/convert-alphabet.js +6 -3
  34. package/dist/steps/finalize.d.ts +2 -2
  35. package/dist/steps/i-to-j.js +3 -3
  36. package/dist/steps/iotacize-ji.js +7 -7
  37. package/dist/steps/phonetize.js +2 -3
  38. package/dist/steps/resolve-syntax.js +5 -5
  39. package/dist/steps/store-splitted-abc-converted-orig.js +2 -2
  40. package/dist/steps/taraskevize.js +2 -2
  41. package/dist/steps/types.d.ts +2 -2
  42. package/dist/tarask.js +3 -3
  43. package/package.json +1 -1
  44. package/dist/lib/replace-with-dict.d.ts +0 -2
  45. package/dist/lib/replace-with-dict.js +0 -5
  46. package/dist/lib/tools.debug.d.ts +0 -3
  47. package/dist/lib/tools.debug.js +0 -15
package/dist/bin.js CHANGED
@@ -6,7 +6,7 @@ const printWithPrefix = (msg) => {
6
6
  process.argv.splice(0, 2);
7
7
  const checkForOptions = (options) => process.argv[0] && options.includes(process.argv[0].toLowerCase());
8
8
  if (checkForOptions(['-v', '--version'])) {
9
- printWithPrefix("9.2.4");
9
+ printWithPrefix("9.3.1");
10
10
  process.exit(0);
11
11
  }
12
12
  if (checkForOptions(['-h', '--help'])) {
@@ -66,7 +66,7 @@ let cfg = {
66
66
  let mode = 'tar';
67
67
  const toHashTable = (dict) => {
68
68
  const result = {};
69
- for (const [options, callback] of dict)
69
+ for (const { 0: options, 1: callback } of dict)
70
70
  for (const option of options)
71
71
  result[option] = callback;
72
72
  return result;
@@ -1,3 +1,3 @@
1
1
  export declare const arabic: {
2
- lower: import("..").Dict;
2
+ lower: import("..").CallableDict;
3
3
  };
@@ -1,62 +1,66 @@
1
- import { dictFrom } from '../lib.js';
1
+ import { re } from '../../lib/index.js';
2
+ import { callableDict } from '../lib.js';
2
3
  const soft = '\u0652(?=[еёіюяь])';
3
4
  const presoft = '([تزكثࢮбвгджзйклмнпрстфхцчшў])\u0652?(\u0651?)';
4
5
 
5
6
  export const arabic = {
6
- lower: dictFrom.raw([
7
- [/ л[ая]/, ' لا'],
8
- [[ая]/, 'ـلا'],
7
+ lower: callableDict([
8
+ [/ [Лл][АаЯя]/g, ' لا'],
9
+ [/[Лл][АаЯя]/g, 'ـلا'],
9
10
  // падваеньне зычнага, шадда
10
- [/([бвгджзйклмнпрстфхцчшў]|д[зж])\1/, '$1\u0651'],
11
+ [
12
+ /([БбВвГгДдЖжЗзЙйКкЛлМмНнПпРрСсТтФфХхЦцЧчШшЎў]|[Дд][ЗзЖж])\1/g,
13
+ '$1\u0651',
14
+ ],
11
15
  // няма галоснага, сукун
12
- [/([бвгджзйклмнпрстфхцчшў])/, '$1\u0652'],
16
+ [/([БбВвГгДдЖжЗзЙйКкЛлМмНнПпРрСсТтФфХхЦцЧчШшЎў])/g, '$1\u0652'],
13
17
  // а, аліф
14
- [/а/, '\u0627а'],
18
+ [/[Аа]/g, '\u0627а'],
15
19
  // першая галосная, аліф
16
- [/ (?=[еэыуо])/, ' \u0627'],
17
- ['д\u0652з' + soft, 'ࢮ'],
18
- ['з' + soft, 'ز'],
19
- ['к' + soft, 'ك'],
20
- ['с' + soft, 'ث'],
21
- ['т' + soft, 'ت'],
22
- [/([تزكث])і/, 'ы'],
20
+ [/ (?=[ЕеЭэЫыУуОо])/g, ' \u0627'],
21
+ [re.gi('д\u0652з' + soft), 'ࢮ'],
22
+ [re.gi('з' + soft), 'ز'],
23
+ [re.gi('к' + soft), 'ك'],
24
+ [re.gi('с' + soft), 'ث'],
25
+ [re.gi('т' + soft), 'ت'],
26
+ [/([تزكث])[Іі]/g, 'ы'],
23
27
  // $2 - шадда
24
- [presoft + '[аяэе]', '$1$2\u064E'],
25
- [presoft + '[іы]', '$1$2\u0650'],
26
- [/ і /, ' \u0627\u0650 '],
27
- [presoft + '[оёую]', '$1$2\u064F'],
28
- [/ʼ/, 'ع'],
29
- [/ь/, ''],
30
- // [/[ьʼ]/, ''],
31
- [/[яе]/, 'ي\u064E'],
32
- [/і/, 'ي\u0650'],
33
- [/[ёю]/, 'ي\u064F'],
34
- [/[аэ]/, '\u064E'],
35
- [/[ыі]/, '\u0650'],
36
- [/[оу]/, '\u064F'],
37
- [/б/, 'ب'],
38
- [/[вў]/, 'و'],
39
- [/г/, 'ه'],
40
- [/ґ/, 'غ'],
41
- [/д\u0652ж/, 'ج'],
42
- [/д/, 'د'],
43
- [/ж/, 'ژ'],
44
- [/з/, 'ض'],
45
- [/й/, 'ي'],
46
- [/к/, 'ق'],
47
- [/л/, 'ل'],
48
- [/м/, 'م'],
49
- [/н/, 'ن'],
50
- [/п/, 'پ'],
51
- [/р/, 'ر'],
52
- [/с/, 'ص'],
53
- [/т/, 'ط'],
54
- [/ф/, 'ف'],
55
- [/х/, 'ح'],
56
- [/ц/, 'ࢯ'],
57
- [/ч/, 'چ'],
58
- [/ш/, 'ش'],
59
- [/,/, '،'],
60
- [/\?/, '؟'],
61
- ], 'gi'),
28
+ [re.gi(presoft + '[аяэе]'), '$1$2\u064E'],
29
+ [re.gi(presoft + '[іы]'), '$1$2\u0650'],
30
+ [/ [Iі] /g, ' \u0627\u0650 '],
31
+ [re.gi(presoft + '[оёую]'), '$1$2\u064F'],
32
+ [/[ʼ]/g, 'ع'],
33
+ [/[Ьь]/g, ''],
34
+ // [/[ьʼ]/g, ''],
35
+ [/[ЯяЕе]/g, 'ي\u064E'],
36
+ [/[Іі]/g, 'ي\u0650'],
37
+ [/[ЁёЮю]/g, 'ي\u064F'],
38
+ [/[АаЭэ]/g, '\u064E'],
39
+ [/[ЫыІі]/g, '\u0650'],
40
+ [/[ОоУу]/g, '\u064F'],
41
+ [/[Бб]/g, 'ب'],
42
+ [/[ВвЎў]/g, 'و'],
43
+ [/[Гг]/g, 'ه'],
44
+ [/[Ґґ]/g, 'غ'],
45
+ [/д\u0652ж/gi, 'ج'],
46
+ [/[Дд]/g, 'د'],
47
+ [/[Жж]/g, 'ژ'],
48
+ [/[Зз]/g, 'ض'],
49
+ [/[Йй]/g, 'ي'],
50
+ [/[Кк]/g, 'ق'],
51
+ [/[Лл]/g, 'ل'],
52
+ [/[Мм]/g, 'م'],
53
+ [/[Нн]/g, 'ن'],
54
+ [/[Пп]/g, 'پ'],
55
+ [/[Рр]/g, 'ر'],
56
+ [/[Сс]/g, 'ص'],
57
+ [/[Тт]/g, 'ط'],
58
+ [/[Фф]/g, 'ف'],
59
+ [/[Хх]/g, 'ح'],
60
+ [/[Цц]/g, 'ࢯ'],
61
+ [/[Чч]/g, 'چ'],
62
+ [/[Шш]/g, 'ش'],
63
+ [/[,]/g, '،'],
64
+ [/\?/g, '؟'],
65
+ ]),
62
66
  };
@@ -1,4 +1,4 @@
1
1
  export declare const cyrillic: {
2
- readonly lower: readonly [];
3
- readonly upper: readonly [];
2
+ readonly lower: import("..").CallableDict;
3
+ readonly upper: import("..").CallableDict;
4
4
  };
@@ -1,4 +1,5 @@
1
+ import { callableDict } from '../lib.js';
1
2
  export const cyrillic = {
2
- lower: [],
3
- upper: [],
3
+ lower: callableDict([]),
4
+ upper: callableDict([]),
4
5
  };
@@ -1,8 +1,8 @@
1
1
  export declare const latin: {
2
- lower: (readonly [RegExp, string])[];
3
- upper: (readonly [RegExp, string])[];
2
+ lower: import("../types").CallableDict;
3
+ upper: import("../types").CallableDict;
4
4
  };
5
5
  export declare const latinJi: {
6
- lower: (readonly [RegExp, string])[];
7
- upper: (readonly [RegExp, string])[];
6
+ lower: import("../types").CallableDict;
7
+ upper: import("../types").CallableDict;
8
8
  };
@@ -1,141 +1,139 @@
1
1
  import { iwords } from '../iwords.js';
2
- import { dictFrom } from '../lib.js';
2
+ import { callableDict } from '../lib.js';
3
+ import { re } from '../../lib/index.js';
3
4
  const common = {
4
5
  lower: [
5
6
  [
6
- [/(?<=[аеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)е/, 'je'],
7
- [/(?<=[eаеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)ё/, 'jo'],
8
- [/(?<=[eoаеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)ю/, 'ju'],
9
- [/(?<=[eouаеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)я/, 'ja'],
7
+ [/(?<=[аеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)е/g, 'je'],
8
+ [/(?<=[eаеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)ё/g, 'jo'],
9
+ [/(?<=[eoаеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)ю/g, 'ju'],
10
+ [/(?<=[eouаеёіоуўыэюяьʼ| >АЕЁІОУЎЫЭЮЯЬ]|^)я/g, 'ja'],
10
11
  ],
11
12
  [
12
- [/ʼ/, ''],
13
- [/ць/, 'ć'],
14
- [/зь/, 'ź'],
15
- [/сь/, 'ś'],
16
- [/нь/, 'ń'],
17
- [/ль/, 'l'],
18
- [/а/, 'a'],
19
- [/б/, 'b'],
20
- [/в/, 'v'],
21
- [/г/, 'h'],
22
- [/ґ/, 'g'],
23
- [/д/, 'd'],
24
- [/е/, 'ie'],
25
- [/ё/, 'io'],
26
- [/ж/, 'ž'],
27
- [/з/, 'z'],
28
- [/і/, 'i'],
29
- [/й/, 'j'],
30
- [/к/, 'k'],
31
- [/л/, 'ł'],
32
- [/м/, 'm'],
33
- [/н/, 'n'],
34
- [/о/, 'o'],
35
- [/п/, 'p'],
36
- [/р/, 'r'],
37
- [/с/, 's'],
38
- [/т/, 't'],
39
- [/у/, 'u'],
40
- [/ў/, 'ŭ'],
41
- [/ф/, 'f'],
42
- [/х/, 'ch'],
43
- [/ц/, 'c'],
44
- [/ч/, 'č'],
45
- [/ш/, 'š'],
46
- [/ы/, 'y'],
47
- [/э/, 'e'],
48
- [/ю/, 'iu'],
49
- [/я/, 'ia'],
50
- [/łi(?=[eoua])/, 'l'],
51
- [/łi/, 'li'],
13
+ [/ʼ/g, ''],
14
+ [/ць/g, 'ć'],
15
+ [/зь/g, 'ź'],
16
+ [/сь/g, 'ś'],
17
+ [/нь/g, 'ń'],
18
+ [/ль/g, 'l'],
19
+ [/а/g, 'a'],
20
+ [/б/g, 'b'],
21
+ [/в/g, 'v'],
22
+ [/г/g, 'h'],
23
+ [/ґ/g, 'g'],
24
+ [/д/g, 'd'],
25
+ [/е/g, 'ie'],
26
+ [/ё/g, 'io'],
27
+ [/ж/g, 'ž'],
28
+ [/з/g, 'z'],
29
+ [/і/g, 'i'],
30
+ [/й/g, 'j'],
31
+ [/к/g, 'k'],
32
+ [/л/g, 'ł'],
33
+ [/м/g, 'm'],
34
+ [/н/g, 'n'],
35
+ [/о/g, 'o'],
36
+ [/п/g, 'p'],
37
+ [/р/g, 'r'],
38
+ [/с/g, 's'],
39
+ [/т/g, 't'],
40
+ [/у/g, 'u'],
41
+ [/ў/g, 'ŭ'],
42
+ [/ф/g, 'f'],
43
+ [/х/g, 'ch'],
44
+ [/ц/g, 'c'],
45
+ [/ч/g, 'č'],
46
+ [/ш/g, 'š'],
47
+ [/ы/g, 'y'],
48
+ [/э/g, 'e'],
49
+ [/ю/g, 'iu'],
50
+ [/я/g, 'ia'],
51
+ [/łi(?=[eoua])/g, 'l'],
52
+ [/łi/g, 'li'],
52
53
  ],
53
- ].map(dictFrom.nonGlobal),
54
+ ],
54
55
  upper: [
55
56
  [
56
- [/ Е(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/u, ' Je'],
57
- [/ Ё(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/u, ' Jo'],
58
- [/ Ю(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/u, ' Ju'],
59
- [/ Я(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/u, ' Ja'],
57
+ [/ Е(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/gu, ' Je'],
58
+ [/ Ё(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/gu, ' Jo'],
59
+ [/ Ю(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/gu, ' Ju'],
60
+ [/ Я(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/gu, ' Ja'],
60
61
  ],
61
62
  [
62
- [/([АЕЁІОУЎЫЭЮЯЬ| ]\(?)Е/, '$1JE'],
63
- [/([EАЕЁІОУЎЫЭЮЯЬ| ]\(?)Ё/, '$1JO'],
64
- [/([EOАЕЁІОУЎЫЭЮЯЬ| ]\(?)Ю/, '$1JU'],
65
- [/([EOUАЕЁІОУЎЫЭЮЯЬ| ]\(?)Я/, '$1JA'],
63
+ [/([АЕЁІОУЎЫЭЮЯЬ| ]\(?)Е/g, '$1JE'],
64
+ [/([EАЕЁІОУЎЫЭЮЯЬ| ]\(?)Ё/g, '$1JO'],
65
+ [/([EOАЕЁІОУЎЫЭЮЯЬ| ]\(?)Ю/g, '$1JU'],
66
+ [/([EOUАЕЁІОУЎЫЭЮЯЬ| ]\(?)Я/g, '$1JA'],
66
67
  ],
67
68
  [
68
- [/Е/, 'IE'],
69
- [/Ё/, 'IO'],
70
- [/Ю/, 'IU'],
71
- [/Я/, 'IA'],
72
- [/Ц[Ьь]/, 'Ć'],
73
- [/З[Ьь]/, 'Ź'],
74
- [/С[Ьь]/, 'Ś'],
75
- [/Н[Ьь]/, 'Ń'],
76
- [/Л[Ьь]/, 'L'],
77
- [/А/, 'A'],
78
- [/Б/, 'B'],
79
- [/В/, 'V'],
80
- [/Г/, 'H'],
81
- [/Ґ/, 'G'],
82
- [/Д/, 'D'],
83
- [/Ж/, 'Ž'],
84
- [/З/, 'Z'],
85
- [/І/, 'I'],
86
- [/Й/, 'J'],
87
- [/К/, 'K'],
88
- [/Л/, 'Ł'],
89
- [/М/, 'M'],
90
- [/Н/, 'N'],
91
- [/О/, 'O'],
92
- [/П/, 'P'],
93
- [/Р/, 'R'],
94
- [/С/, 'S'],
95
- [/Т/, 'T'],
96
- [/У/, 'U'],
97
- [/Ў/, 'Ŭ'],
98
- [/Ф/, 'F'],
99
- [/ Х(?=[\p{Ll} ])/u, ' Ch'],
100
- [/Х/, 'CH'],
101
- [/Ц/, 'C'],
102
- [/Ч/, 'Č'],
103
- [/Ш/, 'Š'],
104
- [/Ы/, 'Y'],
105
- [/Э/, 'E'],
106
- [/Ł[Ii](?=[AEOUaeou])/, 'L'],
107
- [/Ł(?=[Ii])/, 'L'],
69
+ [/Е/g, 'IE'],
70
+ [/Ё/g, 'IO'],
71
+ [/Ю/g, 'IU'],
72
+ [/Я/g, 'IA'],
73
+ [/Ц[Ьь]/g, 'Ć'],
74
+ [/З[Ьь]/g, 'Ź'],
75
+ [/С[Ьь]/g, 'Ś'],
76
+ [/Н[Ьь]/g, 'Ń'],
77
+ [/Л[Ьь]/g, 'L'],
78
+ [/А/g, 'A'],
79
+ [/Б/g, 'B'],
80
+ [/В/g, 'V'],
81
+ [/Г/g, 'H'],
82
+ [/Ґ/g, 'G'],
83
+ [/Д/g, 'D'],
84
+ [/Ж/g, 'Ž'],
85
+ [/З/g, 'Z'],
86
+ [/І/g, 'I'],
87
+ [/Й/g, 'J'],
88
+ [/К/g, 'K'],
89
+ [/Л/g, 'Ł'],
90
+ [/М/g, 'M'],
91
+ [/Н/g, 'N'],
92
+ [/О/g, 'O'],
93
+ [/П/g, 'P'],
94
+ [/Р/g, 'R'],
95
+ [/С/g, 'S'],
96
+ [/Т/g, 'T'],
97
+ [/У/g, 'U'],
98
+ [/Ў/g, 'Ŭ'],
99
+ [/Ф/g, 'F'],
100
+ [/ Х(?=[\p{Ll} ])/gu, ' Ch'],
101
+ [/Х/g, 'CH'],
102
+ [/Ц/g, 'C'],
103
+ [/Ч/g, 'Č'],
104
+ [/Ш/g, 'Š'],
105
+ [/Ы/g, 'Y'],
106
+ [/Э/g, 'E'],
107
+ [/Ł[Ii](?=[AEOUaeou])/g, 'L'],
108
+ [/Ł(?=[Ii])/g, 'L'],
108
109
  ],
109
- ].map(dictFrom.nonGlobal),
110
+ ],
110
111
  };
111
112
  export const latin = {
112
- lower: [...common.lower[0], [/ʼі/g, 'ji'], ...common.lower[1]],
113
- upper: common.upper.flat(),
113
+ lower: callableDict([...common.lower[0], [/ʼі/g, 'ji'], ...common.lower[1]]),
114
+ upper: callableDict(common.upper.flat()),
114
115
  };
115
116
  export const latinJi = {
116
- lower: dictFrom
117
- .raw([
118
- [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )і Ў/, '$1j U'],
119
- [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )і ў/, '$1j u'],
120
- [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )і /, '$1j '],
121
- [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )І Ў/, '$1J U'],
122
- [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )І ў/, '$1J u'],
123
- [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )І /, '$1J '],
124
- [` і(?=${iwords})`, ' ji'],
125
- [` І(?=${iwords})`, ' Ji'],
126
- [` І(?=${iwords.toUpperCase()})`, ' JI'],
127
- ])
128
- .concat([
117
+ lower: callableDict([
118
+ [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )і Ў/g, '$1j U'],
119
+ [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )і ў/g, '$1j u'],
120
+ [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )і /g, '$1j '],
121
+ [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )І Ў/g, '$1J U'],
122
+ [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )І ў/g, '$1J u'],
123
+ [/([аеёіоуыэюяАЕЁІОУЫЭЮЯ] )І /g, '$1J '],
124
+ [re.g(` і(?=${iwords})`), ' ji'],
125
+ [re.g(` І(?=${iwords})`), ' Ji'],
126
+ [re.g(` І(?=${iwords.toUpperCase()})`), ' JI'],
129
127
  ...common.lower[0],
130
128
  [/([eouaаеёіоуыэюяʼАЕЁІОУЫЭЮЯЬ] *)і/g, '$1ji'],
131
129
  ...common.lower[1],
132
130
  ]),
133
- upper: [
131
+ upper: callableDict([
134
132
  ...common.upper[0],
135
133
  [/([eoua] *)І(?=[ \p{P}\d]*\p{Lu}?\p{Ll})/gu, '$1Ji'],
136
134
  ...common.upper[1],
137
135
  [/([AOEUАЕЁІОУЎЫЭЮЯ][( ]*)І/g, '$1JI'],
138
136
  ...common.upper[2],
139
137
  [/ JIŁ -/g, ' IŁ -'],
140
- ],
138
+ ]),
141
139
  };
@@ -1,4 +1,4 @@
1
- import type { Dict } from '../types';
1
+ import type { CallableDict } from '../types';
2
2
  /**
3
3
  * If {@link Alphabet.upper} in not defined,
4
4
  * it is assumed that the alphabet is case-insensitive,
@@ -6,6 +6,6 @@ import type { Dict } from '../types';
6
6
  * upper and lower case letters.
7
7
  */
8
8
  export type Alphabet = {
9
- lower: Dict;
10
- upper?: Dict;
9
+ lower: CallableDict;
10
+ upper?: CallableDict;
11
11
  };
@@ -1 +1 @@
1
- export declare const iaWords: import("./types").Dict;
1
+ export declare const iaWords: import("./types").CallableDict;
@@ -1,7 +1,8 @@
1
1
  import { iwords } from './iwords.js';
2
- import { dictFrom, toOneLine } from './lib.js';
3
- const ia = (word, words) => ` ${word}(?= \\(?(?:[бвгджзйклмнпрстфхцчшўьʼ]*[оё]|${toOneLine(words).replace(/\(/g, '(?:')}|i(?:${iwords})))`;
4
- export const iaWords = dictFrom.raw([
2
+ import { callableDict, toOneLine } from './lib.js';
3
+ import { re } from '../lib/index.js';
4
+ const ia = (word, words) => re.g(` ${word}(?= \\(?(?:[бвгджзйклмнпрстфхцчшўьʼ]*[оё]|${toOneLine(words).replace(/\(/g, '(?:')}|i(?:${iwords})))`);
5
+ export const iaWords = callableDict([
5
6
 
6
7
  [
7
8
  ia('не', `(вы)?(бач[ауы]
@@ -1,25 +1,13 @@
1
- import type { Dict, RawDict, WritableDict } from './types';
1
+ import type { CallableDict, Dict } from './types';
2
2
  export declare const copyDict: <T extends [any, any][]>(dict: T) => T;
3
3
  /**
4
- * Collection of MUTATING functions
5
- * that help to work with dictionaries.
4
+ * @returns function with property `value` that references the dictionary
5
+ * passed as an argument.
6
6
  *
7
- * Use {@link copyDict} before applying these functions
8
- * to avoid mutating the original dictionary.
7
+ * It is possible to change the dictionary after initialization by modifying
8
+ * the `value` property.
9
9
  *
10
- * @example
11
- * const rawDict = [
12
- * ["pattern", "result"],
13
- * ];
14
- *
15
- * const dict = dictFrom.raw(copyDict(rawDict));
16
- * // [ [ /pattern/g, "result" ] ]
10
+ * You can use {@link copyDict} before passing the dictionary to this function
17
11
  */
18
- export declare const dictFrom: {
19
- raw: (dict: RawDict, additionalFlags?: string) => Dict;
20
- /**
21
- * Adds the global flag to all patterns in the dictionary.
22
- */
23
- nonGlobal: (dict: WritableDict) => Dict;
24
- };
12
+ export declare const callableDict: (value: Dict) => CallableDict;
25
13
  export declare const toOneLine: (str: string) => string;
package/dist/dict/lib.js CHANGED
@@ -1,18 +1,8 @@
1
- export const copyDict = (dict) => dict.map(([pattern, result]) => [pattern, result]);
1
+ export const copyDict = (dict) => dict.map(({ 0: pattern, 1: result }) => [pattern, result]);
2
2
 
3
- export const dictFrom = {
4
- raw: (dict, additionalFlags = 'g') => {
5
- for (const item of dict)
6
- item[0] = RegExp(item[0], item[0] instanceof RegExp
7
- ? item[0].flags + additionalFlags
8
- : additionalFlags);
9
- return dict;
10
- },
11
-
12
- nonGlobal: (dict) => {
13
- for (const item of dict)
14
- item[0] = RegExp(item[0], 'g' + item[0].flags);
15
- return dict;
16
- },
3
+ export const callableDict = (value) => {
4
+ const fn = (text) => fn.value.reduce((acc, item) => acc.replace(item[0], item[1]), text);
5
+ fn.value = value;
6
+ return fn;
17
7
  };
18
8
  export const toOneLine = (str) => str.replace(/\n/g, '|');
@@ -1,3 +1,3 @@
1
1
  import type { Dict } from './types';
2
2
  export declare const commonPhonetic: Dict;
3
- export declare const phonetic: Dict;
3
+ export declare const phonetic: import("./types").CallableDict;
@@ -1,12 +1,13 @@
1
+ import { callableDict } from './lib.js';
1
2
  export const commonPhonetic = [
2
3
  [/шся /g, 'сься '],
3
4
  [/здж/g, 'ждж'],
4
- [/ ([бд]|кнд|нот)р /, ' $1\ue0ffр '],
5
- [/(\S\S[дт])р /, '$1ар '],
5
+ [/ ([бд]|кнд|нот)р /g, ' $1\ue0ffр '],
6
+ [/(\S\S[дт])р /g, '$1ар '],
6
7
  ];
7
- export const phonetic = [
8
+ export const phonetic = callableDict([
8
9
  [/сш/g, 'шш'],
9
10
  [/[зс]ч/g, 'шч'],
10
11
  [/чц(?![ьіеюя])/g, 'цц'],
11
12
  [/[жш]ц(?=ы )/g, 'сц'],
12
- ].concat(commonPhonetic);
13
+ ].concat(commonPhonetic));
@@ -1,2 +1,2 @@
1
- export declare const noSoften: import("./types").Dict;
2
- export declare const softeners: import("./types").Dict;
1
+ export declare const noSoften: import("./types").CallableDict;
2
+ export declare const softeners: import("./types").CallableDict;
@@ -1,19 +1,20 @@
1
- import { dictFrom } from './lib.js';
1
+ import { callableDict } from './lib.js';
2
+ import { re } from '../lib/index.js';
2
3
  import { iwords } from './iwords.js';
3
- export const noSoften = dictFrom.nonGlobal([
4
- [/масфільм/, 'мас\ue0ffфільм'],
5
- [/пэндзлік/, 'пэндз\ue0ffлік'],
6
- [/ ((?:[пн]|пе?р)?)аддз/, ' $1ад\ue0ffдз'],
4
+ export const noSoften = callableDict([
5
+ [/масфільм/g, 'мас\ue0ffфільм'],
6
+ [/пэндзлік/g, 'пэндз\ue0ffлік'],
7
+ [/ ((?:[пн]|пе?р)?)аддз/g, ' $1ад\ue0ffдз'],
7
8
  ]);
8
- export const softeners = dictFrom.raw([
9
- [/([лнц])\1(?=[еёіюяь])/, '$1ь$1'],
10
- [/(\S\S)дз?дз(?=[еёіюяь])/, '$1дзьдз'],
11
- [/з(?=(?:[бвзлмнц]|дз)[еёіюяь])/, 'зь'],
12
- [/с(?=[бвлмнпсфц][еёіюяь])/, 'сь'],
13
- [/ц(?=[вм][еёіюяь])/, 'ць'],
9
+ export const softeners = callableDict([
10
+ [/([лнц])\1(?=[еёіюяь])/g, '$1ь$1'],
11
+ [/(\S\S)дз?дз(?=[еёіюяь])/g, '$1дзьдз'],
12
+ [/з(?=(?:[бвзлмнц]|дз)[еёіюяь])/g, 'зь'],
13
+ [/с(?=[бвлмнпсфц][еёіюяь])/g, 'сь'],
14
+ [/ц(?=[вм][еёіюяь])/g, 'ць'],
14
15
  [
15
- `( (?:б[ея]|пра|цера)?з) (?=\\(?)(?=[еёюяь]|([бвзйлмнпстфц]|дз)[еёіюяь]|імі? |іх(?:ні)?|і(?:${iwords}))`,
16
+ re.g(`( (?:б[ея]|пра|цера)?з) (?=\\(?)(?=[еёюяь]|([бвзйлмнпстфц]|дз)[еёіюяь]|імі? |іх(?:ні)?|і(?:${iwords}))`),
16
17
  '$1ь ',
17
18
  ],
18
- [/([сз])ʼ(?=[яюеё])/, '$1ь'],
19
+ [/([сз])ʼ(?=[яюеё])/g, '$1ь'],
19
20
  ]);
@@ -1,15 +1,12 @@
1
1
  export type Dict<T = RegExp> = readonly (readonly [T, string])[];
2
+ export type CallableDict<T = RegExp> = {
3
+ (value: string): string;
4
+ value: Dict<T>;
5
+ };
2
6
  /**
3
7
  * Useful if you want to modify the dictionary.
4
8
  *
5
- * Consider converting it to the type {@link Dict}
9
+ * Consider converting it to the type {@link Dict} or {@link CallableDict}
6
10
  * if you no longer need to modify it.
7
11
  */
8
12
  export type WritableDict<T = RegExp> = [T, string][];
9
- /**
10
- * useful if you use variables in patterns.
11
- *
12
- * Don't forget to convert it to the type {@link Dict},
13
- * {@link lib.dictFrom} can help you with this.
14
- */
15
- export type RawDict = WritableDict<string | RegExp>;
@@ -1,2 +1 @@
1
- import type { Dict } from "./types";
2
- export declare const wordlist: Dict;
1
+ export declare const wordlist: import("./types").CallableDict;