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

wordgenie

v1.1.0

Published

This package is a word (list) generator built on the Markov chain model.

Downloads

16

Readme

Readme

NPM

npm version dependencies Codacy Badge

Description

This package is a word (list) generator built on the Markov chain model.

Documentation available here

Inspired by this article written (in french) by David Louapre.

It generates words by using the probability of a character to appear after a specific chain of characters. Thus, depending on the original words list you put in, it will generate words which would look like those of the words list.

You can throw a lot of differents words lists at it depending on the expected result (words, names, whatever... in many languages).

It's been tested and worked fine on english, french and mythological words/names containing special characters. Just make sure the original words list is formatted as you would expect the output to be (no characters you don't want like [space], £, +, ;, ... unless you wan't them you appear in the result).

Of course, in the following example, the original words list is very short so you won't get many words generated since the pool of probabilities is very small, so to get the best results, you'll need to give it a strong words list unless you expect very specific results.

Ex.: Original words list:

monday
tuesday
wednesday
wedding
dingo
demon
daylight
sunlight
lighthouse

Generated list:

ding
mon
weddingo
demondaylight
tuesdaylight
sunlighthouse
light
wednesdaylight
demonday
day
daylighthouse
mondaylight
wednesdaylighthouse
tuesdaylighthouse
demondaylighthouse
mondaylighthouse

Installation

Using npm:

$ npm install wordgenie
$ npm install --save wordgenie

Usage example

var fs = require('fs');

// Load the module.
var Generator = require("wordgenie");

// Read a word list
fs.readFile("/path/to/wordlist", "utf8", function(err, data) {
    if (err) throw err;
    
    let _data = data.split('\n');       // Considering your wordlist is a file where each line is a word
    let _words = new Set(_data);
    
    let _generator = new Generator();   // Create a new instance of the generator
    _generator.analyze(_words);         // Analyze the word list (mandatory before generation)
    
    // Get and print a generated word
    let _newWord = _generator.genWord();       // <- String
    console.log("Generated Word: " + _newWord);
    
    // Get and print a list of 10 generated word
    let _newWords = _generator.genSet(10);      // <- Set
    console.log("Generated Words:");
    _newWords.forEach((word) => {
        console.log(word);
    });
});

Todos

  • [ ] Explain the configuration of the "analyze" method
  • [ ] Explain the markovLen parameter
  • [ ] Allow the user to put in a String[] instead of a Set in the "analyze" method (the Set was chosen as a good way to avoid duplicates, but I could manage that from inside the module)
  • [ ] Do something about the case sensitivity (since atm it doesn't recognize the relation between lowercase chars and their uppercase equivalent)
  • [ ] Implement callbacks in the "genWord", "genSet" and "analyze" methods (maybe, is there even a point to do it?)