trivia-api
Version:
A nodejs module for getting trivia questions in all your fancy projects, in a pretty simple way.
93 lines (74 loc) • 3.55 kB
Markdown
# Trivia API
[](https://www.npmjs.com/package/trivia-api)
[](https://www.npmjs.com/package/trivia-api)
[](https://david-dm.org/k3rn31p4nic/node-trivia-api)
[](https://snyk.io/test/github/k3rn31p4nic/node-trivia-api)
[](LICENSE)
[](https://paypal.me/snkrsnkampa)
[](https://saythanks.io/to/k3rn31p4nic)
A Node.JS module for getting trivia questions in all your fancy projects, in a pretty simple way.
## Classes
<dl>
<dt><a href="#Trivia">Trivia</a></dt>
<dd></dd>
</dl>
## Functions
<dl>
<dt><a href="#getCategories">getCategories()</a> ⇒ <code>Promise.<Object></code></dt>
<dd><p>Returs the available categories of the trivia questions.</p>
</dd>
<dt><a href="#getQuestions">getQuestions([options])</a> ⇒ <code>Promise.<Object></code></dt>
<dd><p>Returs a trivia question from the given options.</p>
</dd>
</dl>
<a name="Trivia"></a>
## Trivia
**Kind**: global class
<a name="new_Trivia_new"></a>
### new Trivia([options])
| Param | Type | Optional | Description |
| --- | --- | --- | --- |
| [options] | <code>Object</code> | True | The options for Trivia API |
| [options.encoding] | <code>String</code> | True | The encoding format of the result, either `urlLegacy`, `url3986` and `base64`. |
**Example**
```js
const Trivia = require('trivia-api')
const trivia = new Trivia({ encoding: 'url3986' });
```
<a name="getCategories"></a>
## getCategories() ⇒ <code>Promise.<Object></code>
Returs the available categories of the trivia questions.
**Kind**: global function
**Returns**: <code>Promise.<Object></code> - Resolves available trivia categories and their IDs
**Example**
```js
trivia.getCategories()
.then(console.log)
.catch(console.error);
```
<a name="getQuestions"></a>
## getQuestions([options]) ⇒ <code>Promise.<Object></code>
Returs a trivia question from the given options.
**Kind**: global function
**Returns**: <code>Promise.<Object></code> - Resolves available trivia questions
| Param | Type | Optional | Default | Description |
| --- | --- | --- | --- | --- |
| [options] | <code>Object</code> | True | | The options for retrieving the question |
| [options.amount] | <code>String</code> | True | <code>1</code> | The amount of question(s) to be retrieved |
| [options.difficulty] | <code>String</code> | True | | The difficulty of question(s) to be retrieved, either `easy`, `medium` or `hard` |
| [options.category] | <code>Number</code> | True | | The category ID from which the question(s) should be retrieved |
| [options.type] | <code>String</code> | True | | The type of question(s) to be retrieved, either `multiple` or `boolean` |
**Example**
```js
let options = {
type: 'boolean',
amount: 10,
difficulty: 'hard'
};
trivia.getQuestions(options)
.then(questions => console.log(questions))
.catch(console.error);
```
> If you liked this project you can **⭐ Star** it on
> [GitHub](https://github.com/k3rn31p4nic/node-trivia-api) and/or
> [send a thank you note to me](https://saythanks.io/to/k3rn31p4nic).