diff --git a/src/lib/dict.ts b/src/lib/dict.ts index 539e0c4..50603a6 100644 --- a/src/lib/dict.ts +++ b/src/lib/dict.ts @@ -9,10 +9,9 @@ export class Dict { this.letters = new Set([...words.values()].map((w) => w.split("")).flat()); } - static async from_file(path: string, length: number) { + static from_lines(lines: string[], length: number) { const words = new Set(); - const content = await Deno.readTextFile(path); - for (const word of content.split("\n")) { + for (const word of lines) { const word_ = word.trim().toLowerCase(); if (word_.length !== length) continue; if (contains_any(word_, [" ", "-", "."])) continue; @@ -21,8 +20,13 @@ export class Dict { return new Dict(words, length); } + static async from_text_file(path: string, length: number) { + const content = await Deno.readTextFile(path); + return Dict.from_lines(content.split("\n"), length); + } + [Symbol.for("Deno.customInspect")]() { - return `Dict { ${this.words.size} words }`; + return `Dict { ${this.words.size} words, ${this.letters.size} letters }`; } }