Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
open-trivia-db
Advanced tools
open-trivia-db
is a small and simple library for interacting with the OpenTDB API.
Live Demo: https://replit.com/@Elitezenv/open-trivia-db-DEMO?v=1
Documentation: https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation
Planning a trivia command for your Discord bot?
discord-trivia
v2 is coming!: https://github.com/Elitezen/discord-trivia
import { getQuestions, CategoryNames } from "open-trivia-db";
const questions = await getQuestions({
amount: 10,
category: CategoryNames.Animals,
difficulty: QuestionDifficulties.Easy,
})
[
{
value: 'How many teeth does an adult rabbit have?',
category: { id: 27, name: 'Animals', getData: [Function: getData] },
type: 'multiple',
difficulty: 'easy',
correctAnswer: '28',
incorrectAnswers: [ '30', '26', '24' ],
allAnswers: [ '24', '28', '30', '26' ],
checkAnswer: [Function: checkAnswer]
}
...
]
Questions can be fetched via the getQuestions()
function by supplying options such as amount
, category
, difficulty
, type
, session
and encode
.
type
: The kind of questions, such as multiple choice ("multiple"
) or true/false ("boolean"
).
session
: A session instance or session token. Learn about sessions
encode
: The encoding of the questions such as base64
, urlLegacy
, url3968
or none
which is the default.
You can apply options via their respective enums.
The result will be an array of questions.
import {
CategoryNames,
QuestionDifficulties,
QuestionTypes,
QuestionEncodings
} from "open-trivia-db";
getQuestions({
amount: 50,
category: CategoryNames["Entertainment: Japanese Anime & Manga"],
difficulty: QuestionDifficulties.Hard,
type: QuestionTypes.Multiple,
encode: QuestionEncodings.None
})
A category resolvable can either be a category name or id. Category id's range from 9-32 inclusive, for there are 23 categories.
To jump between resolvables, use Category.idByName()
and Category.nameById()
.
import { Category, CategoryNames } from "open-trivia-db";
Category.idByName('Art'); // 25
Category.nameById(25); // 'Art'
Use Category.getCategory()
to get a category's data such as name, id, and question counts.
import { Category, CategoryNames } from "open-trivia-db"
Category.getCategory(CategoryNames.Geography)
.then(console.log)
{
id: 22,
name: 'Geography',
questionCount: {
total: 275,
easy: 80, medium: 139, hard: 56
}
}
You can also complete a category's data through a question via Question.category.getData()
const targetQuestion = questions[0] // from getQuestions()
targetQuestion.category.getData()
.then(console.log)
A session ensures you are not supplied a question more than once throughout it's lifetime.
Initialize a session and supply the instance into getQuestions()
. Make sure to await or resolve Session.start()
.
import { Session } from "open-trivia-db"
const mySession = new Session();
await mySession.start();
getQuestions({
session: mySession
})
getQuestions()
will return an error once your session has served every single question in OpenTDB. Don't worry, theres thousands of questions! You will likely never come accross a session's end. However, if you wish to reset your session, use Session.reset()
.
await mySession.reset();
Documentation: https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation
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.
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.