taraskevizer 2.0.4 → 2.1.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.
package/dist/bin.js ADDED
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+ import { tarask, taraskToHtml } from "./index.js";
3
+ import { readFile } from "fs/promises";
4
+ const printWithPrefix = (msg) => {
5
+ process.stdout.write(
6
+ "\x1B[34m[taraskevizer]\x1B[0m " + msg.toString() + "\n"
7
+ );
8
+ };
9
+ process.argv.splice(0, 2);
10
+ const checkForOptions = (options) => options.includes(process.argv[0].toLowerCase());
11
+ if (checkForOptions(["-v", "--version"])) {
12
+ const { version } = JSON.parse(
13
+ await readFile(new URL("../package.json", import.meta.url), "utf8")
14
+ );
15
+ printWithPrefix(version);
16
+ process.exit(0);
17
+ }
18
+ const taraskOptions = {};
19
+ const nonHtmlOptions = {
20
+ variations: 2,
21
+ nodeColors: true
22
+ };
23
+ const htmlOptions = { g: true };
24
+ let isHtml = false;
25
+ const toHashTable = (dict) => {
26
+ const result = {};
27
+ for (const [options, callback] of dict)
28
+ for (const option of options)
29
+ result[option] = callback;
30
+ return result;
31
+ };
32
+ const optionDict = toHashTable([
33
+ [
34
+ ["--latin", "-l"],
35
+ () => {
36
+ taraskOptions.abc = 1;
37
+ }
38
+ ],
39
+ [
40
+ ["--arabic", "-a"],
41
+ () => {
42
+ taraskOptions.abc = 2;
43
+ }
44
+ ],
45
+ [
46
+ ["--greek", "-gr"],
47
+ () => {
48
+ taraskOptions.abc = 3;
49
+ }
50
+ ],
51
+ [
52
+ ["--jrandom", "-jr"],
53
+ () => {
54
+ taraskOptions.j = 1;
55
+ }
56
+ ],
57
+ [
58
+ ["--jalways", "-ja"],
59
+ () => {
60
+ taraskOptions.j = 2;
61
+ }
62
+ ],
63
+ [
64
+ ["--h", "-h"],
65
+ () => {
66
+ nonHtmlOptions.h = true;
67
+ htmlOptions.g = false;
68
+ }
69
+ ],
70
+ [
71
+ ["--no-variations", "-nv"],
72
+ () => {
73
+ nonHtmlOptions.variations = 0;
74
+ }
75
+ ],
76
+ [
77
+ ["--first-variation-only", "-fvo"],
78
+ () => {
79
+ nonHtmlOptions.variations = 1;
80
+ }
81
+ ],
82
+ [
83
+ ["--no-color", "-nc"],
84
+ () => {
85
+ nonHtmlOptions.nodeColors = false;
86
+ }
87
+ ],
88
+ [
89
+ ["--html", "-html"],
90
+ () => {
91
+ isHtml = true;
92
+ }
93
+ ]
94
+ ]);
95
+ let currOption;
96
+ while (currOption = process.argv.shift()) {
97
+ if (currOption in optionDict) {
98
+ optionDict[currOption]();
99
+ } else {
100
+ process.argv.unshift(currOption);
101
+ break;
102
+ }
103
+ }
104
+ const text = process.argv.join(" ");
105
+ process.stdout.write(
106
+ isHtml ? taraskToHtml(text, taraskOptions, htmlOptions) : tarask(text, taraskOptions, nonHtmlOptions)
107
+ );
package/dist/index.cjs CHANGED
@@ -78,10 +78,10 @@ var latinLetters = [
78
78
  [/łi/, "li"]
79
79
  ];
80
80
  var latinLettersUpperCase = [
81
- [/ Е(?= *\p{Ll})/u, " Je"],
82
- [/ Ё(?= *\p{Ll})/u, " Jo"],
83
- [/ Ю(?= *\p{Ll})/u, " Ju"],
84
- [/ Я(?= *\p{Ll})/u, " Ja"],
81
+ [new RegExp(" Е(?= *\\p{Ll})", "u"), " Je"],
82
+ [new RegExp(" Ё(?= *\\p{Ll})", "u"), " Jo"],
83
+ [new RegExp(" Ю(?= *\\p{Ll})", "u"), " Ju"],
84
+ [new RegExp(" Я(?= *\\p{Ll})", "u"), " Ja"],
85
85
  [/(?<=[АЕЁІОУЎЫЭЮЯЬʼ| ]\(?)Е/, "JE"],
86
86
  [/(?<=[АЕЁІОУЎЫЭЮЯЬʼ| ]\(?)Ё/, "JO"],
87
87
  [/(?<=[АЕЁІОУЎЫЭЮЯЬʼ| ]\(?)Ю/, "JU"],
@@ -169,12 +169,12 @@ var greekLetters = [
169
169
  [/ь/, "’"]
170
170
  ];
171
171
  var greekLettersUpperCase = [
172
- [/ Б(?= *\p{Ll})/u, " Μπ"],
173
- [/ Ґ(?= *\p{Ll})/u, " Γκ"],
174
- [/ Ё(?= *\p{Ll})/u, " Υο"],
175
- [/ Ю(?= *\p{Ll})/u, " Υϋ"],
176
- [/ Я(?= *\p{Ll})/u, " Υα"],
177
- [/ Ч(?= *\p{Ll})/u, " Τσ̌"],
172
+ [new RegExp(" Б(?= *\\p{Ll})", "u"), " Μπ"],
173
+ [new RegExp(" Ґ(?= *\\p{Ll})", "u"), " Γκ"],
174
+ [new RegExp(" Ё(?= *\\p{Ll})", "u"), " Υο"],
175
+ [new RegExp(" Ю(?= *\\p{Ll})", "u"), " Υϋ"],
176
+ [new RegExp(" Я(?= *\\p{Ll})", "u"), " Υα"],
177
+ [new RegExp(" Ч(?= *\\p{Ll})", "u"), " Τσ̌"],
178
178
  [/Б/, "ΜΠ"],
179
179
  [/Ґ/, "ΓΚ"],
180
180
  [/Ё/, "ΥΟ"],
@@ -2132,7 +2132,7 @@ for (const word of gwords)
2132
2132
  var isUpperCase = (str) => str === str.toUpperCase();
2133
2133
  var getLastLetter = (word, i) => {
2134
2134
  for (let i2 = word.length - 1; i2 >= 0; i2--)
2135
- if (/\p{L}/u.test(word[i2]))
2135
+ if (new RegExp("\\p{L}", "u").test(word[i2]))
2136
2136
  return word[i2];
2137
2137
  throw new Error(`the last letter of the word ${word} not found. index: ${i}`);
2138
2138
  };
@@ -2186,7 +2186,7 @@ var process = (text, LEFT_ANGLE_BRACKET, options) => {
2186
2186
  return LEFT_ANGLE_BRACKET + $2 + ">";
2187
2187
  noFix2[noFix2.length] = $1 === "." ? $2 : $0;
2188
2188
  return NOFIX_CHAR;
2189
- }).replace(/г'(?![еёіюя])/g, "ґ").replace(/([\n\t])/g, " $1 ").replace(/ - /g, " — ").replace(/(\p{P}|\p{S}|\d)/gu, " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40");
2189
+ }).replace(/г'(?![еёіюя])/g, "ґ").replace(/([\n\t])/g, " $1 ").replace(/ - /g, " — ").replace(new RegExp("(\\p{P}|\\p{S}|\\d)", "gu"), " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40");
2190
2190
  let splittedOrig, splitted;
2191
2191
  splittedOrig = replaceWithDict(
2192
2192
  replaceWithDict(text, letters[abc]),
@@ -2215,7 +2215,7 @@ var applyNoFix = (text) => {
2215
2215
  noFix = [];
2216
2216
  return text;
2217
2217
  };
2218
- var join = (textArr) => textArr.join(" ").replace(/&nbsp;/g, " ").replace(/ (\p{P}|\p{S}|\d|&#40) /gu, "$1");
2218
+ var join = (textArr) => textArr.join(" ").replace(/&nbsp;/g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d|&#40) ", "gu"), "$1");
2219
2219
  var finilize = (text, newLine) => text.replace(/ \t /g, " ").replace(/ \n /g, newLine).trim();
2220
2220
  var replaceG = (text, replacer) => text.replace(
2221
2221
  G_REGEX,
package/dist/index.d.ts CHANGED
@@ -56,4 +56,4 @@ declare const gobj: {
56
56
  readonly Ґ: "Г";
57
57
  };
58
58
 
59
- export { ALPHABET, AlphabetDependentDict, DeepPartialReadonly, Dict, ExtendedDict, HtmlOptions, J, NonHtmlOptions, ReplaceWithDict, Tarask, TaraskOptions, ToTarask, VARIATION, gobj, tarask, taraskToHtml };
59
+ export { ALPHABET, type AlphabetDependentDict, type DeepPartialReadonly, type Dict, type ExtendedDict, type HtmlOptions, J, type NonHtmlOptions, type ReplaceWithDict, type Tarask, type TaraskOptions, type ToTarask, VARIATION, gobj, tarask, taraskToHtml };
package/dist/index.js CHANGED
@@ -47,10 +47,10 @@ var latinLetters = [
47
47
  [/łi/, "li"]
48
48
  ];
49
49
  var latinLettersUpperCase = [
50
- [/ Е(?= *\p{Ll})/u, " Je"],
51
- [/ Ё(?= *\p{Ll})/u, " Jo"],
52
- [/ Ю(?= *\p{Ll})/u, " Ju"],
53
- [/ Я(?= *\p{Ll})/u, " Ja"],
50
+ [new RegExp(" Е(?= *\\p{Ll})", "u"), " Je"],
51
+ [new RegExp(" Ё(?= *\\p{Ll})", "u"), " Jo"],
52
+ [new RegExp(" Ю(?= *\\p{Ll})", "u"), " Ju"],
53
+ [new RegExp(" Я(?= *\\p{Ll})", "u"), " Ja"],
54
54
  [/(?<=[АЕЁІОУЎЫЭЮЯЬʼ| ]\(?)Е/, "JE"],
55
55
  [/(?<=[АЕЁІОУЎЫЭЮЯЬʼ| ]\(?)Ё/, "JO"],
56
56
  [/(?<=[АЕЁІОУЎЫЭЮЯЬʼ| ]\(?)Ю/, "JU"],
@@ -138,12 +138,12 @@ var greekLetters = [
138
138
  [/ь/, "’"]
139
139
  ];
140
140
  var greekLettersUpperCase = [
141
- [/ Б(?= *\p{Ll})/u, " Μπ"],
142
- [/ Ґ(?= *\p{Ll})/u, " Γκ"],
143
- [/ Ё(?= *\p{Ll})/u, " Υο"],
144
- [/ Ю(?= *\p{Ll})/u, " Υϋ"],
145
- [/ Я(?= *\p{Ll})/u, " Υα"],
146
- [/ Ч(?= *\p{Ll})/u, " Τσ̌"],
141
+ [new RegExp(" Б(?= *\\p{Ll})", "u"), " Μπ"],
142
+ [new RegExp(" Ґ(?= *\\p{Ll})", "u"), " Γκ"],
143
+ [new RegExp(" Ё(?= *\\p{Ll})", "u"), " Υο"],
144
+ [new RegExp(" Ю(?= *\\p{Ll})", "u"), " Υϋ"],
145
+ [new RegExp(" Я(?= *\\p{Ll})", "u"), " Υα"],
146
+ [new RegExp(" Ч(?= *\\p{Ll})", "u"), " Τσ̌"],
147
147
  [/Б/, "ΜΠ"],
148
148
  [/Ґ/, "ΓΚ"],
149
149
  [/Ё/, "ΥΟ"],
@@ -2101,7 +2101,7 @@ for (const word of gwords)
2101
2101
  var isUpperCase = (str) => str === str.toUpperCase();
2102
2102
  var getLastLetter = (word, i) => {
2103
2103
  for (let i2 = word.length - 1; i2 >= 0; i2--)
2104
- if (/\p{L}/u.test(word[i2]))
2104
+ if (new RegExp("\\p{L}", "u").test(word[i2]))
2105
2105
  return word[i2];
2106
2106
  throw new Error(`the last letter of the word ${word} not found. index: ${i}`);
2107
2107
  };
@@ -2155,7 +2155,7 @@ var process = (text, LEFT_ANGLE_BRACKET, options) => {
2155
2155
  return LEFT_ANGLE_BRACKET + $2 + ">";
2156
2156
  noFix2[noFix2.length] = $1 === "." ? $2 : $0;
2157
2157
  return NOFIX_CHAR;
2158
- }).replace(/г'(?![еёіюя])/g, "ґ").replace(/([\n\t])/g, " $1 ").replace(/ - /g, " — ").replace(/(\p{P}|\p{S}|\d)/gu, " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40");
2158
+ }).replace(/г'(?![еёіюя])/g, "ґ").replace(/([\n\t])/g, " $1 ").replace(/ - /g, " — ").replace(new RegExp("(\\p{P}|\\p{S}|\\d)", "gu"), " $1 ").replace(/ ['`’] (?=\S)/g, "ʼ").replace(/\(/g, "&#40");
2159
2159
  let splittedOrig, splitted;
2160
2160
  splittedOrig = replaceWithDict(
2161
2161
  replaceWithDict(text, letters[abc]),
@@ -2184,7 +2184,7 @@ var applyNoFix = (text) => {
2184
2184
  noFix = [];
2185
2185
  return text;
2186
2186
  };
2187
- var join = (textArr) => textArr.join(" ").replace(/&nbsp;/g, " ").replace(/ (\p{P}|\p{S}|\d|&#40) /gu, "$1");
2187
+ var join = (textArr) => textArr.join(" ").replace(/&nbsp;/g, " ").replace(new RegExp(" (\\p{P}|\\p{S}|\\d|&#40) ", "gu"), "$1");
2188
2188
  var finilize = (text, newLine) => text.replace(/ \t /g, " ").replace(/ \n /g, newLine).trim();
2189
2189
  var replaceG = (text, replacer) => text.replace(
2190
2190
  G_REGEX,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "taraskevizer",
3
3
  "author": "GooseOb",
4
4
  "license": "MIT",
5
- "version": "2.0.4",
5
+ "version": "2.1.0",
6
6
  "private": false,
7
7
  "homepage": "https://gooseob.github.io/taraskevizatar/",
8
8
  "main": "dist/index.js",
@@ -10,11 +10,10 @@
10
10
  "types": "dist/index.d.ts",
11
11
  "type": "module",
12
12
  "bin": {
13
- "tarask": "bin/index.js"
13
+ "tarask": "dist/bin.js"
14
14
  },
15
15
  "files": [
16
16
  "dist/**/*",
17
- "bin/**/*",
18
17
  "README.md"
19
18
  ],
20
19
  "scripts": {
@@ -39,13 +38,13 @@
39
38
  "belarusian"
40
39
  ],
41
40
  "devDependencies": {
42
- "@digitak/esrun": "^3.2.24",
43
- "@types/node": "^20.5.4",
44
- "bun-types": "^1.0.1",
41
+ "@digitak/esrun": "^3.2.25",
42
+ "@types/node": "^20.10.4",
43
+ "bun-types": "^1.0.17",
45
44
  "husky": "^8.0.3",
46
- "prettier": "^3.0.0",
47
- "simple-git": "^3.19.1",
45
+ "prettier": "^3.1.1",
46
+ "simple-git": "^3.21.0",
48
47
  "tsup": "^7.2.0",
49
- "typescript": "^5.2.2"
48
+ "typescript": "^5.3.3"
50
49
  }
51
50
  }
package/bin/index.js DELETED
@@ -1,121 +0,0 @@
1
- #!/usr/bin/env node
2
- import { tarask, taraskToHtml } from '../dist/index.js';
3
- import { readFile } from 'fs/promises';
4
-
5
- const printWithPrefix = (msg) => {
6
- process.stdout.write(
7
- '\x1b[34m[taraskevizer]\x1b[0m ' + msg.toString() + '\n'
8
- );
9
- };
10
-
11
- process.argv.splice(0, 2);
12
-
13
- const checkForOptions = (options) =>
14
- options.includes(process.argv[0].toLowerCase());
15
-
16
- if (checkForOptions(['-v', '--version'])) {
17
- const { version } = JSON.parse(
18
- await readFile(new URL('../package.json', import.meta.url), 'utf8')
19
- );
20
- printWithPrefix(version);
21
- process.exit(0);
22
- }
23
-
24
- /** @type {Partial<import('../dist/types.js').TaraskOptions>} */
25
- const taraskOptions = {};
26
- /** @type {Partial<import('../dist/types.js').NonHtmlOptions>} */
27
- const nonHtmlOptions = { variations: 2, nodeColors: true };
28
- /** @type {Partial<import('../dist/types.js').HtmlOptions>} */
29
- const htmlOptions = { g: true };
30
-
31
- let isHtml = false;
32
-
33
- const toHashTable = (dict) => {
34
- const result = {};
35
- for (const [options, callback] of dict)
36
- for (const option of options) result[option] = callback;
37
- return result;
38
- };
39
-
40
- const optionDict = toHashTable([
41
- [
42
- ['--latin', '-l'],
43
- () => {
44
- taraskOptions.abc = 1;
45
- },
46
- ],
47
- [
48
- ['--arabic', '-a'],
49
- () => {
50
- taraskOptions.abc = 2;
51
- },
52
- ],
53
- [
54
- ['--greek', '-gr'],
55
- () => {
56
- taraskOptions.abc = 3;
57
- },
58
- ],
59
- [
60
- ['--jrandom', '-jr'],
61
- () => {
62
- taraskOptions.j = 1;
63
- },
64
- ],
65
- [
66
- ['--jalways', '-ja'],
67
- () => {
68
- taraskOptions.j = 2;
69
- },
70
- ],
71
- [
72
- ['--h', '-h'],
73
- () => {
74
- nonHtmlOptions.h = true;
75
- htmlOptions.g = false;
76
- },
77
- ],
78
- [
79
- ['--no-variations', '-nv'],
80
- () => {
81
- nonHtmlOptions.variations = 0;
82
- },
83
- ],
84
- [
85
- ['--first-variation-only', '-fvo'],
86
- () => {
87
- nonHtmlOptions.variations = 1;
88
- },
89
- ],
90
- [
91
- ['--no-color', '-nc'],
92
- () => {
93
- nonHtmlOptions.nodeColors = false;
94
- },
95
- ],
96
- [
97
- ['--html', '-html'],
98
- () => {
99
- isHtml = true;
100
- },
101
- ],
102
- ]);
103
-
104
- let currOption;
105
-
106
- while ((currOption = process.argv.shift())) {
107
- if (currOption in optionDict) {
108
- optionDict[currOption]();
109
- } else {
110
- process.argv.unshift(currOption);
111
- break;
112
- }
113
- }
114
-
115
- const text = process.argv.join(' ');
116
-
117
- process.stdout.write(
118
- isHtml
119
- ? taraskToHtml(text, taraskOptions, htmlOptions)
120
- : tarask(text, taraskOptions, nonHtmlOptions)
121
- );
package/dist/index.d.cts DELETED
@@ -1,59 +0,0 @@
1
- type ModifyObjectType<T, TResultObj> = T extends object ? T extends (...args: any[]) => any ? T : TResultObj : T;
2
- type DeepPartialReadonly<T> = ModifyObjectType<T, {
3
- readonly [P in keyof T]?: DeepPartialReadonly<T[P]>;
4
- }>;
5
- type Alphabet = 0 | 1 | 2 | 3;
6
- type OptionJ = 0 | 1 | 2;
7
- type Variation = 0 | 1 | 2;
8
- type TaraskOptions = {
9
- abc: Alphabet;
10
- j: OptionJ;
11
- OVERRIDE_toTarask?: ToTarask;
12
- };
13
- type NonHtmlOptions = {
14
- nodeColors: boolean;
15
- h: boolean;
16
- variations: Variation;
17
- };
18
- type HtmlOptions = {
19
- g: boolean;
20
- };
21
- type ReplaceWithDict = (text: string, dict?: ExtendedDict) => string;
22
- type ToTarask = (text: string, replaceWithDict: ReplaceWithDict, wordlist: Dict, softers: Dict, afterTarask: ExtendedDict) => string;
23
- type Tarask<TOptions extends object> = (text: string, taraskOptions?: DeepPartialReadonly<TaraskOptions>, options?: DeepPartialReadonly<TOptions>) => string;
24
- type Dict<T = RegExp> = [T, string][];
25
- type ExtendedDict = [
26
- RegExp,
27
- string | ((...substrings: string[]) => string)
28
- ][];
29
- type AlphabetDependentDict = {
30
- [key in Alphabet]?: Dict;
31
- };
32
-
33
- declare const ALPHABET: {
34
- readonly CYRILLIC: 0;
35
- readonly LATIN: 1;
36
- readonly ARABIC: 2;
37
- readonly GREEK: 3;
38
- };
39
- declare const J: {
40
- readonly NEVER: 0;
41
- readonly RANDOM: 1;
42
- readonly ALWAYS: 2;
43
- };
44
- declare const VARIATION: {
45
- readonly NO: 0;
46
- readonly FIRST: 1;
47
- readonly ALL: 2;
48
- };
49
- declare const taraskToHtml: Tarask<HtmlOptions>;
50
- declare const tarask: Tarask<NonHtmlOptions>;
51
-
52
- declare const gobj: {
53
- readonly г: "ґ";
54
- readonly Г: "Ґ";
55
- readonly ґ: "г";
56
- readonly Ґ: "Г";
57
- };
58
-
59
- export { ALPHABET, AlphabetDependentDict, DeepPartialReadonly, Dict, ExtendedDict, HtmlOptions, J, NonHtmlOptions, ReplaceWithDict, Tarask, TaraskOptions, ToTarask, VARIATION, gobj, tarask, taraskToHtml };