Skip to content

Instantly share code, notes, and snippets.

@iamjohnmills
Last active May 3, 2025 22:34
Show Gist options
  • Save iamjohnmills/c7660db57e871f0933a67a2e5585960f to your computer and use it in GitHub Desktop.
Save iamjohnmills/c7660db57e871f0933a67a2e5585960f to your computer and use it in GitHub Desktop.
Get a dictionary on Macos

Gist Overview: Create a comprehensive list of English words with MacOS.


Copy /usr/share/dict/words as words.txt

(async () => {
  const fs = require('fs');
  const readline = require('readline');
  const file_stream = fs.createReadStream('words.txt');
  const readline_interface = readline.createInterface({ input: file_stream, crlfDelay: Infinity });
  const dictionary_path = 'dictionary.txt';
  fs.unlinkSync(dictionary_path);
  for await (const word of readline_interface) {
    const valid_length = word.length > 2; // remove 2-letter words
    const valid_case = !/^[A-Z]/.test(word); // remove proper names and places
    const is_valid = [valid_length,valid_case].every(rule => !!rule);
    if(!is_valid) continue;
    fs.appendFileSync(dictionary_path, `${word}\n`);
    console.log(word)
  }
  console.log('Finished...')
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment