open-trivia-db
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -10,3 +10,3 @@ import Category from "./src/classes/Category"; | ||
import type { CategoryData, ErrorResponse, MinifiedCategoryData, Question, QuestionOptions, RawQuestion, RawCategoryResponse, RawQuestionResponse, RawSessionStartResponse } from "./src/typings/interfaces"; | ||
import type { CategoryNameType, CategoryResolvable, Dictionary, ErrorCode, QuestionDifficultyType, QuestionEncodingType, QuestionTypeType, ResponseCode, SimpleDictionary, ExtendedDictionary } from "./src/typings/types"; | ||
export { Category, Constructor, OpenTDBError, Session, Util, getCategory, getQuestions, CategoryNames, QuestionDifficulties, QuestionEncodings, QuestionTypes, Routes, CategoryData, ErrorResponse, MinifiedCategoryData, Question, QuestionOptions, RawQuestion, RawCategoryResponse, RawQuestionResponse, RawSessionStartResponse, CategoryNameType, CategoryResolvable, Dictionary, ErrorCode, QuestionDifficultyType, QuestionEncodingType, QuestionTypeType, ResponseCode, SimpleDictionary, ExtendedDictionary }; | ||
import type { AllAnswers, BooleanString, CategoryNameType, CategoryResolvable, Dictionary, ErrorCode, IncorrectAnswers, QuestionDifficultyType, QuestionEncodingType, QuestionTypeType, ResponseCode, SimpleDictionary, ExtendedDictionary } from "./src/typings/types"; | ||
export { Category, Constructor, OpenTDBError, Session, Util, getCategory, getQuestions, CategoryNames, QuestionDifficulties, QuestionEncodings, QuestionTypes, Routes, CategoryData, ErrorResponse, MinifiedCategoryData, Question, QuestionOptions, RawQuestion, RawCategoryResponse, RawQuestionResponse, RawSessionStartResponse, AllAnswers, BooleanString, CategoryNameType, CategoryResolvable, Dictionary, ErrorCode, IncorrectAnswers, QuestionDifficultyType, QuestionEncodingType, QuestionTypeType, ResponseCode, SimpleDictionary, ExtendedDictionary }; |
@@ -8,3 +8,3 @@ import type { CategoryData, Question, RawCategoryResponse, RawQuestion } from "../typings/interfaces"; | ||
static category(rawCategoryData: RawCategoryResponse): CategoryData; | ||
static questions(rawQuestions: RawQuestion[]): Question[]; | ||
static questions(rawQuestions: RawQuestion[]): Question<unknown>[]; | ||
} |
@@ -46,7 +46,7 @@ "use strict"; | ||
difficulty: question.difficulty, | ||
correctAnswer: question.correct_answer, | ||
incorrectAnswers: question.incorrect_answers, | ||
correctAnswer: question.type === 'multiple' ? question.correct_answer : question.correct_answer.toLowerCase(), | ||
incorrectAnswers: question.type === 'multiple' ? question.incorrect_answers : question.incorrect_answers[0].toLowerCase(), | ||
allAnswers: Util_1.default.shuffleArray(__spreadArray([ | ||
question.correct_answer | ||
], question.incorrect_answers, true)), | ||
], (question.type === 'multiple' ? question.incorrect_answers : question.incorrect_answers.map(function (s) { return s.toLowerCase(); })), true)), | ||
checkAnswer: function (str, caseSensitive) { | ||
@@ -53,0 +53,0 @@ if (caseSensitive === void 0) { caseSensitive = false; } |
@@ -111,1 +111,5 @@ "use strict"; | ||
exports.default = getQuestions; | ||
getQuestions({ | ||
type: 'boolean', | ||
amount: 1 | ||
}).then(console.log); |
@@ -45,4 +45,4 @@ export declare enum CategoryNames { | ||
Questions = "https://opentdb.com/api.php?", | ||
SessionReset = "", | ||
SessionReset = "https://opentdb.com/api_token.php?command=reset", | ||
SessionStart = "https://opentdb.com/api_token.php?command=request" | ||
} |
@@ -53,4 +53,4 @@ "use strict"; | ||
Routes["Questions"] = "https://opentdb.com/api.php?"; | ||
Routes["SessionReset"] = ""; | ||
Routes["SessionReset"] = "https://opentdb.com/api_token.php?command=reset"; | ||
Routes["SessionStart"] = "https://opentdb.com/api_token.php?command=request"; | ||
})(Routes = exports.Routes || (exports.Routes = {})); |
import type Session from "../classes/Session"; | ||
import { QuestionDifficulties, QuestionEncodings, QuestionTypes } from "./enums"; | ||
import type { CategoryNameType, CategoryResolvable, ExtendedDictionary, QuestionDifficultyType, QuestionEncodingType, QuestionTypeType, ResponseCode } from "./types"; | ||
import type { AllAnswers, BooleanString, CategoryNameType, CategoryResolvable, ExtendedDictionary, IncorrectAnswers, QuestionDifficultyType, QuestionEncodingType, QuestionTypeType, ResponseCode } from "./types"; | ||
export interface CategoryData { | ||
@@ -23,10 +23,10 @@ id: number; | ||
} | ||
export interface Question { | ||
export interface Question<QuestionType extends unknown | QuestionTypes = unknown> { | ||
category: MinifiedCategoryData; | ||
type: QuestionTypeType; | ||
type: QuestionType extends unknown ? QuestionTypeType : QuestionType; | ||
difficulty: QuestionDifficultyType; | ||
value: string; | ||
correctAnswer: string; | ||
incorrectAnswers: string[]; | ||
allAnswers: string[]; | ||
correctAnswer: QuestionType extends unknown | 'multiple' ? string : BooleanString; | ||
incorrectAnswers: QuestionType extends unknown ? IncorrectAnswers | BooleanString : QuestionType extends 'multiple' ? IncorrectAnswers : BooleanString; | ||
allAnswers: QuestionType extends unknown ? AllAnswers<QuestionTypes.Multiple> | AllAnswers<QuestionTypes.Boolean> : QuestionType extends 'multiple' ? AllAnswers<QuestionTypes.Multiple> : AllAnswers<QuestionTypes.Boolean>; | ||
checkAnswer: (str: string, caseSensitive?: boolean) => boolean; | ||
@@ -33,0 +33,0 @@ } |
@@ -1,2 +0,4 @@ | ||
import type { CategoryNames } from "./enums"; | ||
import type { CategoryNames, QuestionTypes } from "./enums"; | ||
export declare type AllAnswers<T extends QuestionTypes> = T extends QuestionTypes.Boolean ? [BooleanString, BooleanString] : [string, string, string, string]; | ||
export declare type BooleanString = `${boolean}`; | ||
export declare type CategoryNameType = keyof typeof CategoryNames; | ||
@@ -6,2 +8,3 @@ export declare type CategoryResolvable = CategoryNameType | CategoryNames | number; | ||
export declare type ErrorCode = 1 | 2 | 3 | 4; | ||
export declare type IncorrectAnswers = [string, string, string]; | ||
export declare type QuestionDifficultyType = "easy" | "medium" | "hard"; | ||
@@ -8,0 +11,0 @@ export declare type QuestionEncodingType = "none" | "base64" | "url3986" | "urlLegacy"; |
{ | ||
"name": "open-trivia-db", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A small and simple wrapper for the Open Trivia Database API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,14 +10,20 @@ ![OpenTriviaDB](https://i.imgur.com/QBhF5aY.png) | ||
Live Demo: https://replit.com/@Elitezenv/open-trivia-db-DEMO?v=1 | ||
**Live Demo**: https://replit.com/@Elitezenv/open-trivia-db-DEMO?v=1 | ||
## Updates (2.0.0) | ||
- The library received a massive rework through many quality of life changes. | ||
**Documentation**: https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation | ||
- 'Static' and 'Pretty' category names are no more, developers will no longer have to worry about converting through these formats. | ||
## Discord.JS Add On | ||
- All QuestionOption option types now have respective enums to work with. | ||
Planning a trivia command for your Discord bot? | ||
Checkout `discord-trivia`! https://www.npmjs.com/package/discord-trivia | ||
- `Category` is now just a class with various static methods for working with categories. | ||
# 2.1.0 | ||
- Boolean questions now return their incorrect answer as a BooleanString and not a string[] | ||
- Question type now takes a generic of type QuestionTypes | unknown. Default is unknown | ||
- Created typings for correct and incorrect values. | ||
- Included URL for Session.reset() as it was missing. | ||
## Example Code | ||
@@ -148,2 +154,4 @@ ```js | ||
<hr> | ||
<hr> | ||
**Documentation**: https://github.com/Elitezen/open-trivia-db-wrapper/wiki/Documentation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
54047
958
156
1