diff --git a/README.md b/README.md index 46c32b7..bb38d29 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,9 @@ for (let i = 0; i < searches.length; i += 1) { // There was a match. Print match info if (result) { switch (result.matchType) { - case PERFECT_MATCH: - case PURE_PREFIX: - case PREFIX: + case "PERFECT_MATCH": + case "PURE_PREFIX": + case "PREFIX": console.log(`${searches[i]}: Present in trie`); } } diff --git a/src/greet.test.ts b/src/greet.test.ts deleted file mode 100644 index f729115..0000000 --- a/src/greet.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { describe, expect, it, vi } from "vitest"; - -import { greet } from "./greet.js"; - -const message = "Yay, testing!"; - -describe("greet", () => { - it("logs to the console once when message is provided as a string", () => { - const logger = vi.spyOn(console, "log").mockImplementation(() => undefined); - - greet(message); - - expect(logger).toHaveBeenCalledWith(message); - expect(logger).toHaveBeenCalledTimes(1); - }); - - it("logs to the console once when message is provided as an object", () => { - const logger = vi.spyOn(console, "log").mockImplementation(() => undefined); - - greet({ message }); - - expect(logger).toHaveBeenCalledWith(message); - expect(logger).toHaveBeenCalledTimes(1); - }); - - it("logs once when times is not provided in an object", () => { - const logger = vi.fn(); - - greet({ logger, message }); - - expect(logger).toHaveBeenCalledWith(message); - expect(logger).toHaveBeenCalledTimes(1); - }); - - it("logs a specified number of times when times is provided", () => { - const logger = vi.fn(); - const times = 7; - - greet({ logger, message, times }); - - expect(logger).toHaveBeenCalledWith(message); - expect(logger).toHaveBeenCalledTimes(7); - }); -}); diff --git a/src/greet.ts b/src/greet.ts deleted file mode 100644 index a0d3b4c..0000000 --- a/src/greet.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { GreetOptions } from "./types.js"; - -export function greet(options: GreetOptions | string) { - const { - logger = console.log.bind(console), - message, - times = 1, - } = typeof options === "string" ? { message: options } : options; - - for (let i = 0; i < times; i += 1) { - logger(message); - } -} diff --git a/src/index.ts b/src/index.ts index a39b40f..a0c4ebf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1 @@ -export * from "./greet.js"; export * from "./types.js"; diff --git a/src/types.ts b/src/types.ts index 4f16ae3..b36b9d0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,28 @@ -export interface GreetOptions { - logger?: (message: string) => void; - message: string; - times?: number; -} +/** + * Represents a search for a string that + * successfully ends at a leaf node. + */ +export type PERFECT_MATCH = { + matchType: "PERFECT_MATCH"; +}; + +/** + * Represents a search for a string that + * successfully ends at a non-leaf node. + */ +export type PURE_PREFIX = { + matchType: "PURE_PREFIX"; +}; +/** + * Represents a search for a string that + * is successful. Not strictly necessary + * but useful as the disjunction of + * PERFECT_MATCH and PURE_PREFIX. + */ +export type PREFIX = { + matchType: "PREFIX"; +}; +/** + * Union type of all possible values of Trie SearchResult + */ +export type SearchResult = PERFECT_MATCH | PURE_PREFIX | PREFIX | undefined;