Skip to content

Util for generating random sentences, paragraphs and articles in English

License

Notifications You must be signed in to change notification settings

praveenmunagapati/txtgen

 
 

Repository files navigation

txtgen

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

NPM Build Status codecov Dependency Status NSP Status

Demo

See how it works?

Setup

Usage

var txtgen = require('txtgen');

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

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

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

APIs

  • .sentence()
  • .paragraph([Number totalSentences])
  • .article([Number totalParagraphs])
  • .addNouns(Array nouns)
  • .addAdjectives(Array adjectives)
  • .addTemplates(Array sentenceTemplates)

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)

About

Util for generating random sentences, paragraphs and articles in English

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.5%
  • HTML 0.5%