From 6484ccb42c1e11026b83b57b85e74a3024a84c48 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 5 Jul 2022 19:16:25 -0700 Subject: [PATCH] Run autoformatter --- README.md | 43 ++++++++++++++++++++++++++++++++----------- main.ts | 16 ++++++++-------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1591739..4960ffe 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,51 @@ # random-word-generator -A [Deno](https://deno.land/) CLI which returns a string of random words from a given word list. +A [Deno](https://deno.land/) CLI which returns a string of random words from a +given word list. ``` > deno run --allow-read ./main.ts > cheeking-signs-riches ``` -Similar to [unique-names-generator](https://github.com/andreasonny83/unique-names-generator). +Similar to +[unique-names-generator](https://github.com/andreasonny83/unique-names-generator). ## Flags -- `--words`: path to a word list file where each word is delimited by a newline. Default value is `./words/xkcd.txt`. -- `--separator`: a character to insert in between each word in the output. If multiple characters are provided, a random character is picked for each separator. Default value is `-`. + +- `--words`: path to a word list file where each word is delimited by a newline. + Default value is `./words/xkcd.txt`. +- `--separator`: a character to insert in between each word in the output. If + multiple characters are provided, a random character is picked for each + separator. Default value is `-`. - `--length`: the number of words to output. Default value is `3`. ## Included word lists -- `xkcd.txt`: the dictionary for [XKCD](https://xkcd.com/)'s [Simple Writer](https://xkcd.com/simplewriter/), [Up Goer Five](https://xkcd.com/1133/), and [Thing Explainer](https://blog.xkcd.com/2015/05/13/new-book-thing-explainer/), minus contractions. -- `google-10000.txt`: the top 10,000 most common English words from [Google's Trillion Word Corpus](https://books.google.com/ngrams/info), minus swear words. -- `left-hand-only.txt`: the subset of `google-10000.txt` which only contains the words which can be typed using only the left hand on a QWERTY keyboard. -- `gfycat.txt`: the adjectives and animal names that [gfycat](https://gfycat.com/) uses to generate URLs. -- `bip39.txt`: the word list used to make [BIP39 mnemonic phrases](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) for generating Bitcoin wallets. -- `echohash.txt`: the word list used for Gemini's [Echo Hash](https://echohash.net/) utility, which transforms a hash into an English phrase. + +- `xkcd.txt`: the dictionary for [XKCD](https://xkcd.com/)'s + [Simple Writer](https://xkcd.com/simplewriter/), + [Up Goer Five](https://xkcd.com/1133/), and + [Thing Explainer](https://blog.xkcd.com/2015/05/13/new-book-thing-explainer/), + minus contractions. +- `google-10000.txt`: the top 10,000 most common English words from + [Google's Trillion Word Corpus](https://books.google.com/ngrams/info), minus + swear words. +- `left-hand-only.txt`: the subset of `google-10000.txt` which only contains the + words which can be typed using only the left hand on a QWERTY keyboard. +- `gfycat.txt`: the adjectives and animal names that + [gfycat](https://gfycat.com/) uses to generate URLs. +- `bip39.txt`: the word list used to make + [BIP39 mnemonic phrases](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) + for generating Bitcoin wallets. +- `echohash.txt`: the word list used for Gemini's + [Echo Hash](https://echohash.net/) utility, which transforms a hash into an + English phrase. ## Word list sources + - [XKCD Simple Writer Word List](https://xkcd.com/simplewriter/words.js) - [first20hours/google-10000-english](https://github.com/first20hours/google-10000-english) -- [gfycat adjectives](http://assets.gfycat.com/adjectives) and [gfycat animals](http://assets.gfycat.com/animals) +- [gfycat adjectives](http://assets.gfycat.com/adjectives) and + [gfycat animals](http://assets.gfycat.com/animals) - [BIP39 English word list](https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt) - [echohash](https://github.com/gemini/echohash/blob/master/src/wordlists/en_eff_long.js) diff --git a/main.ts b/main.ts index 65320f0..a52243e 100644 --- a/main.ts +++ b/main.ts @@ -2,10 +2,10 @@ import { parse } from "https://deno.land/std@0.146.0/flags/mod.ts"; const { words, separator, length } = parse(Deno.args, { default: { - 'words': './words/xkcd.txt', - 'separator': '-', - 'length': 3 - } + "words": "./words/xkcd.txt", + "separator": "-", + "length": 3, + }, }); function abort(error: Error) { @@ -16,11 +16,11 @@ function abort(error: Error) { // Validate and process words argument const dictionary: string[] = []; await Deno.readTextFile(words) - .then(f => dictionary.push(...f.split(/\r?\n/))) + .then((f) => dictionary.push(...f.split(/\r?\n/))) .catch(abort); // Will throw if an invalid file path is given // Validate and process separator argument -const separators: string[] = separator.toString().split(''); +const separators: string[] = separator.toString().split(""); // Validate and process length argument const len = parseInt(length); @@ -31,10 +31,10 @@ const rand = new Uint16Array(len); crypto.getRandomValues(rand); const output: string[] = []; -rand.forEach(v => { +rand.forEach((v) => { output.push(dictionary[v % dictionary.length]); output.push(separators[v % separators.length]); }); output.pop(); -console.log(output.join('')); +console.log(output.join("")); -- 2.47.3