taraskevizer 2.1.2 → 3.0.0-alpha.2

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 CHANGED
@@ -19,7 +19,7 @@ const taraskedText = tarask(
19
19
  j: J.ALWAYS,
20
20
  },
21
21
  {
22
- nodeColors: true,
22
+ ansiColors: true,
23
23
  variations: VARIATION.FIRST,
24
24
  h: false,
25
25
  }
@@ -110,7 +110,7 @@ true: <tarH>ґ</tarH> <tarH>Ґ</tarH>
110
110
 
111
111
  ## NonHtmlOptions
112
112
 
113
- ### nodeColors
113
+ ### ansiColors
114
114
 
115
115
  Type: `boolean`
116
116
 
package/dist/bin.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { tarask, taraskToHtml } from "./index.js";
3
+ import readline from "readline/promises";
3
4
  import { readFile } from "fs/promises";
5
+ const prefix = "\x1B[34m[taraskevizer]\x1B[0m ";
4
6
  const printWithPrefix = (msg) => {
5
- process.stdout.write(
6
- "\x1B[34m[taraskevizer]\x1B[0m " + msg.toString() + "\n"
7
- );
7
+ process.stdout.write(prefix + msg.toString() + "\n");
8
8
  };
9
9
  process.argv.splice(0, 2);
10
- const checkForOptions = (options) => options.includes(process.argv[0].toLowerCase());
10
+ const checkForOptions = (options) => process.argv[0] && options.includes(process.argv[0].toLowerCase());
11
11
  if (checkForOptions(["-v", "--version"])) {
12
12
  const { version } = JSON.parse(
13
13
  await readFile(new URL("../package.json", import.meta.url), "utf8")
@@ -18,7 +18,7 @@ if (checkForOptions(["-v", "--version"])) {
18
18
  const taraskOptions = {};
19
19
  const nonHtmlOptions = {
20
20
  variations: 2,
21
- nodeColors: true
21
+ ansiColors: true
22
22
  };
23
23
  const htmlOptions = { g: true };
24
24
  let isHtml = false;
@@ -82,7 +82,7 @@ const optionDict = toHashTable([
82
82
  [
83
83
  ["--no-color", "-nc"],
84
84
  () => {
85
- nonHtmlOptions.nodeColors = false;
85
+ nonHtmlOptions.ansiColors = false;
86
86
  }
87
87
  ],
88
88
  [
@@ -101,7 +101,11 @@ while (currOption = process.argv.shift()) {
101
101
  break;
102
102
  }
103
103
  }
104
- const text = process.argv.join(" ");
104
+ let text = process.argv.length ? process.argv.join(" ") : await readline.createInterface({
105
+ input: process.stdin,
106
+ output: process.stdout
107
+ }).question(prefix + "Enter the text:\n");
105
108
  process.stdout.write(
106
109
  isHtml ? taraskToHtml(text, taraskOptions, htmlOptions) : tarask(text, taraskOptions, nonHtmlOptions)
107
110
  );
111
+ process.exit(0);
package/dist/index.cjs CHANGED
@@ -2153,15 +2153,14 @@ var lettersUpperCase = {
2153
2153
  [ALPHABET.LATIN]: latinLettersUpperCase,
2154
2154
  [ALPHABET.GREEK]: greekLettersUpperCase
2155
2155
  };
2156
- var tagApplications = {
2156
+ var wrappers = {
2157
2157
  html: {
2158
- F: (content) => `<tarF>${content}</tarF>`,
2159
- H: (content) => `<tarH>${content}</tarH>`
2158
+ fix: (content) => `<tarF>${content}</tarF>`,
2159
+ letterH: (content) => `<tarH>${content}</tarH>`
2160
2160
  },
2161
- nonHtml: {
2162
- F: (content) => `\x1B[32m${content}\x1B[0m`,
2163
- H: (content) => `\x1B[35m${content}\x1B[0m`,
2164
- L: (content) => `\x1B[35m${content}\x1B[0m`
2161
+ ansiColors: {
2162
+ fix: (content) => `\x1B[32m${content}\x1B[0m`,
2163
+ variable: (content) => `\x1B[35m${content}\x1B[0m`
2165
2164
  }
2166
2165
  };
2167
2166
  var iaReplacer = ($0, $1, $2) => {
@@ -2230,15 +2229,15 @@ var getCompletedOptions = (options) => ({
2230
2229
  });
2231
2230
  var taraskToHtml = (text, taraskOptions, htmlOptions = {}) => {
2232
2231
  const options = getCompletedOptions(taraskOptions);
2233
- const apply = tagApplications.html;
2232
+ const wrapInTag = wrappers.html;
2234
2233
  const isCyrillic = options.abc === ALPHABET.CYRILLIC;
2235
2234
  const { splitted, splittedOrig } = process(text, "&lt;", options);
2236
- addTags(splitted, splittedOrig, isCyrillic, apply.F);
2235
+ highlightChanges(splitted, splittedOrig, isCyrillic, wrapInTag.fix);
2237
2236
  text = join(splitted);
2238
2237
  if (isCyrillic)
2239
2238
  text = replaceG(
2240
2239
  text,
2241
- htmlOptions.g ? apply.H("$&") : ($0) => apply.H(gobj[$0])
2240
+ htmlOptions.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
2242
2241
  );
2243
2242
  return finilize(
2244
2243
  applyNoFix(text).replace(OPTIONAL_WORDS_REGEX, ($0) => {
@@ -2251,23 +2250,23 @@ var taraskToHtml = (text, taraskOptions, htmlOptions = {}) => {
2251
2250
  };
2252
2251
  var tarask = (text, taraskOptions, nonHtmlOptions = {}) => {
2253
2252
  const options = getCompletedOptions(taraskOptions);
2254
- const apply = tagApplications.nonHtml;
2253
+ const wrapInColorOf = wrappers.ansiColors;
2255
2254
  const isCyrillic = options.abc === ALPHABET.CYRILLIC;
2256
2255
  const { splitted, splittedOrig } = process(text, "&lt;", options);
2257
- if (nonHtmlOptions.nodeColors)
2258
- addTags(splitted, splittedOrig, isCyrillic, apply.F);
2256
+ if (nonHtmlOptions.ansiColors)
2257
+ highlightChanges(splitted, splittedOrig, isCyrillic, wrapInColorOf.fix);
2259
2258
  text = join(splitted);
2260
- if (isCyrillic && (nonHtmlOptions.h || nonHtmlOptions.nodeColors))
2259
+ if (isCyrillic && (nonHtmlOptions.h || nonHtmlOptions.ansiColors))
2261
2260
  text = replaceG(
2262
2261
  text,
2263
- nonHtmlOptions.nodeColors ? nonHtmlOptions.h ? ($0) => apply.H(gobj[$0]) : apply.H("$&") : ($0) => gobj[$0]
2262
+ nonHtmlOptions.ansiColors ? nonHtmlOptions.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
2264
2263
  );
2265
2264
  if ("variations" in nonHtmlOptions && nonHtmlOptions.variations !== VARIATION.ALL) {
2266
2265
  const wordIndex = nonHtmlOptions.variations ?? 0;
2267
2266
  const replacer = ($0) => $0.slice(1, -1).split("|")[wordIndex];
2268
2267
  text = text.replace(
2269
2268
  OPTIONAL_WORDS_REGEX,
2270
- nonHtmlOptions.nodeColors ? ($0) => apply.L(replacer($0)) : replacer
2269
+ nonHtmlOptions.ansiColors ? ($0) => wrapInColorOf.variable(replacer($0)) : replacer
2271
2270
  );
2272
2271
  }
2273
2272
  return finilize(applyNoFix(text).replace(/&#40/g, "("), "\n");
@@ -2297,7 +2296,7 @@ var restoreCase = (text, orig) => {
2297
2296
  }
2298
2297
  return text;
2299
2298
  };
2300
- var addTags = (text, orig, isCyrillic, applyF) => {
2299
+ var highlightChanges = (text, orig, isCyrillic, highlight) => {
2301
2300
  for (let i = 0; i < text.length; i++) {
2302
2301
  const word = text[i];
2303
2302
  const oWord = orig[i];
@@ -2311,7 +2310,7 @@ var addTags = (text, orig, isCyrillic, applyF) => {
2311
2310
  const wordLetters = word.split("");
2312
2311
  for (let j = 0; j < wordLetters.length; j++) {
2313
2312
  if (wordH[j] !== oWord[j])
2314
- wordLetters[j] = applyF(wordLetters[j]);
2313
+ wordLetters[j] = highlight(wordLetters[j]);
2315
2314
  }
2316
2315
  text[i] = wordLetters.join("");
2317
2316
  continue;
@@ -2320,10 +2319,10 @@ var addTags = (text, orig, isCyrillic, applyF) => {
2320
2319
  const word1 = word.replace(/ь/g, "");
2321
2320
  switch (oWord) {
2322
2321
  case word1:
2323
- text[i] = word.replace(/ь/g, applyF("ь"));
2322
+ text[i] = word.replace(/ь/g, highlight("ь"));
2324
2323
  continue;
2325
2324
  case word1 + "ь":
2326
- text[i] = word.slice(0, -1).replace(/ь/g, applyF("ь")) + "ь";
2325
+ text[i] = word.slice(0, -1).replace(/ь/g, highlight("ь")) + "ь";
2327
2326
  continue;
2328
2327
  }
2329
2328
  }
@@ -2340,13 +2339,13 @@ var addTags = (text, orig, isCyrillic, applyF) => {
2340
2339
  }
2341
2340
  if (oWord.length < word.length) {
2342
2341
  if (fromOWordEnd === oWordEnd) {
2343
- text[i] = applyF(word);
2342
+ text[i] = highlight(word);
2344
2343
  continue;
2345
2344
  }
2346
2345
  if (fromWordEnd < 0)
2347
2346
  fromWordEnd = 0;
2348
2347
  }
2349
- text[i] = word.slice(0, fromStart) + applyF(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
2348
+ text[i] = word.slice(0, fromStart) + highlight(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
2350
2349
  }
2351
2350
  };
2352
2351
  var toTarask = (text, replaceWithDict2, wordlist2, softers2, afterTarask2) => {
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ type TaraskOptions = {
11
11
  OVERRIDE_toTarask?: ToTarask;
12
12
  };
13
13
  type NonHtmlOptions = {
14
- nodeColors: boolean;
14
+ ansiColors: boolean;
15
15
  h: boolean;
16
16
  variations: Variation;
17
17
  };
package/dist/index.js CHANGED
@@ -2122,15 +2122,14 @@ var lettersUpperCase = {
2122
2122
  [ALPHABET.LATIN]: latinLettersUpperCase,
2123
2123
  [ALPHABET.GREEK]: greekLettersUpperCase
2124
2124
  };
2125
- var tagApplications = {
2125
+ var wrappers = {
2126
2126
  html: {
2127
- F: (content) => `<tarF>${content}</tarF>`,
2128
- H: (content) => `<tarH>${content}</tarH>`
2127
+ fix: (content) => `<tarF>${content}</tarF>`,
2128
+ letterH: (content) => `<tarH>${content}</tarH>`
2129
2129
  },
2130
- nonHtml: {
2131
- F: (content) => `\x1B[32m${content}\x1B[0m`,
2132
- H: (content) => `\x1B[35m${content}\x1B[0m`,
2133
- L: (content) => `\x1B[35m${content}\x1B[0m`
2130
+ ansiColors: {
2131
+ fix: (content) => `\x1B[32m${content}\x1B[0m`,
2132
+ variable: (content) => `\x1B[35m${content}\x1B[0m`
2134
2133
  }
2135
2134
  };
2136
2135
  var iaReplacer = ($0, $1, $2) => {
@@ -2199,15 +2198,15 @@ var getCompletedOptions = (options) => ({
2199
2198
  });
2200
2199
  var taraskToHtml = (text, taraskOptions, htmlOptions = {}) => {
2201
2200
  const options = getCompletedOptions(taraskOptions);
2202
- const apply = tagApplications.html;
2201
+ const wrapInTag = wrappers.html;
2203
2202
  const isCyrillic = options.abc === ALPHABET.CYRILLIC;
2204
2203
  const { splitted, splittedOrig } = process(text, "&lt;", options);
2205
- addTags(splitted, splittedOrig, isCyrillic, apply.F);
2204
+ highlightChanges(splitted, splittedOrig, isCyrillic, wrapInTag.fix);
2206
2205
  text = join(splitted);
2207
2206
  if (isCyrillic)
2208
2207
  text = replaceG(
2209
2208
  text,
2210
- htmlOptions.g ? apply.H("$&") : ($0) => apply.H(gobj[$0])
2209
+ htmlOptions.g ? wrapInTag.letterH("$&") : ($0) => wrapInTag.letterH(gobj[$0])
2211
2210
  );
2212
2211
  return finilize(
2213
2212
  applyNoFix(text).replace(OPTIONAL_WORDS_REGEX, ($0) => {
@@ -2220,23 +2219,23 @@ var taraskToHtml = (text, taraskOptions, htmlOptions = {}) => {
2220
2219
  };
2221
2220
  var tarask = (text, taraskOptions, nonHtmlOptions = {}) => {
2222
2221
  const options = getCompletedOptions(taraskOptions);
2223
- const apply = tagApplications.nonHtml;
2222
+ const wrapInColorOf = wrappers.ansiColors;
2224
2223
  const isCyrillic = options.abc === ALPHABET.CYRILLIC;
2225
2224
  const { splitted, splittedOrig } = process(text, "&lt;", options);
2226
- if (nonHtmlOptions.nodeColors)
2227
- addTags(splitted, splittedOrig, isCyrillic, apply.F);
2225
+ if (nonHtmlOptions.ansiColors)
2226
+ highlightChanges(splitted, splittedOrig, isCyrillic, wrapInColorOf.fix);
2228
2227
  text = join(splitted);
2229
- if (isCyrillic && (nonHtmlOptions.h || nonHtmlOptions.nodeColors))
2228
+ if (isCyrillic && (nonHtmlOptions.h || nonHtmlOptions.ansiColors))
2230
2229
  text = replaceG(
2231
2230
  text,
2232
- nonHtmlOptions.nodeColors ? nonHtmlOptions.h ? ($0) => apply.H(gobj[$0]) : apply.H("$&") : ($0) => gobj[$0]
2231
+ nonHtmlOptions.ansiColors ? nonHtmlOptions.h ? ($0) => wrapInColorOf.variable(gobj[$0]) : wrapInColorOf.variable("$&") : ($0) => gobj[$0]
2233
2232
  );
2234
2233
  if ("variations" in nonHtmlOptions && nonHtmlOptions.variations !== VARIATION.ALL) {
2235
2234
  const wordIndex = nonHtmlOptions.variations ?? 0;
2236
2235
  const replacer = ($0) => $0.slice(1, -1).split("|")[wordIndex];
2237
2236
  text = text.replace(
2238
2237
  OPTIONAL_WORDS_REGEX,
2239
- nonHtmlOptions.nodeColors ? ($0) => apply.L(replacer($0)) : replacer
2238
+ nonHtmlOptions.ansiColors ? ($0) => wrapInColorOf.variable(replacer($0)) : replacer
2240
2239
  );
2241
2240
  }
2242
2241
  return finilize(applyNoFix(text).replace(/&#40/g, "("), "\n");
@@ -2266,7 +2265,7 @@ var restoreCase = (text, orig) => {
2266
2265
  }
2267
2266
  return text;
2268
2267
  };
2269
- var addTags = (text, orig, isCyrillic, applyF) => {
2268
+ var highlightChanges = (text, orig, isCyrillic, highlight) => {
2270
2269
  for (let i = 0; i < text.length; i++) {
2271
2270
  const word = text[i];
2272
2271
  const oWord = orig[i];
@@ -2280,7 +2279,7 @@ var addTags = (text, orig, isCyrillic, applyF) => {
2280
2279
  const wordLetters = word.split("");
2281
2280
  for (let j = 0; j < wordLetters.length; j++) {
2282
2281
  if (wordH[j] !== oWord[j])
2283
- wordLetters[j] = applyF(wordLetters[j]);
2282
+ wordLetters[j] = highlight(wordLetters[j]);
2284
2283
  }
2285
2284
  text[i] = wordLetters.join("");
2286
2285
  continue;
@@ -2289,10 +2288,10 @@ var addTags = (text, orig, isCyrillic, applyF) => {
2289
2288
  const word1 = word.replace(/ь/g, "");
2290
2289
  switch (oWord) {
2291
2290
  case word1:
2292
- text[i] = word.replace(/ь/g, applyF("ь"));
2291
+ text[i] = word.replace(/ь/g, highlight("ь"));
2293
2292
  continue;
2294
2293
  case word1 + "ь":
2295
- text[i] = word.slice(0, -1).replace(/ь/g, applyF("ь")) + "ь";
2294
+ text[i] = word.slice(0, -1).replace(/ь/g, highlight("ь")) + "ь";
2296
2295
  continue;
2297
2296
  }
2298
2297
  }
@@ -2309,13 +2308,13 @@ var addTags = (text, orig, isCyrillic, applyF) => {
2309
2308
  }
2310
2309
  if (oWord.length < word.length) {
2311
2310
  if (fromOWordEnd === oWordEnd) {
2312
- text[i] = applyF(word);
2311
+ text[i] = highlight(word);
2313
2312
  continue;
2314
2313
  }
2315
2314
  if (fromWordEnd < 0)
2316
2315
  fromWordEnd = 0;
2317
2316
  }
2318
- text[i] = word.slice(0, fromStart) + applyF(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
2317
+ text[i] = word.slice(0, fromStart) + highlight(word.slice(fromStart, fromWordEnd + 1)) + word.slice(fromWordEnd + 1);
2319
2318
  }
2320
2319
  };
2321
2320
  var toTarask = (text, replaceWithDict2, wordlist2, softers2, afterTarask2) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "taraskevizer",
3
3
  "author": "GooseOb",
4
4
  "license": "MIT",
5
- "version": "2.1.2",
5
+ "version": "3.0.0-alpha.2",
6
6
  "private": false,
7
7
  "homepage": "https://gooseob.github.io/taraskevizatar/",
8
8
  "main": "dist/index.js",
@@ -13,7 +13,10 @@
13
13
  "tarask": "dist/bin.js"
14
14
  },
15
15
  "files": [
16
- "dist/**/*",
16
+ "dist/index.js",
17
+ "dist/index.cjs",
18
+ "dist/index.d.ts",
19
+ "dist/bin.js",
17
20
  "README.md"
18
21
  ],
19
22
  "scripts": {
@@ -23,7 +26,8 @@
23
26
  "dev:bun": "bun ./test/bun-watch.ts",
24
27
  "dev-bun": "bun test --watch",
25
28
  "test": "esrun --send-code-mode=temporaryFile test",
26
- "prepare": "husky install"
29
+ "prepare": "husky install",
30
+ "typecheck": "tsc --project src/tsconfig.json"
27
31
  },
28
32
  "repository": {
29
33
  "type": "git",