Skip to content

Instantly share code, notes, and snippets.

@tobimori
Created January 2, 2023 11:31
Show Gist options
  • Save tobimori/fd5c26a8d7e7dd130c79f28d4eb26d55 to your computer and use it in GitHub Desktop.
Save tobimori/fd5c26a8d7e7dd130c79f28d4eb26d55 to your computer and use it in GitHub Desktop.

Revisions

  1. tobimori created this gist Jan 2, 2023.
    28 changes: 28 additions & 0 deletions jinglejam-parser.js
    Original 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")
    );