@quizpot/quizcore 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/index.cjs +582 -0
  2. package/dist/index.d.cts +472 -0
  3. package/dist/index.d.cts.map +1 -0
  4. package/dist/index.d.mts +472 -0
  5. package/dist/index.d.mts.map +1 -0
  6. package/dist/index.mjs +522 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +7 -6
  9. package/dist/events/client/host/kick-player.d.ts +0 -8
  10. package/dist/events/client/host/kick-player.d.ts.map +0 -1
  11. package/dist/events/client/host/kick-player.js +0 -4
  12. package/dist/events/client/host/next-step.d.ts +0 -5
  13. package/dist/events/client/host/next-step.d.ts.map +0 -1
  14. package/dist/events/client/host/next-step.js +0 -3
  15. package/dist/events/client/host/start-lobby.d.ts +0 -6
  16. package/dist/events/client/host/start-lobby.d.ts.map +0 -1
  17. package/dist/events/client/host/start-lobby.js +0 -4
  18. package/dist/events/client/player/submit-answer.d.ts +0 -9
  19. package/dist/events/client/player/submit-answer.d.ts.map +0 -1
  20. package/dist/events/client/player/submit-answer.js +0 -4
  21. package/dist/events/server/lobby-deleted.d.ts +0 -8
  22. package/dist/events/server/lobby-deleted.d.ts.map +0 -1
  23. package/dist/events/server/lobby-deleted.js +0 -4
  24. package/dist/events/server/lobby-joined.d.ts +0 -14
  25. package/dist/events/server/lobby-joined.d.ts.map +0 -1
  26. package/dist/events/server/lobby-joined.js +0 -18
  27. package/dist/events/server/lobby-status-update.d.ts +0 -32
  28. package/dist/events/server/lobby-status-update.d.ts.map +0 -1
  29. package/dist/events/server/lobby-status-update.js +0 -4
  30. package/dist/events/server/player-answer-result.d.ts +0 -11
  31. package/dist/events/server/player-answer-result.d.ts.map +0 -1
  32. package/dist/events/server/player-answer-result.js +0 -4
  33. package/dist/events/server/player-joined.d.ts +0 -9
  34. package/dist/events/server/player-joined.d.ts.map +0 -1
  35. package/dist/events/server/player-joined.js +0 -4
  36. package/dist/events/server/player-kicked.d.ts +0 -6
  37. package/dist/events/server/player-kicked.d.ts.map +0 -1
  38. package/dist/events/server/player-kicked.js +0 -4
  39. package/dist/events/server/player-left.d.ts +0 -9
  40. package/dist/events/server/player-left.d.ts.map +0 -1
  41. package/dist/events/server/player-left.js +0 -4
  42. package/dist/events/server/player-update.d.ts +0 -9
  43. package/dist/events/server/player-update.d.ts.map +0 -1
  44. package/dist/events/server/player-update.js +0 -4
  45. package/dist/events/server/update-lobby-answers.d.ts +0 -8
  46. package/dist/events/server/update-lobby-answers.d.ts.map +0 -1
  47. package/dist/events/server/update-lobby-answers.js +0 -4
  48. package/dist/index.d.ts +0 -26
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/index.js +0 -25
  51. package/dist/managers/lobby-manager.d.ts +0 -12
  52. package/dist/managers/lobby-manager.d.ts.map +0 -1
  53. package/dist/managers/lobby-manager.js +0 -112
  54. package/dist/types/events.d.ts +0 -16
  55. package/dist/types/events.d.ts.map +0 -1
  56. package/dist/types/events.js +0 -1
  57. package/dist/types/lobby.d.ts +0 -42
  58. package/dist/types/lobby.d.ts.map +0 -1
  59. package/dist/types/lobby.js +0 -10
  60. package/dist/types/question.d.ts +0 -106
  61. package/dist/types/question.d.ts.map +0 -1
  62. package/dist/types/question.js +0 -22
  63. package/dist/types/questions/multiple-choice.d.ts +0 -51
  64. package/dist/types/questions/multiple-choice.d.ts.map +0 -1
  65. package/dist/types/questions/multiple-choice.js +0 -21
  66. package/dist/types/questions/short-answer.d.ts +0 -34
  67. package/dist/types/questions/short-answer.d.ts.map +0 -1
  68. package/dist/types/questions/short-answer.js +0 -11
  69. package/dist/types/questions/true-false.d.ts +0 -36
  70. package/dist/types/questions/true-false.d.ts.map +0 -1
  71. package/dist/types/questions/true-false.js +0 -12
  72. package/dist/types/quizfile.d.ts +0 -79
  73. package/dist/types/quizfile.d.ts.map +0 -1
  74. package/dist/types/quizfile.js +0 -23
  75. package/dist/types/quizstep.d.ts +0 -73
  76. package/dist/types/quizstep.d.ts.map +0 -1
  77. package/dist/types/quizstep.js +0 -7
  78. package/dist/types/quiztheme.d.ts +0 -7
  79. package/dist/types/quiztheme.d.ts.map +0 -1
  80. package/dist/types/quiztheme.js +0 -5
  81. package/dist/types/slide.d.ts +0 -18
  82. package/dist/types/slide.d.ts.map +0 -1
  83. package/dist/types/slide.js +0 -9
  84. package/dist/types/slides/comparison.d.ts +0 -9
  85. package/dist/types/slides/comparison.d.ts.map +0 -1
  86. package/dist/types/slides/comparison.js +0 -7
  87. package/dist/types/slides/titleImageTextSlide.d.ts +0 -9
  88. package/dist/types/slides/titleImageTextSlide.d.ts.map +0 -1
  89. package/dist/types/slides/titleImageTextSlide.js +0 -7
  90. package/dist/types/slides/titleSlide.d.ts +0 -8
  91. package/dist/types/slides/titleSlide.d.ts.map +0 -1
  92. package/dist/types/slides/titleSlide.js +0 -6
  93. package/dist/util/guards.d.ts +0 -18
  94. package/dist/util/guards.d.ts.map +0 -1
  95. package/dist/util/guards.js +0 -15
  96. package/dist/util/names/additives.json +0 -23
  97. package/dist/util/names/animals.json +0 -23
  98. package/dist/util/names/colors.json +0 -14
  99. package/dist/util/names/names.d.ts +0 -4
  100. package/dist/util/names/names.d.ts.map +0 -1
  101. package/dist/util/names/names.js +0 -31
  102. package/dist/util/sanitizer.d.ts +0 -3
  103. package/dist/util/sanitizer.d.ts.map +0 -1
  104. package/dist/util/sanitizer.js +0 -18
  105. package/dist/util/score.d.ts +0 -11
  106. package/dist/util/score.d.ts.map +0 -1
  107. package/dist/util/score.js +0 -33
  108. package/dist/util/validator.d.ts +0 -14
  109. package/dist/util/validator.d.ts.map +0 -1
  110. package/dist/util/validator.js +0 -27
@@ -1,31 +0,0 @@
1
- import animals from "./animals.json";
2
- import additives from "./additives.json";
3
- import colors from "./colors.json";
4
- export const generateName = () => {
5
- const animal = animals[Math.floor(Math.random() * animals.length)];
6
- const additive = additives[Math.floor(Math.random() * additives.length)];
7
- const color = colors[Math.floor(Math.random() * colors.length)];
8
- return `${color}${additive}${animal}`;
9
- };
10
- export const generateUniqueName = (players) => {
11
- const maxPossible = animals.length * additives.length * colors.length;
12
- if (players.length >= maxPossible) {
13
- throw new Error("No unique names available");
14
- }
15
- const existingNames = new Set(players.map((p) => p.name));
16
- for (let i = 0; i < 100; i++) {
17
- const candidate = generateName();
18
- if (!existingNames.has(candidate))
19
- return candidate;
20
- }
21
- for (const c of colors) {
22
- for (const ad of additives) {
23
- for (const an of animals) {
24
- const candidate = `${c}${ad}${an}`;
25
- if (!existingNames.has(candidate))
26
- return candidate;
27
- }
28
- }
29
- }
30
- throw new Error("No unique names available"); // Fallback
31
- };
@@ -1,3 +0,0 @@
1
- import { Question, SafeQuestion } from "../types/question";
2
- export declare const sanitizeQuestion: (question: Question) => SafeQuestion;
3
- //# sourceMappingURL=sanitizer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanitizer.d.ts","sourceRoot":"","sources":["../../src/util/sanitizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG3D,eAAO,MAAM,gBAAgB,GAAI,UAAU,QAAQ,KAAG,YAmBrD,CAAC"}
@@ -1,18 +0,0 @@
1
- import { isMultipleChoice, isShortAnswer, isTrueFalse } from "./guards";
2
- export const sanitizeQuestion = (question) => {
3
- if (isMultipleChoice(question)) {
4
- return {
5
- ...question,
6
- choices: question.choices.map(({ text }) => ({ text })),
7
- };
8
- }
9
- if (isTrueFalse(question)) {
10
- const { answer, ...sanitized } = question;
11
- return sanitized;
12
- }
13
- if (isShortAnswer(question)) {
14
- const { answers, ...sanitized } = question;
15
- return sanitized;
16
- }
17
- throw new Error("Invalid question type");
18
- };
@@ -1,11 +0,0 @@
1
- import { Answer } from "./validator";
2
- import { QuizFile } from "../types/quizfile";
3
- import { Question } from "../types/question";
4
- export declare const calculateScore: (player: {
5
- score: number;
6
- streak: number;
7
- }, question: Question, answer: Answer, quiz: QuizFile) => {
8
- newScore: number;
9
- pointsAwarded: number;
10
- };
11
- //# sourceMappingURL=score.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/util/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAK7C,eAAO,MAAM,cAAc,GACzB,QAAQ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACzC,UAAU,QAAQ,EAClB,QAAQ,MAAM,EACd,MAAM,QAAQ,KACb;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAmC3C,CAAC"}
@@ -1,33 +0,0 @@
1
- const BASE_SCORE = 500;
2
- const TIME_BONUS_MAX = 500;
3
- export const calculateScore = (player, question, answer, quiz) => {
4
- if (!answer.isCorrect)
5
- return { newScore: player.score, pointsAwarded: 0 };
6
- const multipliers = {
7
- noPoints: 0,
8
- normalPoints: 1,
9
- doublePoints: 2,
10
- };
11
- const pointMultiplier = multipliers[question.points] ?? 1;
12
- if (pointMultiplier === 0)
13
- return { newScore: player.score, pointsAwarded: 0 };
14
- let timeBonus = 0;
15
- if (question.timeLimit > 0) {
16
- const timeLimitMs = question.timeLimit * 1000;
17
- const timeTaken = Math.max(0, Math.min(answer.timeTaken, timeLimitMs));
18
- const timeRemainingRatio = 1 - (timeTaken / timeLimitMs);
19
- timeBonus = TIME_BONUS_MAX * timeRemainingRatio;
20
- }
21
- let questionScore = (BASE_SCORE + timeBonus) * pointMultiplier;
22
- if (player.streak >= 2) {
23
- const totalQuestions = quiz.steps.filter(s => s.type === "question").length;
24
- const dynamicCap = Math.min(1.2 + Math.max(0, totalQuestions - 5) * 0.02, 1.5);
25
- const streakMultiplier = Math.min(1 + (player.streak - 1) * 0.05, dynamicCap);
26
- questionScore *= streakMultiplier;
27
- }
28
- const finalPoints = Math.trunc(questionScore);
29
- return {
30
- newScore: player.score + finalPoints,
31
- pointsAwarded: finalPoints
32
- };
33
- };
@@ -1,14 +0,0 @@
1
- import { ShortAnswerQuestionAnswer } from "../types/questions/short-answer";
2
- import { TrueFalseQuestionAnswer } from "../types/questions/true-false";
3
- import { MultipleChoiceQuestionAnswer } from "../types/questions/multiple-choice";
4
- import { Question } from "../types/question";
5
- export type SubmittedAnswer = MultipleChoiceQuestionAnswer | TrueFalseQuestionAnswer | ShortAnswerQuestionAnswer;
6
- export interface Answer {
7
- playerId: string;
8
- submission: SubmittedAnswer;
9
- timeTaken: number;
10
- isCorrect: boolean;
11
- pointsAwarded: number;
12
- }
13
- export declare const isCorrect: (question: Question, submission: SubmittedAnswer) => boolean;
14
- //# sourceMappingURL=validator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/util/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,MAAM,eAAe,GACvB,4BAA4B,GAC5B,uBAAuB,GACvB,yBAAyB,CAAC;AAE9B,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,eAAe,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,SAAS,GAAI,UAAU,QAAQ,EAAE,YAAY,eAAe,KAAG,OA+B3E,CAAC"}
@@ -1,27 +0,0 @@
1
- import { isMultipleChoice, isShortAnswer, isTrueFalse } from "../util/guards";
2
- ;
3
- export const isCorrect = (question, submission) => {
4
- if (isMultipleChoice(question) && submission.type === "multiple-choice") {
5
- if (question.matchAll) {
6
- const correctIndices = question.choices
7
- .map((c, i) => (c.correct ? i : -1))
8
- .filter((i) => i !== -1);
9
- return (submission.choices.length === correctIndices.length &&
10
- submission.choices.every((index) => correctIndices.includes(index)));
11
- }
12
- if (submission.choices.length === 0)
13
- return false;
14
- return submission.choices.every(index => {
15
- const choice = question.choices[index];
16
- return choice ? choice.correct : false;
17
- });
18
- }
19
- if (isTrueFalse(question) && submission.type === "true-false") {
20
- return question.answer === submission.answer;
21
- }
22
- if (isShortAnswer(question) && submission.type === "short-answer") {
23
- const playerAns = submission.answer.trim().toLowerCase();
24
- return question.answers.some(ans => ans.trim().toLowerCase() === playerAns);
25
- }
26
- return false;
27
- };