@dpmcmlxxvi/randomfacts
v0.2.0
Published
Generate random facts about people.
Downloads
19
Readme
randomfacts
is a Node package that generates
random facts about people given a list of their names. Inspired by Sentencer
and txtgen. A website to generate random facts is available
online here.
GETTING STARTED
The randomfacts
library is available as browser script and
a Node package.
In a browser
<script src="randomfacts.js" charset="utf-8"></script>
<script>
const fact = randomfacts.make('Shaggy');
// returns a string like "Shaggy believes aliens come from Mozambique."
</script>
A sample website can be found in the web
directory.
In Node
npm install @dpmcmlxxvi/randomfacts
const randomfacts = require('@dpmcmlxxvi/randomfacts');
const fact = randomfacts.make('Scrapy-Doo');
// returns a string like "Scrappy-Doo punched a clown somewhere in Germany."
USAGE
API
The randomfacts
object has the following methods:
configure(options)
Configures an existing
randomfacts
instance.create(options)
Creates a new
randomfacts
instance configured with the given options.make(name)
Generate a new random fact for the given
name
.
The library can be configured using the same options available by the Sentencer library and with the following additional options
options = {
// the list of sentence templates in the format specified by Sentener.
// "randomfacts" provides a default if not provded. The action "{{name}}"
// should be included to insert a name into the generated fact.
templates: [],
// The rate at which introductory phrases (e.g., "In recent years, ") are
// randomly prepended to the generated fact.
phraseRate: <number>,
};
BUILD
To build and test the library locally:
npm install
npm test
The browser script is bundled in
./web/js/randomfacts.js
After running the tests a coverage report is availalbe in the coverage
directory.
LICENSE
Copyright (c) 2019 Daniel Pulido [email protected]
Source code is released under the MIT License.