npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

gn222gq-quiz-engine

v1.0.0

Published

A quiz engine module

Readme

QUIZ ENGINE

This module is a standalone quiz engine built with the intent to be integrated into games or educational platforms.

See API Documentation

FEATURES

Quiz Result

A QuizResult is being created while the quiz is going on. The QuizResult holds the players name, the current score and contains functionality to generate a QuizResultSummary wich contains information about the results based on different categories. This feature adds value to the educational use cases where you can present detailed information about how a user has performed based on categories.

Randomization

You decide if the questions should be displayed in a random order or sequential order.

Highscore

Easily integrate a persistent highscore system that uses either local storage for browser or the local filesystem for use with node.js.

Installation

npm install gn222gq-quiz-engine

The API

Example

Since the QuizEngine is the main part of the module, and it uses a event emitting way of communicating to listeners, the module works great for both node.js applications aswell as in browser environment.

import {QuizEngine, QuizQuestions, Question, QuizEvents} from 'gn222gq-quiz-engine';

const quizQuestions = new QuizQuestions();

const quizQuestions.createAndAddQuestion({
  text: "Is the sky blue", 
  choices: ["Yes", "No", "Sometimes"], 
  correctChoice: "Sometimes",
  category: "Nature"
  });
// .. More questions

const quizEngine = new QuizEngine(quizQuestions, "PlayerName");

/*      CALLBACKS      */

quizEngine.on(QuizEvents.QUESTION, (questionData) => {
  /* Your application specific logic */
  // Display question --> Get user input --> call quizEngine.answerQuestion(userInput); for example.

  // questionData.text is the current question text.
  // questionData.choices is the current question choices.
})

quizEngine.on(QuizEvents.CORRECT, (scoreData) => {
  /* Your application specific logic */
  // Display information + call quizEngine.continueQuiz() for example.

  // scoreData.playerName is the current players name.
  // scoreData.score is the current players score.
})

quizEngine.on(QuizEvents.FALSE, (scoreData) => {
  /* Your application specific logic */
  // Display information + call quizEngine.continueQuiz() for example.
})

quizEngine.on(QuizEvents.DONE, (scoreData) => {
  /* Your application specific logic */
  // Display information + call quizEngine.getHighscore() to display the persistent highscore
  // if initialized for example.
})

/*     SET-UP     */

// If you want peristent highscore on local filesystem
quizEngine.initFilesystemStorage("your-custom-path/highscore.json");
// or local storage for browser
quizEngine.initLocalStorage('my-awsome-quiz');

// If you want a randomized order on the questions
quizEngine.randomizeQuestions();


/*     USEFUL METHODS     */

// Starts the quiz and emits a 'question' event.
quizEngine.startQuiz();

// Advances the quiz, and emits 'question' event 
// if there are more questions and a 'done' event if no more questions.
quizEngine.continueQuiz();

// Checks answer and assigns a point and emits 'correct' event if corret.
// Emits a 'false' event if answer is not correct.
quizEngine.answerQuestion(answer);

// Resets the quiz
quizEngine.resetQuiz();

// Gives indication if there are more questions
quizEngine.hasMoreQuestions();

// Returns a Highscore object (see below)
quizEngine.getHighscore();

// Returns a QuizResultSummary object (see below)
quizEngine.getSummary();

Create a QuizQuestions object and questions for the quiz

import {QuizQuestions, Question} from 'gn222gq-quiz-engine';

const quizQuestions = new QuizQuestions();

// You can instantiate Question objects seperately..
const questionObject = new Question({
  text: "text", 
  choices:["choice", "choice2"], 
  correctChoice: "choice", 
  category: "Example"
});

// ..and pass the to the addQuestion() method.
quizQuestions.addQuestion(questionObject);

// You can also supply the constructor arguments for a Question object to the createAndAddQuestion() method to create a Question
// that will be added to the QuizQuestions.
quizQuestions.createAndAddQuestion({text: "text", choices:["choice", "choice2"], correctChoice: "choice", category: "Example"});

Highscore and QuizResultSummary

import {QuizEngine, QuizQuestions, Question, QuizEvents} from 'gn222gq-quiz-engine';

// Implemented setup etc..

// Get the Highscore object
const highscore = await quizEngine.getHighscore();
highscore.toString() // Returns a string representation of the highscore.
highscore.toArray() // Returns an array containing the representation of the highscore.

// Get the QuizResultSummary object
const quizResult = await quizEngine.getSummary();
quizResult.toString() // Returns a string representation of the QuizResultSummary.
/* 
"playerName: TestPlayer, score: 10, - categoryName: Category1,  - amount of questions: 20,
- amount of correct answers: 10,  - percentage of correct answers: 50%"
*/ 

quizResult.toArray() // Returns an array containing the representation of the QuizResultSummary.
/* 
["playerName: TestPlayer", "score: 10", "- categoryName: Category1","  - amount of questions: 20",
"  - amount of correct answers: 10", "  - percentage of correct answers: 50%"]
*/
quizResult.playerName // Gets the players name
quizResult.score // Gets the players score
quizResult.allCategorySummaries // Gets an array of QuizCategorySummary

// Get a QuizCategorySummary
const categorySummary = quizResult.allCategorySummaries[0];
categorySummary.toString() // Returns a string representation of the QuizCategorySummary.
/*
  "category: Category1, amount of questions: 20, amount of correct answers: 10, percentage of correct answers: 50%"
*/
categorySummary.toArray() // Returns an array containing the representation of the QuizCategorySummary.
/*
  ["category: Category1", "amount of questions: 20", "amount of correct answers: 10", "percentage of correct answers: 50%"]
*/
categorySummary.nameOfCategory // Gets the name of the category
categorySummary.amountOfQuestions // Gets the amount of questions for that category
categorySummary.amountOfCorrectAnswers // Gets the amount of correct answers
categorySummary.percentageOfCorrectAnswers // Gets the percentage of correct answers in the category.