npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gibrish

v0.1.5

Published

Gibrish generates fake words from real words

Downloads

8

Readme

Gibrish

Gibrish generates fake words from real words.

Install

Gibrish is on npm: npm install gibrish

Quick start

var Gibrish = require("gibrish");
var g = new Gibrish();

var massachusettsTowns = ["Abington", "Acton", /* etc. */ ];
g.push(massachusettsTowns);

g.generate();
  "Brainfield"
g.generate();
  "Pittleborough"
g.generate();
  "East Barnster"
g.generate();
  "Brewster-by-the-Sea"

Docs

new Gibrish([options])

Constructs a new gibrish instance. This constructor is the only export of the module:

var Gibrish = require("gibrish")

Arguments

  • [options] (Object) - Options for the instance (not required).
  • [options.order=3] (Number) - The order of the Markov chain. The order is the number of previous characters used to determine the next. Defaults to 3.
  • [options.novel=true] (Boolean) - Exclusively generate words that do not exist in the training set. Defaults to true.
  • [options.maxTries=10] (Number) - Number of times generate() will retry if its output is not novel. Defaults to 10.

Returns

Object: Returns an Gibrish instance.


gibrish.push(words)

Add training words to the instance. These words are processed and added to the instance's database for use in generate().

Arguments

  • words (Array of Strings or String) - words to add to the instance. If an Array of Strings is given, each member will be added as a word. If a String is given it will be added as a single word.

Returns

undefined: Does not return a value.


gibrish.generate([options])

Generates a word from instance's database. This method is not deterministic, as Gibrish uses a random probabilistic algorithm.

Therefore generate() will return null if novel is truthy and generate() has not found a novel word in maxTries. This may happen often if order is relatively high compared to the training words' average length or if few training words have been added.

Arguments

  • [options] (Object) - Options for generation (not required). These options are identical to those in the Gibrish constructor except that order is ignored (an instance's order is immutable). Any generate() options override those in the constructor.

Returns

String or null: Returns a generated word or null if one could not be created.

About

Markov chains

Gibrish creates a Markov chain from input words and uses it to generate gibberish words. Markov chains are made up of states and links between those states. In Gibrish's case, the states are just letters and other characters you'd find in words (like spaces and dashes). A word is built by linking states together. The links are chosen randomly, according to the distribution of links in the training words.

A chain's order (or memory) is the number of states it uses to determine its next state. In Gibrish the default order is 3.

Don't worry; it's really not that scary. For example, here's how the beginning of the gibberish town name "East Barnster" is created from actual Massachusetts town names:

  1. "Eas" - "Eas" is randomly selected as a starting point. It has a length of 3 because the order is 3. "Eas" was in the training database because it occurred in some of the training words, like "East Longmeadow", and "Eastham."
  2. "East" - "Eas" is used to determine the next character (note that it is 3-characters long, the order of the chain). In this case, "t" is the only character that occurs after "Eas" in the training data, so it is chosen.
  3. "East " - "ast" (again, 3 characters) is used to determine the next character. The characters that follow "ast" in the training data are "e", "o", "h", and " "; these are from words like "Lancaster", "Easthampton", "Easton", and "East Brookfield", respectively. In this example, a space " " was randomly chosen (with a probability of 3/7, if you're curious).

Gibberish passwords

Creating gibberish words is mainly just for fun. One practical use, however, is to create memorable but non-dictionary passwords (especially useful if a system limits your password length). Gibberish words are a nice compromise between real words (easy to type and easy to remember) and random characters (not found in dictionaries and therefore more secure).