A text generation library based on Tracery.
I tried to use Tracery on a React project, but couldn't get it to work. So I built a simple one based on it.
const Generatr = require('generatr')
import Generatr from 'generatr'
<script src="https://cdn.jsdelivr.net/npm/generatr@0.1.1/generatr.min.js"></script>
To create a text generator, you need to supply it with a grammar
object
const generator = Generatr(grammar)
A Generatr grammar is just an object whose values are either strings or arrays.
const grammar = {
title: "{{adjective}} {{noun}}"
adjective: ["Awesome", "Sad", "Nice"],
noun: ["Person", "Animal"]
}
Inside of {{
and }}
should be a key inside the grammar object.
In this example, the {{adjective}}
template will be replaced by one of the strings in the adjective
key.
The same would happen with the {{noun}}
template. You can even nest it or make it recursive but make sure that it will somehow end.
To actually generate some text, run generator.generate("title")
. This will generate text using the template in the title
key of the grammar object.
- Thesis Title Generator - This is a CS/IT thesis title generator that uses Generatr to generate the text.
MIT