if (input === null) {
throw new Error("No seed phrase entered.");
}
- const words = input.split(/\s/g).map((w) => w.trim());
+ const words = input
+ .trim()
+ .replaceAll(/\s+/g, " ")
+ .split(" ").map((w) => w.trim());
if (words.length % 2 === 1) {
throw new Error("Seed phrase length must be even.");
}
assertThrows(() => parseInput("test test test"));
});
+Deno.test("parseInput collapses whitespace correctly", () => {
+ const words = parseInput(
+ " \n\ntest \n\ntest test test test test\ntest\n \n\ntest \n\n",
+ );
+ assertEquals(words.length, 8);
+});
+
Deno.test("parseInput parses 12 word seed phrase", () => {
const words = parseInput(
"test test test test test test test test test test test junk",