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

country-quiz

v0.5.2

Published

Create quiz games with questions about countries, flags and capitals.

Downloads

11

Readme

Build Status Coverage Status npm License npm bundle size GitHub last commit

This node module lets you create questions and quizzes (with multiple questions) about countries, their flag and their capital (or vice versa). Data, Quizzes and Questions are accessed offline from a data file (data originally from https://restcountries.eu/) but the SVG-Files for the Flags need an internet connection.

Installation

npm i country-quiz
# or
yarn add country-quiz

Then import into your project

/* Common JS */
const countryQuiz = require('country-quiz')
const quiz = countryQuiz.newQuiz()

/* ES Module */
import { newQuiz, newQuestion, newRandomQuestion } from 'country-quiz'
const quiz = newQuiz()

Usage

newQuiz Returns an object with an array of questions of the specified quiz mode. If quiz mode is 'mixed' then the quiz mode for every question in the quiz is randomly selected.

newQuiz()
// returns (for example):
{
  quizMode: 'flag-to-country',
  questions: [
    {
      question: 'https://restcountries.eu/data/sau.svg',
      answer: 'Saudi Arabia',
      options: ['Austria', 'Saudi Arabia', 'Nepal', 'Svalbard and Jan Mayen']
    },
    {
      question: 'https://restcountries.eu/data/mus.svg',
      answer: 'Mauritius',
      options: ['Venezuela (Bolivarian Republic of)', 'Brunei Darussalam', 'Mauritius', 'Curaçao']
    },
    {
      question: 'https://restcountries.eu/data/gnb.svg',
      answer: 'Guinea-Bissau',
      options: ['Holy See', 'Rwanda', 'Falkland Islands (Malvinas)', 'Guinea-Bissau']
    },
    {
      question: 'https://restcountries.eu/data/hrv.svg',
      answer: 'Croatia',
      options: ['Croatia', 'Costa Rica', 'Heard Island and McDonald Islands', 'Comoros']
    },
    {
      question: 'https://restcountries.eu/data/khm.svg',
      answer: 'Cambodia',
      options: ['Tanzania, United Republic of', 'Mauritius', 'Cambodia', 'Antigua and Barbuda']
    }
  ]
}
// or with quizMode
const quiz = newQuiz('country-to-capital')

// or with quizMode and numberOfQuestions
const quiz = newQuiz('mixed', 5)

// or with quizMode, numberOfQuestions and numberOfOptions
const quiz = newQuiz('capital-to-flag', 3, 6)

| argument | type | default | description | | ----------------- | ------ | --------------- | ------------------------------------------------------- | | quizMode | string | flag-to-country | Types of questions and options. See below. | | numberOfQuestions | number | 5 | Number of questions in this quiz. | | numberOfOptions | number | 4 | Number of options (i.e. possible answers) per question. |


newQuestion Returns an object with one question of the specified quiz mode.

// create a new question
const question = newQuestion()

// or with quizMode and numberOfOptions
newQuestion('country-to-capital', 5)
// returns (for example):
{
  question: 'Burundi',
  answer: 'Bujumbura',
  options: ['Jamestown', 'Bujumbura', 'Berlin', 'Flying Fish Cove', 'Taipei']
}

| argument | type | default | description | | --------------- | ------ | --------------- | ------------------------------------------------------------ | | quizMode | string | flag-to-country | Types of the question and possible options. See below. | | numberOfOptions | number | 4 | Number of options (i.e. possible answers) for this question. |


newRandomQuestion Returns an object with one question of a random quiz mode.

newRandomQuestion()
// returns (for example):
{
  quizMode: 'capital-to-country',
  question: 'Papeetē',
  answer: 'French Polynesia',
  options: [ 'Mali', 'French Polynesia', 'China', 'Germany' ]
}

// or with numberOfOptions
const randomQuestion = newRandomQuestion(5)

| argument | type | default | description | | --------------- | ------ | ------- | ------------------------------------------------------------ | | numberOfOptions | number | 4 | Number of options (i.e. possible answers) for this question. |


Quiz Modes

Works in the Schema [question]-to-[answer]. mixed is only possible for newQuiz().

  • mixed
  • flag-to-country
  • flag-to-capital
  • country-to-flag
  • country-to-capital
  • capital-to-flag
  • capital-to-country

Copyright

Data and Flag SVGs are from the REST Countries Project: https://restcountries.eu


Development

To update the country data run node update-data.mjs. This fetches fresh data from https://restcountries.com/v3.1/all?fields=name,capital,flags and converts it to the librarie's format. The result is saved to a new-data.json file. The content of this file needs to be copied to src/data.js into the const data = [...] variable.