pf-sowpods
Scrabble's SOWPODS dictionary - The SOWPODS dictionary with related functionality.
Examples
// Require the moduleconst sowpods = sowpods62 // 'ABAPICAL'sowpodslength // 267751 // A trie structure is included, toosowpodstrieHAPHTARA_ // true // Verify wordssowpods // truesowpods // false // Find anagrams out of letterssowpods// [ 'AB', 'ABO', 'ABORT', ..., 'YOK', 'YORK', 'ZO' ] // Get similarly spelled wordssowpods// [ 'BILLOW', 'BILLOWS', 'MELLOWY', ..., 'WILLOWS', 'WILLOWY', 'YELLOWY' ]
API
You can require the whole module, or just pieces of it.
// Everything // Just the array of SOWPODS words // The dictionary and a few core features
Dependency graph (left to right):
index
├─ sowpods ──────┐
│ ├─ random ───┤
│ ├─ verify │
│ │ └───┐ │
│ └───── trie ─┴─ dictionary
├─ anagram ─┤
├─ suggest ─┘
└─ (define)
├─ cheerio
└─ superagent
sowpods
({Array}): An alphabetized array of the SOWPODS dictionary. All letters are capitalized.
sowpods// [ 'AAHED', 'AALII', ..., 'ZYMES', 'ZYMIC' ]
sowpods.trie
({Object}): A trie structure of the words where the nodes are single capitalized characters. The node <path>._ === true
indicates an End-of-Word. Lodash's _.get()
function may be useful here.
const _ = _// undefined_// {// C: { _: true },// S: { _: true,// E: { S: { _: true } }// }// }
sowpods.verify(word)
Arguments
word
(String): A word to check (case-insensitive).
Returns
- (Boolean):
true
if the word is in SOWPODS,false
otherwise.
This function crawls the trie to determine if the word exists.
sowpods // truesowpods // false
sowpods.anagram(chars)
Arguments
chars
(String): The letters to anagram (case-insensitive).
Returns
- (Array): All possible single word anagrams sorted in alphabetical order.
Characters in chars
which are not alphabetic, are considered to be wildcards. This function crawls the trie as long as the next node is available in the letters provided.
sowpods// [ 'BOOTERY', 'BARYTE', ..., 'YU', 'ZO' ]
sowpods.random([count])
Arguments
[count]
(number): The number of random words to return.
Returns
- (String|Array): Some random words.
If count
is undefined
, it returns a single string. Otherwise it returns an array of length count
of random words.
sowpods // 'PICANINNIES'sowpods // [ 'IGLU' ]sowpods // [ 'REFRESHENS', 'EPILOGUIZING' ]
sowpods.suggest(string, [distance = 2])
Arguments
string
(String): The string to query (case-insensitive).[distance = 2]
(number): The maximum distance to search for.
Returns
- (Array): All SOWPODS words whose Levenshtein distance from
string
is no more thandistance
.
sowpods// [ 'BILLOW', 'BILLOWS', 'MELLOWY', ..., 'WILLOWS', 'WILLOWY', 'YELLOWY' ]sowpods// [ 'BATFISH', 'CATFISH', 'CATTISH', 'RATFISH' ]