Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
open-trivia-db
Advanced tools
A wrapper for the Open Trivia Database API. Built with TypeScript, works with VanillaJS.
open-trivia-db is a small, simple and fast wrapper for Open Trivia Database - A Free to use, user-contributed trivia question database. Built with TypeScript, works with VanillaJS.
Documentation: https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation
Support me: https://www.paypal.com/paypalme/alejandromuratalla
Ensure you are using Node version 14 or higher and that your enviroment contains the https
module.
npm i open-trivia-db
The following examples make use of the Async/Await syntax. Ensure you are inside an async function, otherwise use promise callbacks.
You can provide QuestionOptions
to describe the type of questions you want to recieve.
import { Category, getQuestions } from 'open-trivia-db';
const questions = await getQuestions({
amount: 50, // 1 - 50
difficulty: 'easy', // or 'medium' or 'hard'
type: 'multiple', // or 'boolean (true/false)
category: Category.allNames.SCIENCE_COMPUTERS
});
[
{
value: 'What is the code name for the mobile operating system Android 7.0?',
category: 'Science: Computers',
type: 'multiple',
difficulty: 'easy',
correctAnswer: 'Nougat',
incorrectAnswers: [ 'Ice Cream Sandwich', 'Jelly Bean', 'Marshmallow' ],
allAnswers: [ 'Nougat', 'Jelly Bean', 'Marshmallow', 'Ice Cream Sandwich' ],
checkAnswer: [Function: checkAnswer]
}
...
]
You can generate a category class by providing a CategoryResolvable which includes a category's name or id. An instance of Category will allow you to fetch category data and questions relating to the provided resolvable.
let myCategory = new Category(9);
myCategory = new Category('GENERAL_KNOWLEDGE');
myCategory = new Category(Category.allNames.GENERAL_KNOWLEDGE);
const data = await myCategory.getData();
{
id: 9,
name: 'General Knowledge',
questionCounts: {
total: 298,
forEasy: 116,
forMedium: 123,
forHard: 59
}
}
const questions = await myCategory.fetchQuestions({
amount: 1,
difficulty: 'hard'
});
// Same outputs as getQuestions()
You can always get information relating to a category by simply passing a resolvable into getQuestions()
and getCategoryData()
getQuestions({
category: 9
});
getCategoryData('GENERAL_KNOWLEDGE');
// Same as myCategory.fetchQuestions() and .getData()
A session ensures you do not get duplicate questions.
import { Category, Session, getQuestions } from 'open-trivia-db';
const session = new Session();
await session.start();
const batch1 = await getQuestions({
amount: 10,
category: Category.random(),
difficulty: 'hard',
session
});
const batch2 = await getQuestions({
amount: 10,
category: Category.random(),
difficulty: 'hard',
session
});
const completeBatch = [...batch1, ...batch2]; // All unique!
session.end();
Note: In respect to the API, it is recommended you generate and save 1 session token for use when testing.
Documentation has been moved to a GitHub Wiki page:
https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation
Any tip is greatly appreciated 😀 https://www.paypal.com/paypalme/alejandromuratalla
FAQs
A small and simple wrapper for the Open Trivia Database API.
We found that open-trivia-db demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.