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

@it-could-be/trivia-questions

v0.0.12

Published

A trivia questions collection and library for interacting with those questions.

Downloads

16

Readme

It Could Be Trivia Questions

A trivia questions collection and library for interacting with those questions.

Please see It Could Be Trivia Bot for an example of a project utilizing this library.

ICBTQ exports two things:

  1. A JSON file containing the collection of trivia questions (@it-could-be/trivia-questions/dist/questions.json)
  2. A library that does things with those questions (import @it-could-be/trivia-questions)

Questions

Every question has the same top level structure

{
    // The kind of question it is
    question_type: 'single_answer'

    // Tags to associate with this question. They could be anything,
    // but are most often used for categorization.
    tags: ['video_games', 'pokemon']

    // A question_type specific object.
    detail: {
        ...
    }
}

From there, you have the specific kinds of questions. There are a few different types of questions, not all supported at the moment.

Single Answer Question (supported)

These are questions that have one answer. For example...

What was the first city to reach a population of 1 million? (Rome)

What was the highest selling game on the PlayStation 2 (Grand Theft Auto: San Andreas)

Who is the creator of the Python programming language? (Guido van Rossum)

{
    question_type: 'single_answer'
    tags: ['video_games', 'pokemon']

    detail: {
        // The text of the question
        text: "What is the lighest Pokemon?"

        // An array of acceptable correct answers
        answer: ['Gastly']
    }
}

Multiple Answer Question (supported)

These are questions that have multiple correct answers. For example...

Name every colony in the original 13 U.S. colonies.

Name the Top 5 highest selling vidoe game consoles of all-time.

Name the 5 women who were on the winning 2016 Summer Olympics U.S. women's gymnastics team.

{
    question_type: 'multiple_answer'
    tags: ['video_games', 'pokemon']

    detail: {
        // The text of the question
        text: "Name all of the Pokemon that appeared in episode 1 of the Pokemon anime."

        // An array of arrays of the correct answers
        answer: [
            ['Pikachu'],
            ['Nidorino'],
            ['Onix'],
            ['Gengar'],
            ['Spearow'],
            ['Ho-Oh', 'Ho Oh'],
            ['Bulbasaur'],
            ['Charmander'],
            ['Squirtle'],
            ['Pidgey'],
            ['Rattata'],
            ['Sandshrew'],
            ['Mankey'],
            ['Dodrio'],
            ['Magikarp'],
            ['Gyarados'],
        ]
    }
}

Usage

import questions from '@it-could-be/trivia-questions/dist/questions.json';
import * as TriviaQuestions from '@it-could-be/trivia-questions';

TriviaQuestions.getRandomQuestion(
    questions,
    {
        // An array of the types of questions you want to include [optional]
        types: [TriviaQuestions.QuestionType.SingleAnswer, TriviaQuestions.QuestionType.MultipleAnswer]
    }
})

let singleAnswerQuestion = TriviaQuestions.getRandomQuestion(questions, { types: [TriviaQuestions.QuestionType.SingleAnswer } })

// A module for verifying answers
let answerModule = TriviaQuestions.Answer;

/*
{
    // Was the input a correct answer for the question?
    isCorrect: false,

    // If the answer was correct, was the input exact? For example,
    // if the answer to a question is "Super Mario Bros.",
    // the input "Super Mario Bros." is an exact answer, and
    // "smb" is an inexact answer.
    isExactAnswer: false,

    // The exact answer for the question
    exactAnswer: 'TheAnswer',
}
*/
let answer = answerModule.SingleAnswerQuestion.verifyAnswer(singleAnswerQuestion, 'theanswer1')




let multipleAnswerQuestion = TriviaQuestions.getRandomQuestion(questions, { types: [TriviaQuestions.QuestionType.MultipleAnswer } })

/*
{
    isCorrect: correct,
    isExactAnswer: false,
    exactAnswer: 'TheAnswer',

      // The ID of the answer that was answered correctly
    answerId: '1'
}
*/
let answer = answerModule.SingleAnswerQuestion.verifyAnswer(singleAnswerQuestion, 'someInput')

Types

To see specific type documentation, see src/types.ts, or the generated typedefs in the NPM package.