taraskevizer 6.1.2 → 6.1.4
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 +26 -12
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import readline from "readline/promises";
|
|
3
|
-
import { readFileSync } from "fs";
|
|
4
2
|
import { ALPHABET, REPLACE_J, Taraskevizer, VARIATION } from "./index.js";
|
|
5
3
|
const prefix = "\x1B[34m[taraskevizer]\x1B[0m ";
|
|
6
4
|
const printWithPrefix = (msg) => {
|
|
@@ -9,7 +7,7 @@ const printWithPrefix = (msg) => {
|
|
|
9
7
|
process.argv.splice(0, 2);
|
|
10
8
|
const checkForOptions = (options) => process.argv[0] && options.includes(process.argv[0].toLowerCase());
|
|
11
9
|
if (checkForOptions(["-v", "--version"])) {
|
|
12
|
-
printWithPrefix("6.1.
|
|
10
|
+
printWithPrefix("6.1.4");
|
|
13
11
|
process.exit(0);
|
|
14
12
|
}
|
|
15
13
|
if (checkForOptions(["-h", "--help"])) {
|
|
@@ -164,20 +162,36 @@ while (currOption = process.argv.shift()) {
|
|
|
164
162
|
let text = "";
|
|
165
163
|
if (process.argv.length) {
|
|
166
164
|
text = process.argv.join(" ");
|
|
167
|
-
} else if (process.stdin.isTTY) {
|
|
168
|
-
text = await readline.createInterface({
|
|
169
|
-
input: process.stdin,
|
|
170
|
-
output: process.stdout
|
|
171
|
-
}).question(prefix + "Enter the text:\n");
|
|
172
165
|
} else {
|
|
173
|
-
|
|
166
|
+
const chunks = [];
|
|
167
|
+
let length = 0;
|
|
168
|
+
if (process.stdin.isTTY) {
|
|
169
|
+
printWithPrefix("Enter the text");
|
|
170
|
+
for await (const chunk of process.stdin) {
|
|
171
|
+
chunks.push(chunk);
|
|
172
|
+
length += chunk.length;
|
|
173
|
+
if (chunk.includes("\n"))
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
for await (const chunk of process.stdin) {
|
|
178
|
+
chunks.push(chunk);
|
|
179
|
+
length += chunk.length;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
text = Buffer.concat(chunks, length).toString();
|
|
174
183
|
}
|
|
175
184
|
const taraskevizer = new Taraskevizer({ general, html, nonHtml });
|
|
176
|
-
process.stdout.write(
|
|
185
|
+
if (process.stdout.write(
|
|
177
186
|
{
|
|
178
187
|
nonHtml: taraskevizer.convert,
|
|
179
188
|
html: taraskevizer.convertToHtml,
|
|
180
189
|
alphabetOnly: taraskevizer.convertAlphabetOnly
|
|
181
190
|
}[mode].apply(taraskevizer, [text]) + "\n"
|
|
182
|
-
)
|
|
183
|
-
process.exit(0);
|
|
191
|
+
)) {
|
|
192
|
+
process.exit(0);
|
|
193
|
+
} else {
|
|
194
|
+
process.stdout.once("drain", () => {
|
|
195
|
+
process.exit(0);
|
|
196
|
+
});
|
|
197
|
+
}
|