23 lines
781 B
TypeScript
Executable file
23 lines
781 B
TypeScript
Executable file
#!/usr/bin/env -S deno run --allow-read --allow-write
|
|
|
|
import { join } from "https://deno.land/std@0.224.0/path/join.ts";
|
|
import { dirname } from "https://deno.land/std@0.224.0/path/dirname.ts";
|
|
|
|
async function main() {
|
|
const script_path = new URL(import.meta.url).pathname;
|
|
const data_dir = dirname(script_path);
|
|
|
|
for await (const entry of Deno.readDir(data_dir)) {
|
|
if (!entry.isFile) continue;
|
|
if (!entry.name.endsWith("txt")) continue;
|
|
|
|
const content = await Deno.readTextFile(join(data_dir, entry.name));
|
|
const lines = content.split("\n").map((l) => l.trim());
|
|
|
|
const json_path = join(data_dir, entry.name + ".json");
|
|
const serialized = JSON.stringify(lines, null, 2);
|
|
await Deno.writeTextFile(json_path, serialized);
|
|
}
|
|
}
|
|
|
|
if (import.meta.main) await main();
|