txt

txtgen

Util for generating random sentences, paragraphs and articles in English

Showing:

Popularity

Downloads/wk

5.6K

GitHub Stars

45

Maintenance

Last Commit

10mos ago

Contributors

2

Package

Dependencies

0

Size (min+gzip)

3.3KB

License

MIT

Type Definitions

Built-In

Tree-Shakeable

Yes?

Categories

Readme

txtgen

Lightweight util for generating random sentences, paragraphs and articles in English. Inspired by Sentencer and metaphorpsum.com.

NPM CI test Coverage Status Quality Gate Status

Demo

See how it works?

Setup

  • Also supports ES6 Module, CommonJS, AMD and UMD style.

Usage

const txtgen = require('txtgen');

const sentence = txtgen.sentence();
console.log(sentence);

const paragraph = txtgen.paragraph();
console.log(paragraph);

const article = txtgen.article();
console.log(article);

APIs

  • .sentence()
  • .paragraph([Number totalSentences])
  • .article([Number totalParagraphs])
  • .addNouns(Array nouns)
  • .addAdjectives(Array adjectives)
  • .addTemplates(Array sentenceTemplates)
  • .setNouns(Array nouns)
  • .setAdjectives(Array adjectives)
  • .setTemplates(Array sentenceTemplates)
  • .getNouns()
  • .getAdjectives()
  • .getTemplates()

As their name means, we have 4 groups of methods:

  • sentence(), paragraph(), article(): generate text by given grammatical unit
  • addNouns(), addAdjectives(), addTemplates(): add more samples to current sample set
  • setNouns(), setAdjectives(), setTemplates(): replace current sample set with new ones
  • getNouns(), getAdjectives(), getTemplates(): get current sample set

The set* and get* methods were added since v2.2.3 to help you customize your sample data.

Template

If you want to add more kinds of sentence, just use .addTemplates() method. It expects a list of sentence templates. Each of sentence template is an English sentence, with the placeholders that can be replaced with any alternative word.

For example:

import {
  addTemplates
} from 'txtgen';

let templates = [
  '{{a_noun}} is {{a_noun}} from the right perspective',
  'the {{noun}} of {{a_noun}} becomes {{an_adjective}} {{noun}}'
];

addTemplates(templates);

Here are the available placeholders:

  • noun
  • nouns
  • a_noun
  • adjective
  • an_adjective

Test

git clone https://github.com/ndaidong/txtgen.git
cd txtgen
npm install
npm test

License

The MIT License (MIT)

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100