1
Fork 0

Make pretty-printing JSON a separate function.

This commit is contained in:
Bauke 2023-02-22 11:31:26 +01:00
parent be02d685e5
commit efae71195d
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,8 @@
import { Command } from "https://deno.land/x/cliffy@v0.25.5/command/mod.ts";
import * as prompt from "https://deno.land/x/cliffy@v0.25.5/prompt/mod.ts";
import { stringifyJsonPretty } from "./utilities.ts";
const CaveComplexity = [1, 2, 3] as const;
const CaveLength = [1, 2, 3] as const;
const HazardLevel = [1, 2, 3, 4, 5] as const;
@ -506,14 +508,14 @@ async function main(): Promise<void> {
};
if (options.testing) {
console.log(newMission);
console.log(stringifyJsonPretty(newMission));
return;
}
dataMissions.push(newMission);
await Deno.writeTextFile(
options.dataFile,
JSON.stringify(dataMissions, null, 2) + "\n",
stringifyJsonPretty(dataMissions) + "\n",
);
}
}

View File

@ -1,6 +1,10 @@
import { parse } from "https://deno.land/std@0.167.0/encoding/toml.ts";
import { TextDecoder } from "https://deno.land/std@0.167.0/node/util.ts";
export function stringifyJsonPretty(input: unknown): string {
return JSON.stringify(input, null, 2);
}
export async function runAndReturnStdout(
options: Deno.RunOptions,
): Promise<string> {