Generate Anagrams
Generates unique anagrams of a given word, with support for limits and dictionary filtering.
generateAnagrams
The generateAnagrams function generates unique anagrams of a given word. It returns an array of lowercase anagrams, with the original word (lowercased) as the first element.
Function Signature
function generateAnagrams(word: string, options?: AnagramOptions): Lowercase<string>[]Parameters
word(string): The word to generate anagrams for.options(AnagramOptions, optional): Configuration options:limit(number | 'all'): Maximum number of anagrams to generate. Defaults to100.dictionary(string[] | false): If provided, only anagrams present in this list are returned (case-insensitive). Defaults tofalse.
Types
AnagramOptions
interface AnagramOptions {
limit?: number | 'all';
dictionary?: false | string[];
}Return Value
Lowercase<string>[]: An array of unique, lowercase anagrams. The original word (lowercased) is always the first element.
Example Usage
playground.ts
Limitations
- Dictionary-based filtering only includes exact matches; partial matches are ignored.
- For built-in dictionary-based anagrams, use the dedicated package
nhb-anagram-generator, which specifically returns valid words (optional all words) using a built-in json dictionary.
Notes
- Single character words return a single-item array containing the lowercase character.
- An empty string returns an empty array.
- For a pre-built dictionary of English words, you can fetch
english-words.jsonand pass its array format tooptions.dictionary.import dict from './english-words.json'; // match your path const words = (dict as { words: string[] }).words; // it contains 370,100 English words generateAnagrams('banana', { dictionary: words }); - Anagram generation scales factorially with word length; use
limitwhen dealing with longer words to avoid freezing the execution thread.
Last updated: Tue, Jun 16, 2026 05:47:40AM (UTC)
