-
Notifications
You must be signed in to change notification settings - Fork 3
Documentation
Fetches an array of questions that match the provided options.
getQuestions(options?:Partial<QuestionOptions>): Promise<Question[]>
await getQuestions({
amount: 50,
category: 'History',
difficulty: 'hard',
type: 'multiple',
encoding: 'none',
session: aSessionInstance
})
Fetches a trivia category's data. Duplicate of
Category.getCategory()
.
getCategory(arg: CategoryResolvable): Promise<CategoryData>
await getCategory(9)
Properties:
-
An array of all category names. Use
Category.random()
for a random pick.type: CategoryNameType[]
Methods:
-
static .decodeEncodedCategoryName(str: string): CategoryNameType | null
Decodes a URLLegacy, URL3968 or Base64 category name.
Category.decodeEncodedCategoryName('TXl0aG9sb2d5') // 'Mythology'
-
static .getCategory()
Taken from the function with the same name.
-
static .idByName(name: CategoryNameType): number | null
Returns a category id when given it's name.
Category.idByName('General Knowledge') // 9
-
static .nameById(id: number: CategoryNameType) | null
Returns a category name when given it's id.
Category.nameById(9) // 'General Knowledge'
-
static .random(resolvableType?: ["name"] | "id"): CategoryNameType | number
Picks a random category name or id.
Properties:
-
This session's current token
type: string
Methods:
-
.assert(): void
Checks if the session has been initialized or holds a token. Emits a warning if not. (Intended for internal use)
-
.start(): void
Generates a session token and assigns it to the instance Session.token.
-
.reset(): void
Resets the current session's data.
Enums
enum CategoryNames {
"General Knowledge" = 9,
"Entertainment: Books",
"Entertainment: Film",
"Entertainment: Music",
"Entertainment: Musicals & Theatres",
"Entertainment: Television",
"Entertainment: Video Games",
"Entertainment: Board Games",
"Science & Nature",
"Science: Computers",
"Science Mathematics",
"Mythology",
"Sports",
"Geography",
"History",
"Politics",
"Art",
"Celebrities",
"Animals",
"Vehicles",
"Entertainment: Comics",
"Science: Gadgets",
"Entertainment: Japanese Anime & Manga",
"Entertainment: Cartoon & Animations",
}
enum QuestionDifficulties {
Easy = "easy",
Medium = "medium",
Hard = "hard",
}
enum QuestionEncodings {
Base64 = "base64",
None = "none",
Url3986 = "url3986",
UrlLegacy = "urlLegacy",
}
enum QuestionTypes {
Multiple = "multiple",
Boolean = "boolean",
}
Interfaces
A category's API Data
Types Included: number, CategoryNameType
interface CategoryData {
id: number;
name: CategoryNameType;
questionCount: {
total: number;
easy: number;
medium: number;
hard: number;
};
}
Category data that comes inside a Question
Types Included: CategoryData
interface MinifiedCategoryData {
id: number;
name: string;
getData: () => Promise<CategoryData>; // Fetch full category data
}
A fetched trivia question
Types Included: MinifiedCategoryData, QuestionTypeType, string, boolean
interface Question {
category: MinifiedCategoryData; // A portion of the category's API data
type: QuestionTypeType;
difficulty: QuestionDifficultyType;
value: string; // The question itself
correctAnswer: string;
incorrectAnswers: string[];
allAnswers: string[]; // The correct and incorrect answers in one array, shuffled
checkAnswer: (str: string, caseSensitive?: boolean) => boolean; // Returns true if the given string matches .correctAnswer
}
Data describing target questions
Types Included: CategoryResolvable, QuestionDifficultyType, QuestionDifficulties, QuestionTypeType, QuestionTypes, QuestionEncodingType, QuestionEncodings, Session, string, null
interface QuestionOptions ... {
amount: number;
category: CategoryResolvable;
difficulty: QuestionDifficultyType | QuestionDifficulties;
type: QuestionTypeType | QuestionTypes;
encode: QuestionEncodingType | QuestionEncodings;
session: Session | string | null;
}
Types
All string category names
Types Included: CategoryNames
type CategoryNameType = keyof typeof CategoryNames;
A value that can be resolved into an OpenTDB category
Types Included: CategoryNameType, CategoryNames, number
type CategoryResolvable = CategoryNameType | CategoryNames | number;
A string difficulty
type QuestionDifficultyType = "easy" | "medium" | "hard"
A string encoding format
type QuestionEncodingType = "none" | "base64" | "url3986" | "urlLegacy";
A string question type (multiple choice/true or false)
type QuestionTypeType = "multiple" | "boolean";