Created
January 2, 2023 11:31
-
-
Save tobimori/fd5c26a8d7e7dd130c79f28d4eb26d55 to your computer and use it in GitHub Desktop.
Revisions
-
tobimori created this gist
Jan 2, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ 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") );