Skip to content

Instantly share code, notes, and snippets.

@tobimori
Created January 2, 2023 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobimori/fd5c26a8d7e7dd130c79f28d4eb26d55 to your computer and use it in GitHub Desktop.
Save tobimori/fd5c26a8d7e7dd130c79f28d4eb26d55 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const file = fs.readFileSync(__dirname + "/keys.txt").toString();
const games = file.split("\n\n").map((game) => game.split("\n"));
const toObject = games.map((game) => {
const [name, year] = game[0].split(/ \((\d+)\)/gm);
return {
name,
year,
description: game[1],
key: game[2].split(": ")[1].trim(),
};
});
console.log(toObject);
fs.writeFileSync(__dirname + "/json.json", JSON.stringify(toObject));
fs.writeFileSync(
__dirname + "/csv.csv",
"name,year,description,key\n" +
toObject.map((o) => Object.values(o).join(",")).join("\n")
);
fs.writeFileSync(
__dirname + "/justkeys.txt",
toObject.map((o) => o.key).join("\n")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment