Skip to content

pillowfication/pf-sowpods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pf-sowpods

Scrabble’s SOWPODS dictionary - The SOWPODS dictionary with related functionality.

http://pf-n.co/github/pf-sowpods

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 features

Dependency graph (left to right):

index
 ├─ sowpods ──────┐
 │   ├─ random ───┤
 │   ├─ verify    │
 │   │   └───┐    │
 │   └───── trie ─┴─ dictionary
 ├─ anagram ─┤
 └─ suggest ─┘

sowpods

({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

  1. 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.verify('banana')  // true
sowpods.verify('asdfjkl') // false

sowpods.anagram(chars)

Arguments

  1. 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

  1. [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

  1. string (String): The string to query (case-insensitive).
  2. [distance = 2] (Number): The maximum distance to search for.

Returns

sowpods.suggest('pillowy')
// [ 'BILLOW', 'BILLOWS', 'MELLOWY', ..., 'WILLOWS', 'WILLOWY', 'YELLOWY' ]
sowpods.suggest('catfish', 1)
// [ 'BATFISH', 'CATFISH', 'CATTISH', 'RATFISH' ]

About

Scrabble’s SOWPODS dictionary.

Resources

Stars

Watchers

Forks

Packages

No packages published