mirror of
https://github.com/rjNemo/deno_hello
synced 2026-06-06 10:06:40 +00:00
33 lines
856 B
TypeScript
33 lines
856 B
TypeScript
import { readLines } from "./deps.ts";
|
|
import { ID, sayHello, sayRandomHello, ValidationError } from "./src/index.ts";
|
|
|
|
const start = async () => {
|
|
console.log("Hello, World! (International version)\n");
|
|
console.log(
|
|
"🌍 Type a number (between 1 and 78), or leave blank for random language. Type 'quit' to leave.",
|
|
);
|
|
console.log("👉 ");
|
|
|
|
for await (const line of readLines(Deno.stdin)) {
|
|
const value = line.trim();
|
|
|
|
if (value === "") {
|
|
console.log(sayRandomHello());
|
|
} else if (value === "quit") {
|
|
return;
|
|
} else {
|
|
try {
|
|
const id = new ID(parseInt(value, 10));
|
|
console.log(sayHello(id));
|
|
} catch (error) {
|
|
if (error instanceof ValidationError) {
|
|
console.error(error.message);
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
await start();
|