-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbulk-txt-convert.js
54 lines (47 loc) · 1.37 KB
/
bulk-txt-convert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
# example node.js application. Run the following command
node main.js cosmos1r5qkmvn9hnv0pugejr73639w07d2mughnm7qxa juno
*/
var converter = require("./convert-bech32-address.js");
// console.log(converter.lookup("osmo1p7kae67pvenee4c03ajg735kg5zxzp6ww4aarn", "test"));
// process.exit(0);
const fs = require("fs");
const from = "osmo";
const to = "stars";
// Function to process each line's string
function processLine(line, idx) {
if (line.indexOf(from) == 0) {
try {
return converter.lookup(line.replace(/[^\x20-\x7E]/g, ""), to);
} catch (error) {
console.log();
console.log("error parsing line:");
console.log(line);
console.log(error);
console.log();
}
}
}
// Read the input file
fs.readFile("input.txt", "utf8", (err, data) => {
if (err) {
console.error("Error reading the file:", err);
return;
}
// Split the data into lines
const lines = data.split("\n");
// Process each line
const processedLines = lines
.map(processLine)
.filter((value) => value !== undefined);
// Join the processed lines back into a single string
const output = processedLines.join("\n");
// Write the output to a new file
fs.writeFile("output.txt", output, "utf8", (err) => {
if (err) {
console.error("Error writing the file:", err);
return;
}
console.log("File successfully written!");
});
});