-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
43 lines (28 loc) · 1.05 KB
/
index.ts
File metadata and controls
43 lines (28 loc) · 1.05 KB
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
import { scan } from "./src/scan";
const inputPath = "./bson-input.txt";
const outputPath = "./bson-output.txt";
async function main() {
const inputFile = Bun.file(inputPath);
if (!(await inputFile.exists())) {
throw Error("No input file called 'bson-input.txt'.");
}
const inputContent = await inputFile.text();
let splittedInputContent = inputContent.split("// BREAK");
// 1. CLEAN
splittedInputContent = splittedInputContent.map((input) => input.trim()).filter((input) => input !== "");
// 2. Parse and Write
const outputFile = Bun.file(outputPath);
await Bun.write(outputPath, ""); // Reset
const writer = await outputFile.writer();
splittedInputContent.forEach((input, index) => {
// Parse
const parsedObject = JSON.parse(input);
const output = scan(parsedObject);
// Write
writer.write(output);
// If not last item, separate with a // BREAK
if (index !== splittedInputContent.length - 1) writer.write("\n\n// BREAK\n\n");
});
console.log(`\n\n🙌 Done Writing to ${outputPath}.`);
}
main();