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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-quizzer

v2.0.4

Published

A module for generating and evaluating random quizzes

Downloads

16

Readme

node-quizzer

Demo

An example running node-quizzer

Documentation

  • To add questions open the quizzes.json file in node-quizzer\data

  • There are 4 question types marked from 0 to 4

    • {"type": 0} indicates single answer questions, this will generate radio buttons in the UI
    • {"type": 1} multiple answer questions, checkboxes are generated in the UI
    • {"type": 2} free text, this will be validated by RegExp; a text input is generated in the UI
    • {"type": 3} free text, requires human validation; a textarea is generated in the UI
  • Fields a question might have:

    {
      "qid": 0,       // number: indicates the question ID, must be unique per category
      "graded": true, // boolean: marks if the question is graded or not upon evaluation
      "type": 1,      // number: one of the 4 types described above
      "title": null,  // string: the title of the question
      "desc": null,   // string: a small description if needed
      "code": null,   // string: a piece of code if needed
      "lang": null,   // string: the piece of code type (js, css, perl, etc.)
      "opts": [],     // array: holds all possible responses for this question
      "correct": [],  // array: holds all indexes of the correct answers for this question
      "rule": "",     // string: a RegExp to use as validation for type 2 questions
      "ruleOpts": ""  // string: RegExp options for better validation; default: "gi"
    }
  • Don't use all of the fields for every question type:

    • {"type": 0} doesn't need the rule, ruleOpts fields
    • {"type": 1} doesn't need the rule, ruleOpts fields
    • {"type": 2} doesn't need the correct, opts fields
    • {"type": 3} doesn't need the correct, opts, rule, ruleOpts fields
  • All the test evaluations will be saved on the server in a results folder

    • all tests will have the following name format:

      {review|final}-{token_id}-{full-username}

    • quiz names that start with review contain at least one {"type": 3} question

Breakdown of methods in node-quizzer

// load the node-quizzer module
var quizzer = require('node-quizzer');

/*
 * generate - method used for generating quizzes
 * tokenize - method used for generating a quiz token
 * usage: quizzer.generate(opts);
 * usage: quizzer.tokenize(opts);
 *
 * @param {object} opts  And object containing user and quiz details: uname,
 *                       email, name, count, time, perc (defined below)
 *   @param {string} uname The full username of the quiz taker
 *   @param {string} email The email of the quiz taker
 *   @param {string} name  The name of the quiz, defined as a key in quizzes.json
 *   @param {number} count The number of questions in the quiz;    default: 20
 *   @param {number} time  The number of minutes before quiz ends; default: 30
 *   @param {number} perc  The minimum required pass percentage;   default: 50
 *
 * @return {string} HTML markup containing questions and countdown timer
 *                  URL to quiz (in case tokinize was used instead)
 */
var set = quizzer.generate({
  uname: 'John Doe',
  email: '[email protected]',
  name: 'nodejs',
  count: 10
});
console.log(set);

/*
 * fromToken - method user for generating a quiz templated based on a token
 * usage: quizzer.fromToken(token_uid);
 *
 * @param {string} token_uid The token that was generate with quizzer.tokenize
 *
 * @return {string} HTML markup containing questions and countdown timer
 */
var quiz = quizzer.fromToken("1a2b3c4d5e"); // warning: use an actual token
console.log(quiz);

/*
 * getCategories - gets a list of categories (only those that have questions)
 * usage: quizzer.getCategories()
 *
 * @return {array} Array of categories as strings
 */
var categories = quizzer.getCategories();
console.log(categories);

/*
 * evaluate - evaluates the quiz based on the provided form data
 * usage: quizzer.evaluate(form)
 *
 * @return {object} Contains details about the result of the quiz
 */

Future tasks

  • [ ] create a manager for better categories, quiz, question and answer handling
  • [ ] support templating/custom CSS