pdf-tools/util/asciiArt.ts

30 lines
826 B
TypeScript

import { log } from "./logfile.ts";
import { join } from "@std/path";
export async function getAsciiArt(art: string) {
try {
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
join(import.meta.dirname || "", "../asciiart.txt");
let artFileText: string;
if (artFilePath?.startsWith("http")) {
artFileText = await fetch(artFilePath).then((res) => res.text());
} else {
artFileText = await Deno.readTextFile(
artFilePath,
);
}
const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g;
let result = parserRX.exec(artFileText);
while (result !== null) {
const [_, name, artText] = result;
if (name === art) return artText;
result = parserRX.exec(artFileText);
}
} catch (e) {
console.log(e);
alert();
}
return art;
}