fun-facts
v1.0.5
Published
NPM package for random facts, by Xilog.
Downloads
24
Readme
npm-randomfacts
The GitHub repo for my fun-facts npm package
How to use
First, you do the obvious, npm i fun-facts
in terminal then const facts = require('randomfacts');
Next, you run the fact function: facts.get(options)
Now the options bit is detailed in the next section. It can be run without any options, just leave it blank (facts.get()
).
The get function returns a fact as an object: { type: "success", fact: "example fact", desc: "extra details about example fact" }
If there's an error, it returns an error obj like this: { type: "error", msg: "you did something wrong mate" }
Note: The description may be blank since there are no extra details about the fact, read about the useDesc
option below to avoid errors involving this.
Options
The options argument is an object, here's an example of how you might set it:
{
category : "all",
maxLength : 0,
maxDLength : 0,
useDesc: 0,
safe : false
}
###Category: What category to choose a fact from, leave it blank for all or type a category (detailed in the Categories section)
###Max Length: Max length of the fact
###Max D Length: Max description length of the fact
###Use Desc:
If 0, it will give a description unless description is blank (then it will not add a "desc" property)
If 1, it will give no description (the object does not have a "desc" property)
If 2, it will always give a fact that has a description (doesn't work yet)
###Safe: Safe output, currently doesn't do anything.
Categories
Current categories: (Lowercase when using of course!)
- Animals
- Brands
- Countries
- Fun
- History
- Language
- Laws
- Maths
- Sports
- Phobias
Functions
Currently all it can do is get() but more might be coming.
Contributions - Adding facts
Please make a pull request on GitHub to add facts or contribute, maybe also fix the hacky code if you want, greatly appreciated.
I'll try to accept ASAP.