Package Exports
- pf-sowpods
- pf-sowpods/src/dictionary
- pf-sowpods/src/sowpods
- pf-sowpods/src/trie
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pf-sowpods) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pf-sowpods
Scrabble's SOWPODS dictionary - The SOWPODS dictionary with related functionality.
Examples
// Require the module
const sowpods = require('pf-sowpods')
sowpods[62] // 'ABAPICAL'
sowpods.length // 267751
// A trie structure is included, too
sowpods.trie.H.A.P.H.T.A.R.A._ // true
// Verify words
sowpods.verify('banana') // true
sowpods.verify('asdfjkl') // false
// Find anagrams out of letters
sowpods.anagram('BCKRTO*')
// [ 'AB', 'ABO', 'ABORT', ..., 'YOK', 'YORK', 'ZO' ]
// Get similarly spelled words
sowpods.suggest('pillowy')
// [ 'BILLOW', 'BILLOWS', 'MELLOWY', ..., 'WILLOWS', 'WILLOWY', 'YELLOWY' ]API
You can require the whole module, or just pieces of it.
require('pf-sowpods') // Everything
require('pf-sowpods/src/dictionary') // Just the array of SOWPODS words
require('pf-sowpods/src/sowpods') // The dictionary and a few core featuresDependency graph (left to right):
index
├─ sowpods ──────┐
│ ├─ random ───┤
│ ├─ verify │
│ │ └───┐ │
│ └───── trie ─┴─ dictionary
├─ anagram ─┤
├─ suggest ─┘
└─ (define)
├─ cheerio
└─ superagentsowpods
({Array}): An alphabetized array of the SOWPODS dictionary. All letters are capitalized.
sowpods.filter(word => word.length === 5)
// [ '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 _ = require('lodash')
_.get(sowpods.trie, 'A.B.C.D.E.F')
// undefined
_.get(sowpods.trie, 'DERMI'.split(''))
// {
// C: { _: true },
// S: { _: true,
// E: { S: { _: true } }
// }
// }sowpods.verify(word)
Arguments
word(String): A word to check (case-insensitive).
Returns
- (Boolean):
trueif the word is in SOWPODS,falseotherwise.
This function crawls the trie to determine if the word exists.
sowpods.verify('banana') // true
sowpods.verify('asdfjkl') // falsesowpods.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.anagram('EYBTOR*')
// [ '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.random() // 'PICANINNIES'
sowpods.random(1) // [ 'IGLU' ]
sowpods.random(2) // [ '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
stringis no more thandistance.
sowpods.suggest('pillowy')
// [ 'BILLOW', 'BILLOWS', 'MELLOWY', ..., 'WILLOWS', 'WILLOWY', 'YELLOWY' ]
sowpods.suggest('catfish', 1)
// [ 'BATFISH', 'CATFISH', 'CATTISH', 'RATFISH' ]