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

stylish-quiz

v1.0.8

Published

Simple, stylish and responsive quiz Web Component

Downloads

647

Readme

stylish-quiz

Simple, stylish and responsive quiz Web Component

Colors and Font are adaptable through CSS Variables.

Questions and result texts (for different point ranges) can be inserted through JSON into attributes.

Demo

See it in action and play around:

⚡ https://jsfiddle.net/maidi/o90hzqdk/ ⚡

Screenshots

Desktop View Mobile View

Usage

Integrate the package script:

<script type="module" src="https://unpkg.com/[email protected]"></script>

Option 1: Pure HTML

JSON.stringify your questions and result object arrays before adding them to HTML and you have no need for JavaScript:

<quiz-component questions='[{"question":"Question one?","answers":[{"text":"Answer 1.1","points":3},{"text":"Answer 1.2","points":2},{"text":"Answer 1.3","points":0},{"text":"Answer 1.4","points":1}],"index":0},{"question":"Question two?","answers":[{"text":"Answer 2.1","points":0},{"text":"Answer 2.2","points":2},{"text":"Answer 2.3","points":0}],"index":1}]'
                result='[{"points":"0-2","text":"Your result text"},{"points":"3-5","text":"Your awesome result text"}]'
                restart="Try again!">
</quiz-component>

Option 2: With JavaScript

Have a more structured overview over your questions and result objects:

<quiz-component restart="Try again!"></quiz-component>
const questions =
  JSON.stringify([
  {
      question: "Question one?",
      answers: [
        {text: "Answer 1.1", points: 3},
        {text: "Answer 1.2", points: 2},
        {text: "Answer 1.3", points: 0},
        {text: "Answer 1.4", points: 1}
      ],
      index: 0
  },{
      question: "Question two?",
      answers: [
        {text: "Answer 2.1", points: 0},
        {text: "Answer 2.2", points: 2},
        {text: "Answer 2.3", points: 0}
      ],
      index: 1
  }
]);

const result = 
   JSON.stringify([
   {
        points:"0-2",
        text:"Your result text"
   }, {
        points:"3-5",
        text:"Your awesome result text"
   }
]);

document.querySelector('quiz-component').setAttribute('questions', questions);
document.querySelector('quiz-component').setAttribute('result', result);

Styling

You can adjust colors and fonts through the following CSS variables:

quiz-component { 
  --color-primary: #1B1B3A; /* background of the slides */
  --color-primary-bright: #34346F; /* :active background of the answer when clicked */
  --color-primary-highlight: #C09BE9; /* :hover effect of the answer */
  --color-secondary: #DCDFE5; /* font color of the slides */
  --font-type: Arial;
  --font-size-question: 1.5rem;
  --font-size-answer: 1rem;
  --font_size_result: 1.2rem;
  --font_size_restart: 1rem;
}

Attributes and JSON Structure

Questions

The questions are displayed subsequently in the order determined by the index property.

Insert questions (= attribute name) as Array of objects matching the question interface:

interface Question {
  question: string; // displayed question text
  answers: {
      text: string, // displayed answer text
      points: number // received points when choosing this answer
  }[];
  index: number; // order (when is the question displayed in the sequence)
}

Result

The result is displayed at the end of all questions depending on the points that the user has reached.

Insert result (= attribute name) as Array of objects matching the result interface:

interface Result {
  points: string; // the result is displayed for this amount of points, can be inserted as range '0-5' or single number '8'
  text: string; // displayed result text for this amount of points
}

Take attention that the full range of points that can be achieved through your questions is mapped in the results.

Restart

A restart button is displayed below the result text if you insert this attribute. Insert restart (= attribute name) as string with the label text of the restart button.