UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

26 lines (25 loc) 1.09 kB
import type { AnagramOptions } from './types'; /** * * Generates unique anagrams of a given word. Optionally looks up valid anagrams inside a provided dictionary. * * @param word The word from which to generate anagrams. Converted to lowercase internally. * * @param options Controls the output limit and optional dictionary lookup. * * @returns A list of unique, lowercase anagrams. The original word (lowercased) is always included as the first element. * * @remarks * - When a dictionary is provided, only anagrams found inside that dictionary are returned. * - The dictionary is cached internally (with converting to lowercase) using a `WeakMap`, allowing garbage collection of unused inputs. * - Repeated letters are handled efficiently using a per-level set to avoid duplicate permutations. * * @example * generateAnagrams("east", { limit: 10 }); * * @example * generateAnagrams("tone", { * dictionary: ["tone", "note", "one"], * limit: "all" * }); */ export declare function generateAnagrams(word: string, options?: AnagramOptions): Lowercase<string>[];