Word Puzzle Pack

A Flutter package for English words with utilities for word games and puzzles.

Features

  • Word Utilities: Anagram detection, palindrome checking, word scoring, letter frequency analysis
  • Word Validation: Check if words are valid English words, contain only letters, vowel/consonant counting
  • Word Lists: Curated lists of 1200+ common English words
  • Dictionary: Complete dictionary with meanings, examples, synonyms, and acronyms
  • Puzzle Tools: Find words by length, search for anagrams, and more

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  word_puzzle_pack: ^0.1.0

Then run:

flutter pub get

Usage

import 'package:word_puzzle_pack/word_puzzle_pack.dart';

// Load dictionary data
DictionaryData.loadDefaultEntries();

// Dictionary lookup
DictionaryEntry? entry = Dictionary.lookup('happy');
print(entry?.meaning); // "Feeling or showing pleasure or contentment"
print(entry?.example); // "She was happy to see her friends."
print(entry?.synonyms); // ["joyful", "cheerful", "glad", "pleased"]

// Search dictionary
List<DictionaryEntry> synonyms = Dictionary.findSynonyms('happy');
List<DictionaryEntry> acronyms = Dictionary.findAcronyms();
List<DictionaryEntry> wordsWithMeaning = Dictionary.searchByMeaning('pleasure');

// Word utilities
bool isAnagram = WordUtils.isAnagram('listen', 'silent'); // true
bool isPalindrome = WordUtils.isPalindrome('racecar'); // true
int score = WordUtils.getWordScore('quiz'); // 22

// Word validation
bool isValid = WordValidator.isValidEnglishWord('hello'); // true
int vowelCount = WordValidator.countVowels('hello'); // 2

// Work with word lists (1200+ words)
List<String> allWords = WordLists.getAllWords();
List<String> threeLetterWords = WordLists.getWordsByLength(3);

// Advanced word filtering with count parameter
List<String> wordsInRange = WordLists.getWordsByLengthRange(3, 6, count: 5);
List<String> randomWords = WordLists.getRandomWords(count: 10);
List<String> longWords = WordLists.getWordsByMinLength(8, count: 3);
List<String> shortWords = WordLists.getWordsByMaxLength(4, count: 5);

// Pattern-based filtering
List<String> wordsStartingWithTh = WordLists.getWordsStartingWith('th', count: 3);
List<String> wordsEndingWithIng = WordLists.getWordsEndingWith('ing', count: 5);
List<String> wordsContainingOo = WordLists.getWordsContaining('oo', count: 4);

// Find anagrams from word list
List<String> anagrams = WordUtils.findAnagrams('evil', WordLists.getAllWords());

API Reference

WordUtils

  • isAnagram(String word1, String word2) - Check if two words are anagrams
  • isPalindrome(String word) - Check if a word is a palindrome
  • getWordScore(String word) - Calculate Scrabble-like score for a word
  • reverseWord(String word) - Reverse a word
  • getLetterFrequency(String word) - Get frequency map of letters in a word
  • findAnagrams(String word, List<String> wordList) - Find anagrams in a word list
  • findWordsOfLength(int length, List<String> wordList) - Find words of specific length

WordValidator

  • isValidEnglishWord(String word) - Check if word contains only letters
  • containsOnlyLetters(String word) - Check if word contains only letters
  • countVowels(String word) - Count vowels in a word
  • countConsonants(String word) - Count consonants in a word
  • hasMinimumLength(String word, int minLength) - Check minimum length
  • hasMaximumLength(String word, int maxLength) - Check maximum length

WordLists

  • getAllWords() - Get all available words (1200+ words)
  • getWordsByLength(int length) - Get words of specific length
  • getWordsByLengthRange(int minLength, int maxLength, {int count = 1}) - Get words within length range
  • getRandomWords({int count = 1}) - Get random words
  • getWordsByMinLength(int minLength, {int count = 1}) - Get words with minimum length
  • getWordsByMaxLength(int maxLength, {int count = 1}) - Get words with maximum length
  • getWordsStartingWith(String prefix, {int count = 1}) - Get words starting with prefix
  • getWordsEndingWith(String suffix, {int count = 1}) - Get words ending with suffix
  • getWordsContaining(String substring, {int count = 1}) - Get words containing substring
  • commonWords - List of common English words

Dictionary

  • lookup(String word) - Look up a word in the dictionary
  • contains(String word) - Check if word exists in dictionary
  • getAllWords() - Get all dictionary words
  • findByPrefix(String prefix) - Find words starting with prefix
  • findBySuffix(String suffix) - Find words ending with suffix
  • findByLength(int length) - Find words of specific length
  • searchByMeaning(String term) - Search by meaning content
  • findSynonyms(String word) - Find synonyms for a word
  • findAcronyms() - Get all acronym entries
  • findByAcronym(String acronym) - Find words by acronym expansion
  • addEntry(DictionaryEntry entry) - Add custom dictionary entry
  • getRandomEntries(int count) - Get random dictionary entries

DictionaryEntry

  • word - The word itself
  • meaning - Definition of the word
  • example - Example sentence using the word
  • synonyms - List of synonyms
  • acronym - Acronym expansion (optional)
  • toMap() - Convert to Map
  • fromMap(Map map) - Create from Map

Example

Check out the example/main.dart file for a complete Flutter app demonstrating the package features.

Testing

Run the tests with:

flutter test

License

MIT License

Libraries

word_puzzle_pack