Util for generating random sentences, paragraphs and articles in English
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
src
test
.eslintignore
.eslintrc.json
.gitignore
.travis.yml
LICENSE
README.md
package.json
reset.js

README.md

txtgen

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

NPM Build 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)