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 🙏

© 2026 – Pkg Stats / Ryan Hefner

markov-text

v0.1.7

Published

A simple procedural text generator implementing Markov chains

Readme

Markov Text Build Status

A simple procedural text generator implementing Markov chains

Markov Chain

Installation

npm install markov-text

Usage

    var Markov = require('markov-text');

    const trainingText = 'Lorem ipsum dolor sit ammet'

    options = {...}
    
    const loremGenerator = new Markov(options) // Setup generator
    
    loremGenerator.seed(trainingText) // Seed chain with "training" text

    const generatedText = loremGenerator.generate(5) // Set length of the generated output.

| Method | Arguments | Returns | Description | |-----------|-----------------------|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | seed | trainingText | - | Seeds the generator with the training text. The generator splits the text into nGrams (pieces of n-characters or n-words length, depending on the mode)analog to chainlinks. | | generate | outputLength | output | Returns the generated text of the specified length. (Length is in ngrams not in charcters/words) |

Options

You can pass in an options object when instancing the generator that accepts the following options:

| Property | Type | Options | Default | Description | |:--------:|:-------:|:----------------------:|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | order | integer | 1-n | no | Specifies the length of the ngrams (chainlinks). Longer chainlinks will produce more coherent text but less 'creativity' | | mode | string | 'single' | 'multiple' | 'multiple' | Single mode will generate single words and will use training text as single independent words. Multiple mode will generate sentences and will use training text as word blocks. |

Debuggin

You can view the chain building step by setting up the enviroment variable DEBUG_CHAIN to true

DEBUG_CHAIN=true node myTextGenerator

Examples

Provided are two examples you can run using:

Metamorphosis

metamorphosis-text

Uses a excerpt of Franz Kafka's Metamorphosis to generate sentences of the desired length.

npm run example:metamorphosis

Lotr

lotr-text

Uses all the names from characters of LOTR to generate a new one

npm run example:lotr

Copyright for training texts is owned by their respetive authors and is not protected by the license of this library

Tests

npm test

Credit

This is mainly my best shot at implementating in Javascript what is explained in this great series by starbeamrainbowlabs