diff --git a/src/index.ts b/src/index.ts index e928749..e465966 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,19 +1,27 @@ -import { getLocaleById, localesSize } from "./repository/locales.ts"; +import { readLines } from "https://deno.land/std@0.87.0/io/bufio.ts"; import { ID } from "./types/id.ts"; +import { sayHello, sayRandomHello } from "./usecases/hello.ts"; -/** - * Display the iconic Hello, World in a random locale - */ -export const sayRandomHello = () => { - const id = Math.ceil(Math.random() * localesSize); - const val = new ID(id); - return sayHello(val); +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)) { + switch (line.trim()) { + case "": { + console.log(sayRandomHello()); + break; + } + default: { + const id = new ID(parseInt(line.trim(), 10)); + console.log(sayHello(id)); + } + } + break; + } }; -/** - * Display the iconic Hello, World in a locale identified by id - * @param id Unique identifier - */ -export const sayHello = (id: ID): string => { - return getLocaleById(id.value); -}; +await start(); diff --git a/src/repository/locales.data.ts b/src/repositories/locales.data.ts similarity index 100% rename from src/repository/locales.data.ts rename to src/repositories/locales.data.ts diff --git a/src/repository/locales.test.ts b/src/repositories/locales.test.ts similarity index 100% rename from src/repository/locales.test.ts rename to src/repositories/locales.test.ts diff --git a/src/repository/locales.ts b/src/repositories/locales.ts similarity index 100% rename from src/repository/locales.ts rename to src/repositories/locales.ts diff --git a/src/types/id.test.ts b/src/types/id.test.ts index 3346758..2a0953f 100644 --- a/src/types/id.test.ts +++ b/src/types/id.test.ts @@ -1,5 +1,5 @@ import { assertThrows } from "https://deno.land/std@0.87.0/testing/asserts.ts"; -import { localesSize } from "../repository/locales.ts"; +import { localesSize } from "../repositories/locales.ts"; import { ID } from "./id.ts"; import { ValidationError } from "../errors/exceptions.ts"; diff --git a/src/types/id.ts b/src/types/id.ts index f4f84be..1a1335e 100644 --- a/src/types/id.ts +++ b/src/types/id.ts @@ -1,4 +1,4 @@ -import { localesSize } from "../repository/locales.ts"; +import { localesSize } from "../repositories/locales.ts"; import { ValidationError } from "../errors/exceptions.ts"; /** diff --git a/src/index.test.ts b/src/usecases/hello.test.ts similarity index 87% rename from src/index.test.ts rename to src/usecases/hello.test.ts index 5c7f2dd..859f468 100644 --- a/src/index.test.ts +++ b/src/usecases/hello.test.ts @@ -1,6 +1,6 @@ import { assertStrictEquals } from "https://deno.land/std@0.87.0/testing/asserts.ts"; -import { sayHello, sayRandomHello } from "./index.ts"; -import { ID } from "./types/id.ts"; +import { sayHello, sayRandomHello } from "./hello.ts"; +import { ID } from "../types/id.ts"; Deno.test("Random Hello", () => { const result = sayRandomHello(); diff --git a/src/usecases/hello.ts b/src/usecases/hello.ts new file mode 100644 index 0000000..5e99b22 --- /dev/null +++ b/src/usecases/hello.ts @@ -0,0 +1,19 @@ +import { getLocaleById, localesSize } from "../repositories/locales.ts"; +import { ID } from "../types/id.ts"; + +/** + * Display the iconic Hello, World in a random locale + */ +export const sayRandomHello = () => { + const id = Math.ceil(Math.random() * localesSize); + const val = new ID(id); + return sayHello(val); +}; + +/** + * Display the iconic Hello, World in a locale identified by id + * @param id Unique identifier + */ +export const sayHello = (id: ID): string => { + return getLocaleById(id.value); +};