https://github.com/johnpaulada/generatr
A text generator using a user-built grammar. Inspired by Tracery.
https://github.com/johnpaulada/generatr
text-generator
Last synced: 10 months ago
JSON representation
A text generator using a user-built grammar. Inspired by Tracery.
- Host: GitHub
- URL: https://github.com/johnpaulada/generatr
- Owner: johnpaulada
- Created: 2018-08-15T04:51:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-29T21:02:58.000Z (over 7 years ago)
- Last Synced: 2025-08-17T22:37:30.946Z (10 months ago)
- Topics: text-generator
- Language: JavaScript
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Generatr
A text generation library based on Tracery.
[](https://forthebadge.com)
[](https://forthebadge.com)
## Rationale
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.
## Quickstart
### Import via `require`
```javascript
const Generatr = require('generatr')
```
### Import as ES module
```javascript
import Generatr from 'generatr'
```
### Import in browser
```html
```
### Creating a text generator with Generatr
To create a text generator, you need to supply it with a `grammar` object
#### Example:
```javascript
const generator = Generatr(grammar)
```
### Creating a Generatr grammar
A Generatr grammar is just an object whose values are either strings or arrays.
#### Example
```javascript
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.
## Apps that use this
1. [Thesis Title Generator](https://jepe-thesis-title-generator.netlify.com/) - This is a CS/IT thesis title generator that uses Generatr to generate the text.
## License
MIT